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
a5722c37
Commit
a5722c37
authored
Jul 28, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Plain Diff
Merge commit '
45ff4e31
' into sh-support-bitbucket-server-import
parents
6408cd00
45ff4e31
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
3 deletions
+27
-3
app/models/user.rb
app/models/user.rb
+7
-3
changelogs/unreleased/sh-support-users-find-by-confirmed-emails.yml
.../unreleased/sh-support-users-find-by-confirmed-emails.yml
+5
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+15
-0
No files found.
app/models/user.rb
View file @
a5722c37
...
@@ -248,6 +248,7 @@ class User < ActiveRecord::Base
...
@@ -248,6 +248,7 @@ class User < ActiveRecord::Base
scope
:todo_authors
,
->
(
user_id
,
state
)
{
where
(
id:
Todo
.
where
(
user_id:
user_id
,
state:
state
).
select
(
:author_id
))
}
scope
:todo_authors
,
->
(
user_id
,
state
)
{
where
(
id:
Todo
.
where
(
user_id:
user_id
,
state:
state
).
select
(
:author_id
))
}
scope
:order_recent_sign_in
,
->
{
reorder
(
Gitlab
::
Database
.
nulls_last_order
(
'current_sign_in_at'
,
'DESC'
))
}
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
:order_oldest_sign_in
,
->
{
reorder
(
Gitlab
::
Database
.
nulls_last_order
(
'current_sign_in_at'
,
'ASC'
))
}
scope
:confirmed
,
->
{
where
.
not
(
confirmed_at:
nil
)
}
def
self
.
with_two_factor_indistinct
def
self
.
with_two_factor_indistinct
joins
(
"LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id"
)
joins
(
"LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id"
)
...
@@ -293,14 +294,17 @@ class User < ActiveRecord::Base
...
@@ -293,14 +294,17 @@ class User < ActiveRecord::Base
end
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
)
def
find_by_any_email
(
email
,
confirmed:
false
)
by_any_email
(
email
).
take
by_any_email
(
email
,
confirmed:
confirmed
).
take
end
end
# Returns a relation containing all the users for the given Email address
# Returns a relation containing all the users for the given Email address
def
by_any_email
(
email
)
def
by_any_email
(
email
,
confirmed:
false
)
users
=
where
(
email:
email
)
users
=
where
(
email:
email
)
users
=
users
.
confirmed
if
confirmed
emails
=
joins
(
:emails
).
where
(
emails:
{
email:
email
})
emails
=
joins
(
:emails
).
where
(
emails:
{
email:
email
})
emails
=
emails
.
confirmed
if
confirmed
union
=
Gitlab
::
SQL
::
Union
.
new
([
users
,
emails
])
union
=
Gitlab
::
SQL
::
Union
.
new
([
users
,
emails
])
from
(
"(
#{
union
.
to_sql
}
)
#{
table_name
}
"
)
from
(
"(
#{
union
.
to_sql
}
)
#{
table_name
}
"
)
...
...
changelogs/unreleased/sh-support-users-find-by-confirmed-emails.yml
0 → 100644
View file @
a5722c37
---
title
:
Add support for searching users by confirmed e-mails
merge_request
:
20893
author
:
type
:
other
spec/models/user_spec.rb
View file @
a5722c37
...
@@ -949,6 +949,7 @@ describe User do
...
@@ -949,6 +949,7 @@ describe User do
user
=
create
(
:user
,
email:
'foo@example.com'
)
user
=
create
(
:user
,
email:
'foo@example.com'
)
expect
(
described_class
.
find_by_any_email
(
user
.
email
)).
to
eq
user
expect
(
described_class
.
find_by_any_email
(
user
.
email
)).
to
eq
user
expect
(
described_class
.
find_by_any_email
(
user
.
email
,
confirmed:
true
)).
to
eq
user
end
end
it
'finds by secondary email'
do
it
'finds by secondary email'
do
...
@@ -956,11 +957,19 @@ describe User do
...
@@ -956,11 +957,19 @@ describe User do
user
=
email
.
user
user
=
email
.
user
expect
(
described_class
.
find_by_any_email
(
email
.
email
)).
to
eq
user
expect
(
described_class
.
find_by_any_email
(
email
.
email
)).
to
eq
user
expect
(
described_class
.
find_by_any_email
(
email
.
email
,
confirmed:
true
)).
to
eq
user
end
end
it
'returns nil when nothing found'
do
it
'returns nil when nothing found'
do
expect
(
described_class
.
find_by_any_email
(
''
)).
to
be_nil
expect
(
described_class
.
find_by_any_email
(
''
)).
to
be_nil
end
end
it
'returns nil when user is not confirmed'
do
user
=
create
(
:user
,
email:
'foo@example.com'
,
confirmed_at:
nil
)
expect
(
described_class
.
find_by_any_email
(
user
.
email
,
confirmed:
false
)).
to
eq
(
user
)
expect
(
described_class
.
find_by_any_email
(
user
.
email
,
confirmed:
true
)).
to
be_nil
end
end
end
describe
'.by_any_email'
do
describe
'.by_any_email'
do
...
@@ -974,6 +983,12 @@ describe User do
...
@@ -974,6 +983,12 @@ describe User do
expect
(
described_class
.
by_any_email
(
user
.
email
)).
to
eq
([
user
])
expect
(
described_class
.
by_any_email
(
user
.
email
)).
to
eq
([
user
])
end
end
it
'returns a relation of users for confirmed users'
do
user
=
create
(
:user
)
expect
(
described_class
.
by_any_email
(
user
.
email
,
confirmed:
true
)).
to
eq
([
user
])
end
end
end
describe
'.search'
do
describe
'.search'
do
...
...
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