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
5ce9d4d8
Commit
5ce9d4d8
authored
Jul 08, 2021
by
Drew Blessing
Committed by
Mikołaj Wawrzyniak
Jul 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure identity queries use lower query to match index
parent
9e532e95
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
19 additions
and
17 deletions
+19
-17
app/models/user.rb
app/models/user.rb
+1
-4
lib/gitlab/bitbucket_import/importer.rb
lib/gitlab/bitbucket_import/importer.rb
+1
-4
lib/gitlab/github_import/user_finder.rb
lib/gitlab/github_import/user_finder.rb
+1
-1
lib/gitlab/gitlab_import/importer.rb
lib/gitlab/gitlab_import/importer.rb
+2
-2
lib/gitlab/legacy_github_import/user_formatter.rb
lib/gitlab/legacy_github_import/user_formatter.rb
+1
-6
spec/models/user_spec.rb
spec/models/user_spec.rb
+13
-0
No files found.
app/models/user.rb
View file @
5ce9d4d8
...
@@ -430,6 +430,7 @@ class User < ApplicationRecord
...
@@ -430,6 +430,7 @@ class User < ApplicationRecord
scope
:by_id_and_login
,
->
(
id
,
login
)
{
where
(
id:
id
).
where
(
'username = LOWER(:login) OR email = LOWER(:login)'
,
login:
login
)
}
scope
:by_id_and_login
,
->
(
id
,
login
)
{
where
(
id:
id
).
where
(
'username = LOWER(:login) OR email = LOWER(:login)'
,
login:
login
)
}
scope
:dormant
,
->
{
active
.
where
(
'last_activity_on <= ?'
,
MINIMUM_INACTIVE_DAYS
.
day
.
ago
.
to_date
)
}
scope
:dormant
,
->
{
active
.
where
(
'last_activity_on <= ?'
,
MINIMUM_INACTIVE_DAYS
.
day
.
ago
.
to_date
)
}
scope
:with_no_activity
,
->
{
active
.
where
(
last_activity_on:
nil
)
}
scope
:with_no_activity
,
->
{
active
.
where
(
last_activity_on:
nil
)
}
scope
:by_provider_and_extern_uid
,
->
(
provider
,
extern_uid
)
{
joins
(
:identities
).
merge
(
Identity
.
with_extern_uid
(
provider
,
extern_uid
))
}
def
preferred_language
def
preferred_language
read_attribute
(
'preferred_language'
)
||
read_attribute
(
'preferred_language'
)
||
...
@@ -554,10 +555,6 @@ class User < ApplicationRecord
...
@@ -554,10 +555,6 @@ class User < ApplicationRecord
end
end
end
end
def
for_github_id
(
id
)
joins
(
:identities
).
merge
(
Identity
.
with_extern_uid
(
:github
,
id
))
end
# Find a User by their primary email or any associated secondary email
# Find a User by their primary email or any associated secondary email
def
find_by_any_email
(
email
,
confirmed:
false
)
def
find_by_any_email
(
email
,
confirmed:
false
)
return
unless
email
return
unless
email
...
...
lib/gitlab/bitbucket_import/importer.rb
View file @
5ce9d4d8
...
@@ -63,10 +63,7 @@ module Gitlab
...
@@ -63,10 +63,7 @@ module Gitlab
return
users
[
username
]
if
users
.
key?
(
username
)
return
users
[
username
]
if
users
.
key?
(
username
)
users
[
username
]
=
User
.
select
(
:id
)
users
[
username
]
=
User
.
by_provider_and_extern_uid
(
:bitbucket
,
username
).
select
(
:id
).
first
&
.
id
.
joins
(
:identities
)
.
find_by
(
"identities.extern_uid = ? AND identities.provider = 'bitbucket'"
,
username
)
.
try
(
:id
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
...
...
lib/gitlab/github_import/user_finder.rb
View file @
5ce9d4d8
...
@@ -138,7 +138,7 @@ module Gitlab
...
@@ -138,7 +138,7 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
query_id_for_github_id
(
id
)
def
query_id_for_github_id
(
id
)
User
.
for_github_id
(
id
).
pluck
(
:id
).
first
User
.
by_provider_and_extern_uid
(
:github
,
id
).
select
(
:id
).
first
&
.
id
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
...
...
lib/gitlab/gitlab_import/importer.rb
View file @
5ce9d4d8
...
@@ -56,8 +56,8 @@ module Gitlab
...
@@ -56,8 +56,8 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
gitlab_user_id
(
project
,
gitlab_id
)
def
gitlab_user_id
(
project
,
gitlab_id
)
user
=
User
.
joins
(
:identities
).
find_by
(
"identities.extern_uid = ? AND identities.provider = 'gitlab'"
,
gitlab_id
.
to_s
)
user
_id
=
User
.
by_provider_and_extern_uid
(
:gitlab
,
gitlab_id
).
select
(
:id
).
first
&
.
id
(
user
&&
user
.
id
)
||
project
.
creator_id
user_id
||
project
.
creator_id
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
end
end
...
...
lib/gitlab/legacy_github_import/user_formatter.rb
View file @
5ce9d4d8
...
@@ -35,12 +35,7 @@ module Gitlab
...
@@ -35,12 +35,7 @@ module Gitlab
def
find_by_external_uid
def
find_by_external_uid
return
unless
id
return
unless
id
identities
=
::
Identity
.
arel_table
User
.
by_provider_and_extern_uid
(
:github
,
id
).
select
(
:id
).
first
&
.
id
User
.
select
(
:id
)
.
joins
(
:identities
)
.
find_by
(
identities
[
:provider
].
eq
(
:github
).
and
(
identities
[
:extern_uid
].
eq
(
id
)))
.
try
(
:id
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
end
end
...
...
spec/models/user_spec.rb
View file @
5ce9d4d8
...
@@ -5852,4 +5852,17 @@ RSpec.describe User do
...
@@ -5852,4 +5852,17 @@ RSpec.describe User do
end
end
end
end
end
end
describe
'.by_provider_and_extern_uid'
do
it
'calls Identity model scope to ensure case-insensitive query'
,
:aggregate_failures
do
expected_user
=
create
(
:user
)
create
(
:identity
,
extern_uid:
'some-other-name-id'
,
provider: :github
)
create
(
:identity
,
extern_uid:
'my_github_id'
,
provider: :gitlab
)
create
(
:identity
)
create
(
:identity
,
user:
expected_user
,
extern_uid:
'my_github_id'
,
provider: :github
)
expect
(
Identity
).
to
receive
(
:with_extern_uid
).
and_call_original
expect
(
described_class
.
by_provider_and_extern_uid
(
:github
,
'my_github_id'
)).
to
match_array
([
expected_user
])
end
end
end
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