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
350f2ba7
Commit
350f2ba7
authored
Nov 15, 2018
by
Imre Farkas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
User#find_by_any_email to respect confirmed flag on secondary emails
parent
3b23d06c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
6 deletions
+37
-6
app/models/user.rb
app/models/user.rb
+1
-1
changelogs/unreleased/ce-54109-fix_user_by_any_email.yml
changelogs/unreleased/ce-54109-fix_user_by_any_email.yml
+5
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+31
-5
No files found.
app/models/user.rb
View file @
350f2ba7
...
...
@@ -363,7 +363,7 @@ class User < ActiveRecord::Base
from_users
=
from_users
.
confirmed
if
confirmed
from_emails
=
joins
(
:emails
).
where
(
emails:
{
email:
emails
})
from_emails
=
from_emails
.
confirmed
if
confirmed
from_emails
=
from_emails
.
confirmed
.
merge
(
Email
.
confirmed
)
if
confirmed
items
=
[
from_users
,
from_emails
]
...
...
changelogs/unreleased/ce-54109-fix_user_by_any_email.yml
0 → 100644
View file @
350f2ba7
---
title
:
User#find_by_any_email to respect confirmed flag on secondary emails
merge_request
:
23181
author
:
type
:
fixed
spec/models/user_spec.rb
View file @
350f2ba7
...
...
@@ -1137,12 +1137,38 @@ describe User do
expect
(
described_class
.
find_by_any_email
(
user
.
email
.
upcase
,
confirmed:
true
)).
to
eq
user
end
it
'finds by secondary email'
do
email
=
create
(
:email
,
email:
'foo@example.com'
)
user
=
email
.
user
context
'finds by secondary email'
do
let
(
:user
)
{
email
.
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
context
'primary email confirmed'
do
context
'secondary email confirmed'
do
let!
(
:email
)
{
create
(
:email
,
:confirmed
,
email:
'foo@example.com'
)
}
it
'finds user respecting the confirmed flag'
do
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
context
'secondary email not confirmed'
do
let!
(
:email
)
{
create
(
:email
,
email:
'foo@example.com'
)
}
it
'finds user respecting the confirmed flag'
do
expect
(
described_class
.
find_by_any_email
(
email
.
email
)).
to
eq
user
expect
(
described_class
.
find_by_any_email
(
email
.
email
,
confirmed:
true
)).
to
be_nil
end
end
end
context
'primary email not confirmed'
do
let
(
:user
)
{
create
(
:user
,
confirmed_at:
nil
)
}
let!
(
:email
)
{
create
(
:email
,
:confirmed
,
user:
user
,
email:
'foo@example.com'
)
}
it
'finds user respecting the confirmed flag'
do
expect
(
described_class
.
find_by_any_email
(
email
.
email
)).
to
eq
user
expect
(
described_class
.
find_by_any_email
(
email
.
email
,
confirmed:
true
)).
to
be_nil
end
end
end
it
'returns nil when nothing found'
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