Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
56fdade9
Commit
56fdade9
authored
Apr 29, 2021
by
Qingyu Zhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create table user_credit_card_validations
parent
2c4abf28
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
117 additions
and
0 deletions
+117
-0
app/models/user.rb
app/models/user.rb
+6
-0
app/models/users/credit_card_validation.rb
app/models/users/credit_card_validation.rb
+9
-0
changelogs/unreleased/migrate-create-table-user-credit-card-validations.yml
...sed/migrate-create-table-user-credit-card-validations.yml
+5
-0
db/migrate/20210429131525_create_user_credit_card_validations.rb
...ate/20210429131525_create_user_credit_card_validations.rb
+22
-0
db/schema_migrations/20210429131525
db/schema_migrations/20210429131525
+1
-0
db/structure.sql
db/structure.sql
+11
-0
spec/factories/users.rb
spec/factories/users.rb
+6
-0
spec/factories/users/credit_card_validations.rb
spec/factories/users/credit_card_validations.rb
+9
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+41
-0
spec/models/users/credit_card_validation_spec.rb
spec/models/users/credit_card_validation_spec.rb
+7
-0
No files found.
app/models/user.rb
View file @
56fdade9
...
...
@@ -205,6 +205,7 @@ class User < ApplicationRecord
has_one
:user_detail
has_one
:user_highest_role
has_one
:user_canonical_email
has_one
:credit_card_validation
,
class_name:
'::Users::CreditCardValidation'
has_one
:atlassian_identity
,
class_name:
'Atlassian::Identity'
has_many
:reviews
,
foreign_key: :author_id
,
inverse_of: :author
...
...
@@ -317,6 +318,7 @@ class User < ApplicationRecord
accepts_nested_attributes_for
:user_preference
,
update_only:
true
accepts_nested_attributes_for
:user_detail
,
update_only:
true
accepts_nested_attributes_for
:credit_card_validation
,
update_only:
true
state_machine
:state
,
initial: :active
do
event
:block
do
...
...
@@ -1223,6 +1225,10 @@ class User < ApplicationRecord
user_highest_role
&
.
highest_access_level
||
Gitlab
::
Access
::
NO_ACCESS
end
def
credit_card_validated_at
credit_card_validation
&
.
credit_card_validated_at
end
def
accessible_deploy_keys
DeployKey
.
from_union
([
DeployKey
.
where
(
id:
project_deploy_keys
.
select
(
:deploy_key_id
)),
...
...
app/models/users/credit_card_validation.rb
0 → 100644
View file @
56fdade9
# frozen_string_literal: true
module
Users
class
CreditCardValidation
<
ApplicationRecord
self
.
table_name
=
'user_credit_card_validations'
belongs_to
:user
end
end
changelogs/unreleased/migrate-create-table-user-credit-card-validations.yml
0 → 100644
View file @
56fdade9
---
title
:
Create table user_credit_card_validations
merge_request
:
60626
author
:
type
:
changed
db/migrate/20210429131525_create_user_credit_card_validations.rb
0 → 100644
View file @
56fdade9
# frozen_string_literal: true
class
CreateUserCreditCardValidations
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
disable_ddl_transaction!
def
up
with_lock_retries
do
create_table
:user_credit_card_validations
,
id:
false
do
|
t
|
t
.
references
:user
,
foreign_key:
{
on_delete: :cascade
},
index:
false
,
primary_key:
true
,
default:
nil
t
.
datetime_with_timezone
:credit_card_validated_at
,
null:
false
end
end
end
def
down
with_lock_retries
do
drop_table
:user_credit_card_validations
end
end
end
db/schema_migrations/20210429131525
0 → 100644
View file @
56fdade9
68ac54fa7b4e4ef99e58c31d8f960b6f986fd679c11ead235704c7a75b4617ac
\ No newline at end of file
db/structure.sql
View file @
56fdade9
...
...
@@ -18272,6 +18272,11 @@ CREATE SEQUENCE user_canonical_emails_id_seq
ALTER SEQUENCE user_canonical_emails_id_seq OWNED BY user_canonical_emails.id;
CREATE TABLE user_credit_card_validations (
user_id bigint NOT NULL,
credit_card_validated_at timestamp with time zone NOT NULL
);
CREATE TABLE user_custom_attributes (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
...
...
@@ -21642,6 +21647,9 @@ ALTER TABLE ONLY user_callouts
ALTER TABLE ONLY user_canonical_emails
ADD CONSTRAINT user_canonical_emails_pkey PRIMARY KEY (id);
ALTER TABLE ONLY user_credit_card_validations
ADD CONSTRAINT user_credit_card_validations_pkey PRIMARY KEY (user_id);
ALTER TABLE ONLY user_custom_attributes
ADD CONSTRAINT user_custom_attributes_pkey PRIMARY KEY (id);
...
...
@@ -25923,6 +25931,9 @@ ALTER TABLE ONLY lfs_file_locks
ALTER TABLE ONLY project_alerting_settings
ADD CONSTRAINT fk_rails_27a84b407d FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY user_credit_card_validations
ADD CONSTRAINT fk_rails_27ebc03cbf FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY dast_site_validations
ADD CONSTRAINT fk_rails_285c617324 FOREIGN KEY (dast_site_token_id) REFERENCES dast_site_tokens(id) ON DELETE CASCADE;
spec/factories/users.rb
View file @
56fdade9
...
...
@@ -80,6 +80,12 @@ FactoryBot.define do
last_sign_in_ip
{
'127.0.0.1'
}
end
trait
:with_credit_card_validation
do
after
:create
do
|
user
|
create
:credit_card_validation
,
user:
user
end
end
trait
:two_factor_via_otp
do
before
(
:create
)
do
|
user
|
user
.
otp_required_for_login
=
true
...
...
spec/factories/users/credit_card_validations.rb
0 → 100644
View file @
56fdade9
# frozen_string_literal: true
FactoryBot
.
define
do
factory
:credit_card_validation
,
class:
'Users::CreditCardValidation'
do
user
credit_card_validated_at
{
Time
.
current
}
end
end
spec/models/user_spec.rb
View file @
56fdade9
...
...
@@ -83,6 +83,7 @@ RSpec.describe User do
it
{
is_expected
.
to
have_one
(
:user_detail
)
}
it
{
is_expected
.
to
have_one
(
:atlassian_identity
)
}
it
{
is_expected
.
to
have_one
(
:user_highest_role
)
}
it
{
is_expected
.
to
have_one
(
:credit_card_validation
)
}
it
{
is_expected
.
to
have_many
(
:snippets
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:members
)
}
it
{
is_expected
.
to
have_many
(
:project_members
)
}
...
...
@@ -1387,6 +1388,26 @@ RSpec.describe User do
end
end
describe
'#credit_card_validated_at'
do
let_it_be
(
:user
)
{
create
(
:user
)
}
context
'when credit_card_validation does not exist'
do
it
'returns nil'
do
expect
(
user
.
credit_card_validated_at
).
to
be
nil
end
end
context
'when credit_card_validation exists'
do
it
'returns the credit card validated time'
do
credit_card_validated_time
=
Time
.
current
-
1
.
day
create
(
:credit_card_validation
,
credit_card_validated_at:
credit_card_validated_time
,
user:
user
)
expect
(
user
.
credit_card_validated_at
).
to
eq
(
credit_card_validated_time
)
end
end
end
describe
'#update_tracked_fields!'
,
:clean_gitlab_redis_shared_state
do
let
(
:request
)
{
OpenStruct
.
new
(
remote_ip:
"127.0.0.1"
)
}
let
(
:user
)
{
create
(
:user
)
}
...
...
@@ -5290,6 +5311,26 @@ RSpec.describe User do
end
end
describe
'user credit card validation'
do
context
'when user is initialized'
do
let
(
:user
)
{
build
(
:user
)
}
it
{
expect
(
user
.
credit_card_validation
).
not_to
be_present
}
end
context
'when create user without credit card validation'
do
let
(
:user
)
{
create
(
:user
)
}
it
{
expect
(
user
.
credit_card_validation
).
not_to
be_present
}
end
context
'when user credit card validation exists'
do
let
(
:user
)
{
create
(
:user
,
:with_credit_card_validation
)
}
it
{
expect
(
user
.
credit_card_validation
).
to
be_persisted
}
end
end
describe
'user detail'
do
context
'when user is initialized'
do
let
(
:user
)
{
build
(
:user
)
}
...
...
spec/models/users/credit_card_validation_spec.rb
0 → 100644
View file @
56fdade9
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Users
::
CreditCardValidation
do
it
{
is_expected
.
to
belong_to
(
:user
)
}
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment