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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
d8b9de52
Commit
d8b9de52
authored
Nov 17, 2016
by
Semyon Pupkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unnecessary self from user model
parent
694b55c8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
54 deletions
+57
-54
app/models/user.rb
app/models/user.rb
+53
-54
changelogs/unreleased/remove-unnecessary-self-from-user-model.yml
...gs/unreleased/remove-unnecessary-self-from-user-model.yml
+4
-0
No files found.
app/models/user.rb
View file @
d8b9de52
...
...
@@ -227,19 +227,19 @@ class User < ActiveRecord::Base
def
filter
(
filter_name
)
case
filter_name
when
'admins'
self
.
admins
admins
when
'blocked'
self
.
blocked
blocked
when
'two_factor_disabled'
self
.
without_two_factor
without_two_factor
when
'two_factor_enabled'
self
.
with_two_factor
with_two_factor
when
'wop'
self
.
without_projects
without_projects
when
'external'
self
.
external
external
else
self
.
active
active
end
end
...
...
@@ -337,7 +337,7 @@ class User < ActiveRecord::Base
end
def
generate_password
if
self
.
force_random_password
if
force_random_password
self
.
password
=
self
.
password_confirmation
=
Devise
.
friendly_token
.
first
(
Devise
.
password_length
.
min
)
end
end
...
...
@@ -378,56 +378,55 @@ class User < ActiveRecord::Base
end
def
two_factor_otp_enabled?
self
.
otp_required_for_login?
otp_required_for_login?
end
def
two_factor_u2f_enabled?
self
.
u2f_registrations
.
exists?
u2f_registrations
.
exists?
end
def
namespace_uniq
# Return early if username already failed the first uniqueness validation
return
if
self
.
errors
.
key?
(
:username
)
&&
self
.
errors
[
:username
].
include?
(
'has already been taken'
)
return
if
errors
.
key?
(
:username
)
&&
errors
[
:username
].
include?
(
'has already been taken'
)
namespace_name
=
self
.
username
existing_namespace
=
Namespace
.
by_path
(
namespace_name
)
if
existing_namespace
&&
existing_namespace
!=
self
.
namespace
self
.
errors
.
add
(
:username
,
'has already been taken'
)
existing_namespace
=
Namespace
.
by_path
(
username
)
if
existing_namespace
&&
existing_namespace
!=
namespace
errors
.
add
(
:username
,
'has already been taken'
)
end
end
def
avatar_type
unless
self
.
avatar
.
image?
self
.
errors
.
add
:avatar
,
"only images allowed"
unless
avatar
.
image?
errors
.
add
:avatar
,
"only images allowed"
end
end
def
unique_email
if
!
self
.
emails
.
exists?
(
email:
self
.
email
)
&&
Email
.
exists?
(
email:
self
.
email
)
self
.
errors
.
add
(
:email
,
'has already been taken'
)
if
!
emails
.
exists?
(
email:
email
)
&&
Email
.
exists?
(
email:
email
)
errors
.
add
(
:email
,
'has already been taken'
)
end
end
def
owns_notification_email
return
if
self
.
temp_oauth_email?
return
if
temp_oauth_email?
self
.
errors
.
add
(
:notification_email
,
"is not an email you own"
)
unless
self
.
all_emails
.
include?
(
self
.
notification_email
)
errors
.
add
(
:notification_email
,
"is not an email you own"
)
unless
all_emails
.
include?
(
notification_email
)
end
def
owns_public_email
return
if
self
.
public_email
.
blank?
return
if
public_email
.
blank?
self
.
errors
.
add
(
:public_email
,
"is not an email you own"
)
unless
self
.
all_emails
.
include?
(
self
.
public_email
)
errors
.
add
(
:public_email
,
"is not an email you own"
)
unless
all_emails
.
include?
(
public_email
)
end
def
update_emails_with_primary_email
primary_email_record
=
self
.
emails
.
find_by
(
email:
self
.
email
)
primary_email_record
=
emails
.
find_by
(
email:
email
)
if
primary_email_record
primary_email_record
.
destroy
self
.
emails
.
create
(
email:
self
.
email_was
)
emails
.
create
(
email:
email_was
)
self
.
update_secondary_emails!
update_secondary_emails!
end
end
...
...
@@ -581,7 +580,7 @@ class User < ActiveRecord::Base
end
def
project_deploy_keys
DeployKey
.
unscoped
.
in_projects
(
self
.
authorized_projects
.
pluck
(
:id
)).
distinct
(
:id
)
DeployKey
.
unscoped
.
in_projects
(
authorized_projects
.
pluck
(
:id
)).
distinct
(
:id
)
end
def
accessible_deploy_keys
...
...
@@ -597,38 +596,38 @@ class User < ActiveRecord::Base
end
def
sanitize_attrs
%w
(name username skype linkedin twitter)
.
each
do
|
attr
|
value
=
self
.
send
(
attr
)
self
.
send
(
"
#{
attr
}
="
,
Sanitize
.
clean
(
value
))
if
value
.
present?
%w
[name username skype linkedin twitter]
.
each
do
|
attr
|
value
=
public_
send
(
attr
)
public_
send
(
"
#{
attr
}
="
,
Sanitize
.
clean
(
value
))
if
value
.
present?
end
end
def
set_notification_email
if
self
.
notification_email
.
blank?
||
!
self
.
all_emails
.
include?
(
self
.
notification_email
)
self
.
notification_email
=
self
.
email
if
notification_email
.
blank?
||
!
all_emails
.
include?
(
notification_email
)
self
.
notification_email
=
email
end
end
def
set_public_email
if
self
.
public_email
.
blank?
||
!
self
.
all_emails
.
include?
(
self
.
public_email
)
if
public_email
.
blank?
||
!
all_emails
.
include?
(
public_email
)
self
.
public_email
=
''
end
end
def
update_secondary_emails!
se
lf
.
se
t_notification_email
se
lf
.
se
t_public_email
s
elf
.
save
if
self
.
notification_email_changed?
||
self
.
public_email_changed?
set_notification_email
set_public_email
s
ave
if
notification_email_changed?
||
public_email_changed?
end
def
set_projects_limit
# `User.select(:id)` raises
# `ActiveModel::MissingAttributeError: missing attribute: projects_limit`
# without this safeguard!
return
unless
self
.
has_attribute?
(
:projects_limit
)
return
unless
has_attribute?
(
:projects_limit
)
connection_default_value_defined
=
new_record?
&&
!
projects_limit_changed?
return
unless
self
.
projects_limit
.
nil?
||
connection_default_value_defined
return
unless
projects_limit
.
nil?
||
connection_default_value_defined
self
.
projects_limit
=
current_application_settings
.
default_projects_limit
end
...
...
@@ -658,7 +657,7 @@ class User < ActiveRecord::Base
def
with_defaults
User
.
defaults
.
each
do
|
k
,
v
|
self
.
send
(
"
#{
k
}
="
,
v
)
public_
send
(
"
#{
k
}
="
,
v
)
end
self
...
...
@@ -678,7 +677,7 @@ class User < ActiveRecord::Base
# Thus it will automatically generate a new fragment
# when the event is updated because the key changes.
def
reset_events_cache
Event
.
where
(
author_id:
self
.
id
).
Event
.
where
(
author_id:
id
).
order
(
'id DESC'
).
limit
(
1000
).
update_all
(
updated_at:
Time
.
now
)
end
...
...
@@ -711,8 +710,8 @@ class User < ActiveRecord::Base
def
all_emails
all_emails
=
[]
all_emails
<<
self
.
email
unless
self
.
temp_oauth_email?
all_emails
.
concat
(
self
.
emails
.
map
(
&
:email
))
all_emails
<<
email
unless
temp_oauth_email?
all_emails
.
concat
(
emails
.
map
(
&
:email
))
all_emails
end
...
...
@@ -726,21 +725,21 @@ class User < ActiveRecord::Base
def
ensure_namespace_correct
# Ensure user has namespace
self
.
create_namespace!
(
path:
self
.
username
,
name:
self
.
username
)
unless
self
.
namespace
create_namespace!
(
path:
username
,
name:
username
)
unless
namespace
if
self
.
username_changed?
self
.
namespace
.
update_attributes
(
path:
self
.
username
,
name:
self
.
username
)
if
username_changed?
namespace
.
update_attributes
(
path:
username
,
name:
username
)
end
end
def
post_create_hook
log_info
(
"User
\"
#{
self
.
name
}
\"
(
#{
self
.
email
}
) was created"
)
notification_service
.
new_user
(
self
,
@reset_token
)
if
self
.
created_by_id
log_info
(
"User
\"
#{
name
}
\"
(
#{
email
}
) was created"
)
notification_service
.
new_user
(
self
,
@reset_token
)
if
created_by_id
system_hook_service
.
execute_hooks_for
(
self
,
:create
)
end
def
post_destroy_hook
log_info
(
"User
\"
#{
self
.
name
}
\"
(
#{
self
.
email
}
) was removed"
)
log_info
(
"User
\"
#{
name
}
\"
(
#{
email
}
) was removed"
)
system_hook_service
.
execute_hooks_for
(
self
,
:destroy
)
end
...
...
@@ -784,7 +783,7 @@ class User < ActiveRecord::Base
end
def
oauth_authorized_tokens
Doorkeeper
::
AccessToken
.
where
(
resource_owner_id:
self
.
id
,
revoked_at:
nil
)
Doorkeeper
::
AccessToken
.
where
(
resource_owner_id:
id
,
revoked_at:
nil
)
end
# Returns the projects a user contributed to in the last year.
...
...
@@ -917,7 +916,7 @@ class User < ActiveRecord::Base
end
def
ensure_external_user_rights
return
unless
self
.
external?
return
unless
external?
self
.
can_create_group
=
false
self
.
projects_limit
=
0
...
...
@@ -929,7 +928,7 @@ class User < ActiveRecord::Base
if
current_application_settings
.
domain_blacklist_enabled?
blocked_domains
=
current_application_settings
.
domain_blacklist
if
domain_matches?
(
blocked_domains
,
self
.
email
)
if
domain_matches?
(
blocked_domains
,
email
)
error
=
'is not from an allowed domain.'
valid
=
false
end
...
...
@@ -937,7 +936,7 @@ class User < ActiveRecord::Base
allowed_domains
=
current_application_settings
.
domain_whitelist
unless
allowed_domains
.
blank?
if
domain_matches?
(
allowed_domains
,
self
.
email
)
if
domain_matches?
(
allowed_domains
,
email
)
valid
=
true
else
error
=
"domain is not authorized for sign-up"
...
...
@@ -945,7 +944,7 @@ class User < ActiveRecord::Base
end
end
self
.
errors
.
add
(
:email
,
error
)
unless
valid
errors
.
add
(
:email
,
error
)
unless
valid
valid
end
...
...
changelogs/unreleased/remove-unnecessary-self-from-user-model.yml
0 → 100644
View file @
d8b9de52
---
title
:
Remove unnecessary self from user model
merge_request
:
7551
author
:
Semyon Pupkov
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