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
4df97b08
Commit
4df97b08
authored
Oct 30, 2018
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move EE specific code out of the User model
parent
9b83acfd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
33 deletions
+25
-33
app/models/user.rb
app/models/user.rb
+3
-32
ee/app/models/ee/user.rb
ee/app/models/ee/user.rb
+21
-0
ee/spec/lib/gitlab/checks/change_access_spec.rb
ee/spec/lib/gitlab/checks/change_access_spec.rb
+1
-1
No files found.
app/models/user.rb
View file @
4df97b08
...
...
@@ -22,8 +22,6 @@ class User < ActiveRecord::Base
include
OptionallySearch
include
FromUnion
prepend
EE
::
User
DEFAULT_NOTIFICATION_LEVEL
=
:participating
ignore_column
:external_email
...
...
@@ -230,8 +228,6 @@ class User < ActiveRecord::Base
delegate
:notes_filter_for
,
to: :user_preference
delegate
:set_notes_filter
,
to: :user_preference
accepts_nested_attributes_for
:namespace
state_machine
:state
,
initial: :active
do
event
:block
do
transition
active: :blocked
...
...
@@ -268,11 +264,6 @@ class User < ActiveRecord::Base
scope
:external
,
->
{
where
(
external:
true
)
}
scope
:active
,
->
{
with_state
(
:active
).
non_internal
}
scope
:without_projects
,
->
{
joins
(
'LEFT JOIN project_authorizations ON users.id = project_authorizations.user_id'
).
where
(
project_authorizations:
{
user_id:
nil
})
}
scope
:subscribed_for_admin_email
,
->
{
where
(
admin_email_unsubscribed_at:
nil
)
}
scope
:ldap
,
->
{
joins
(
:identities
).
where
(
'identities.provider LIKE ?'
,
'ldap%'
)
}
scope
:with_provider
,
->
(
provider
)
do
joins
(
:identities
).
where
(
identities:
{
provider:
provider
})
end
scope
:order_recent_sign_in
,
->
{
reorder
(
Gitlab
::
Database
.
nulls_last_order
(
'current_sign_in_at'
,
'DESC'
))
}
scope
:order_oldest_sign_in
,
->
{
reorder
(
Gitlab
::
Database
.
nulls_last_order
(
'current_sign_in_at'
,
'ASC'
))
}
scope
:confirmed
,
->
{
where
.
not
(
confirmed_at:
nil
)
}
...
...
@@ -370,10 +361,6 @@ class User < ActiveRecord::Base
from_union
([
users
,
emails
])
end
def
existing_member?
(
email
)
User
.
where
(
email:
email
).
any?
||
Email
.
where
(
email:
email
).
any?
end
def
filter
(
filter_name
)
case
filter_name
when
'admins'
...
...
@@ -476,7 +463,7 @@ class User < ActiveRecord::Base
def
find_by_personal_access_token
(
token_string
)
return
unless
token_string
PersonalAccessTokensFinder
.
new
(
state:
'active'
).
find_by
(
token:
token_string
)
&
.
user
# rubocop: disable CodeReuse/Finder
PersonalAccessTokensFinder
.
new
(
state:
'active'
).
find_by
_token
(
token_string
)
&
.
user
# rubocop: disable CodeReuse/Finder
end
# Returns a user for the given SSH key.
...
...
@@ -489,11 +476,6 @@ class User < ActiveRecord::Base
namespace
&
.
owner
end
def
non_ldap
joins
(
'LEFT JOIN identities ON identities.user_id = users.id'
)
.
where
(
'identities.provider IS NULL OR identities.provider NOT LIKE ?'
,
'ldap%'
)
end
def
reference_prefix
'@'
end
...
...
@@ -1111,10 +1093,6 @@ class User < ActiveRecord::Base
end
# rubocop: enable CodeReuse/ServiceClass
def
admin_unsubscribe!
update_column
:admin_email_unsubscribed_at
,
Time
.
now
end
def
starred?
(
project
)
starred_projects
.
exists?
(
project
.
id
)
end
...
...
@@ -1491,15 +1469,6 @@ class User < ActiveRecord::Base
end
end
def
generate_token
(
token_field
)
if
token_field
==
:incoming_email_token
# Needs to be all lowercase and alphanumeric because it's gonna be used in an email address.
SecureRandom
.
hex
.
to_i
(
16
).
to_s
(
36
)
else
super
end
end
def
self
.
unique_internal
(
scope
,
username
,
email_pattern
,
&
block
)
scope
.
first
||
create_unique_internal
(
scope
,
username
,
email_pattern
,
&
block
)
end
...
...
@@ -1542,3 +1511,5 @@ class User < ActiveRecord::Base
Gitlab
::
ExclusiveLease
.
cancel
(
lease_key
,
uuid
)
end
end
User
.
prepend
(
EE
::
User
)
ee/app/models/ee/user.rb
View file @
4df97b08
...
...
@@ -42,6 +42,14 @@ module EE
scope
:excluding_guests
,
->
{
joins
(
:members
).
where
(
'members.access_level > ?'
,
::
Gitlab
::
Access
::
GUEST
).
distinct
}
scope
:subscribed_for_admin_email
,
->
{
where
(
admin_email_unsubscribed_at:
nil
)
}
scope
:ldap
,
->
{
joins
(
:identities
).
where
(
'identities.provider LIKE ?'
,
'ldap%'
)
}
scope
:with_provider
,
->
(
provider
)
do
joins
(
:identities
).
where
(
identities:
{
provider:
provider
})
end
accepts_nested_attributes_for
:namespace
enum
roadmap_layout:
{
weeks:
1
,
months:
4
,
quarters:
12
}
end
...
...
@@ -59,6 +67,15 @@ module EE
def
internal_attributes
super
+
[
:support_bot
]
end
def
non_ldap
joins
(
'LEFT JOIN identities ON identities.user_id = users.id'
)
.
where
(
'identities.provider IS NULL OR identities.provider NOT LIKE ?'
,
'ldap%'
)
end
def
existing_member?
(
email
)
::
User
.
where
(
email:
email
).
any?
||
::
Email
.
where
(
email:
email
).
any?
end
end
def
cannot_be_admin_and_auditor
...
...
@@ -161,5 +178,9 @@ module EE
def
ldap_sync_time
::
Gitlab
.
config
.
ldap
[
'sync_time'
]
end
def
admin_unsubscribe!
update_column
:admin_email_unsubscribed_at
,
Time
.
now
end
end
end
ee/spec/lib/gitlab/checks/change_access_spec.rb
View file @
4df97b08
...
...
@@ -184,7 +184,7 @@ describe Gitlab::Checks::ChangeAccess do
let
(
:push_rule
)
{
create
(
:push_rule
,
member_check:
true
)
}
before
do
allow
(
User
).
to
receive
(
:existing_member?
).
and_return
(
false
)
allow
(
EE
::
User
).
to
receive
(
:existing_member?
).
and_return
(
false
)
allow_any_instance_of
(
Commit
).
to
receive
(
:author_email
).
and_return
(
'some@mail.com'
)
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