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
Léo-Paul Géneau
gitlab-ce
Commits
665c7876
Commit
665c7876
authored
Sep 20, 2017
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added email.confirmed scope and fix email comparison
parent
ed99c899
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
4 deletions
+18
-4
app/models/email.rb
app/models/email.rb
+3
-1
app/models/user.rb
app/models/user.rb
+3
-2
spec/models/email_spec.rb
spec/models/email_spec.rb
+11
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+1
-1
No files found.
app/models/email.rb
View file @
665c7876
...
...
@@ -7,6 +7,8 @@ class Email < ActiveRecord::Base
validates
:email
,
presence:
true
,
uniqueness:
true
,
email:
true
validate
:unique_email
,
if:
->
(
email
)
{
email
.
email_changed?
}
scope
:confirmed
,
->
{
where
.
not
(
confirmed_at:
nil
)
}
after_commit
:update_invalid_gpg_signatures
,
if:
->
{
previous_changes
.
key?
(
'confirmed_at'
)
}
devise
:confirmable
...
...
@@ -19,7 +21,7 @@ class Email < ActiveRecord::Base
def
unique_email
self
.
errors
.
add
(
:email
,
'has already been taken'
)
if
User
.
exists?
(
email:
self
.
email
)
end
# once email is confirmed, update the gpg signatures
def
update_invalid_gpg_signatures
user
.
update_invalid_gpg_signatures
if
confirmed?
...
...
app/models/user.rb
View file @
665c7876
...
...
@@ -837,12 +837,13 @@ class User < ActiveRecord::Base
def
verified_emails
verified_emails
=
[]
verified_emails
<<
email
if
primary_email_verified?
verified_emails
.
concat
(
emails
.
where
.
not
(
confirmed_at:
nil
)
.
pluck
(
:email
))
verified_emails
.
concat
(
emails
.
confirmed
.
pluck
(
:email
))
verified_emails
end
def
verified_email?
(
check_email
)
(
email
==
check_email
&&
primary_email_verified?
)
||
verified_emails
.
include?
(
check_email
)
downcased
=
check_email
.
downcase
(
email
==
downcased
&&
primary_email_verified?
)
||
emails
.
confirmed
.
where
(
email:
downcased
).
exists?
end
def
hook_attrs
...
...
spec/models/email_spec.rb
View file @
665c7876
...
...
@@ -26,4 +26,15 @@ describe Email do
email
.
confirm
end
end
describe
'scopes'
do
let
(
:user
)
{
create
(
:user
)
}
it
'scopes confirmed emails'
do
create
(
:email
,
:confirmed
,
user:
user
)
expect
(
user
.
emails
.
count
).
to
eq
1
expect
(
user
.
emails
.
unconfirmed
.
count
).
to
eq
0
expect
(
user
.
emails
.
confirmed
.
count
).
to
eq
1
end
end
end
spec/models/user_spec.rb
View file @
665c7876
...
...
@@ -1173,7 +1173,7 @@ describe User do
user
.
reload
expect
(
user
.
verified_email?
(
user
.
email
)).
to
be_truthy
expect
(
user
.
verified_email?
(
email_confirmed
.
email
)).
to
be_truthy
expect
(
user
.
verified_email?
(
email_confirmed
.
email
.
titlecase
)).
to
be_truthy
end
it
'returns false when the email is not verified/confirmed'
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