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
7f7e83c0
Commit
7f7e83c0
authored
Dec 21, 2021
by
Manoj M J
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor two factor query methods on `User`
parent
c6a5f71e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
26 deletions
+7
-26
app/models/member.rb
app/models/member.rb
+1
-8
app/models/user.rb
app/models/user.rb
+6
-18
No files found.
app/models/member.rb
View file @
7f7e83c0
...
...
@@ -231,14 +231,7 @@ class Member < ApplicationRecord
end
def
left_join_users
users
=
User
.
arel_table
members
=
Member
.
arel_table
member_users
=
members
.
join
(
users
,
Arel
::
Nodes
::
OuterJoin
)
.
on
(
members
[
:user_id
].
eq
(
users
[
:id
]))
.
join_sources
joins
(
member_users
)
left_outer_joins
(
:user
)
end
def
access_for_user_ids
(
user_ids
)
...
...
app/models/user.rb
View file @
7f7e83c0
...
...
@@ -536,27 +536,15 @@ class User < ApplicationRecord
end
def
self
.
with_two_factor
with_u2f_registrations
=
<<-
SQL
EXISTS (
SELECT *
FROM u2f_registrations AS u2f
WHERE u2f.user_id = users.id
) OR users.otp_required_for_login = ?
OR
EXISTS (
SELECT *
FROM webauthn_registrations AS webauthn
WHERE webauthn.user_id = users.id
)
SQL
where
(
with_u2f_registrations
,
true
)
where
(
otp_required_for_login:
true
)
.
or
(
where_exists
(
U2fRegistration
.
where
(
U2fRegistration
.
arel_table
[
:user_id
].
eq
(
arel_table
[
:id
]))))
.
or
(
where_exists
(
WebauthnRegistration
.
where
(
WebauthnRegistration
.
arel_table
[
:user_id
].
eq
(
arel_table
[
:id
]))))
end
def
self
.
without_two_factor
joins
(
"LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id
LEFT OUTER JOIN webauthn_registrations AS webauthn ON webauthn.user_id = users.id"
)
.
where
(
"u2f.id IS NULL AND webauthn.id IS NULL AND users.otp_required_for_login = ?"
,
false
)
where
.
missing
(
:u2f_registrations
,
:webauthn_registrations
)
.
where
(
otp_required_for_login:
false
)
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