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
4449f57e
Commit
4449f57e
authored
Jun 19, 2017
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactors user model validations
parent
db33c0fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
9 deletions
+11
-9
app/models/user.rb
app/models/user.rb
+9
-9
spec/models/user_spec.rb
spec/models/user_spec.rb
+2
-0
No files found.
app/models/user.rb
View file @
4449f57e
...
...
@@ -139,21 +139,21 @@ class User < ActiveRecord::Base
presence:
true
,
uniqueness:
{
case_sensitive:
false
}
validate
:namespace_uniq
,
if:
->
(
user
)
{
user
.
username_changed?
}
validate
:namespace_uniq
,
if:
:username_changed?
validate
:avatar_type
,
if:
->
(
user
)
{
user
.
avatar
.
present?
&&
user
.
avatar_changed?
}
validate
:unique_email
,
if:
->
(
user
)
{
user
.
email_changed?
}
validate
:owns_notification_email
,
if:
->
(
user
)
{
user
.
notification_email_changed?
}
validate
:owns_public_email
,
if:
->
(
user
)
{
user
.
public_email_changed?
}
validate
:unique_email
,
if:
:email_changed?
validate
:owns_notification_email
,
if:
:notification_email_changed?
validate
:owns_public_email
,
if:
:public_email_changed?
validate
:signup_domain_valid?
,
on: :create
,
if:
->
(
user
)
{
!
user
.
created_by_id
}
validates
:avatar
,
file_size:
{
maximum:
200
.
kilobytes
.
to_i
}
before_validation
:sanitize_attrs
before_validation
:set_notification_email
,
if:
->
(
user
)
{
user
.
email_changed?
}
before_validation
:set_public_email
,
if:
->
(
user
)
{
user
.
public_email_changed?
}
before_validation
:set_notification_email
,
if:
:email_changed?
before_validation
:set_public_email
,
if:
:public_email_changed?
after_update
:update_emails_with_primary_email
,
if:
->
(
user
)
{
user
.
email_changed?
}
after_update
:update_emails_with_primary_email
,
if:
:email_changed?
before_save
:ensure_authentication_token
,
:ensure_incoming_email_token
before_save
:ensure_user_rights_and_limits
,
if:
->
(
user
)
{
user
.
external_changed?
}
before_save
:ensure_user_rights_and_limits
,
if:
:external_changed?
after_save
:ensure_namespace_correct
after_initialize
:set_projects_limit
after_destroy
:post_destroy_hook
...
...
@@ -1038,7 +1038,7 @@ class User < ActiveRecord::Base
self
.
can_create_group
=
false
self
.
projects_limit
=
0
else
self
.
can_create_group
=
true
self
.
can_create_group
=
gitlab_config
.
default_can_create_group
self
.
projects_limit
=
current_application_settings
.
default_projects_limit
end
end
...
...
spec/models/user_spec.rb
View file @
4449f57e
...
...
@@ -462,6 +462,8 @@ describe User, models: true do
end
it
'ensures correct rights and limits for user'
do
stub_config_setting
(
default_can_create_group:
true
)
expect
{
user
.
update_attributes
(
external:
false
)
}.
to
change
{
user
.
can_create_group
}.
to
(
true
)
.
and
change
{
user
.
projects_limit
}.
to
(
current_application_settings
.
default_projects_limit
)
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