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
Jérome Perrin
gitlab-ce
Commits
d7d335c0
Commit
d7d335c0
authored
Sep 20, 2017
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add primary email as a secondary email whenever the primary is changed
parent
945667ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
14 deletions
+12
-14
app/models/user.rb
app/models/user.rb
+5
-7
spec/models/email_spec.rb
spec/models/email_spec.rb
+2
-2
spec/models/user_spec.rb
spec/models/user_spec.rb
+5
-5
No files found.
app/models/user.rb
View file @
d7d335c0
...
...
@@ -535,15 +535,13 @@ class User < ActiveRecord::Base
# By using an `after_commit` instead of `after_update`, we avoid the recursive callback
# scenario, though it then requires us to use the `previous_changes` hash
def
update_emails_with_primary_email
previous_email
=
previous_changes
[
:email
][
0
]
# grab this before the DestroyService is called
primary_email_record
=
emails
.
find_by
(
email:
email
)
if
primary_email_record
previous_email
=
previous_changes
[
:email
][
0
]
Emails
::
DestroyService
.
new
(
self
).
execute
(
primary_email_record
)
Emails
::
DestroyService
.
new
(
self
).
execute
(
primary_email_record
)
if
primary_email_record
# the original primary email was confirmed, and we want that to carry over. We don't
# have access to the original confirmation values at this point, so just set confirmed_at
Emails
::
CreateService
.
new
(
self
,
email:
previous_email
).
execute
(
confirmed_at:
confirmed_at
)
end
# the original primary email was confirmed, and we want that to carry over. We don't
# have access to the original confirmation values at this point, so just set confirmed_at
Emails
::
CreateService
.
new
(
self
,
email:
previous_email
).
execute
(
confirmed_at:
confirmed_at
)
end
def
update_invalid_gpg_signatures
...
...
spec/models/email_spec.rb
View file @
d7d335c0
...
...
@@ -32,8 +32,8 @@ describe Email do
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
create
(
:email
,
user:
user
)
expect
(
user
.
emails
.
count
).
to
eq
2
expect
(
user
.
emails
.
confirmed
.
count
).
to
eq
1
end
end
...
...
spec/models/user_spec.rb
View file @
d7d335c0
...
...
@@ -374,7 +374,7 @@ describe User do
end
end
describe
'after
update
hook'
do
describe
'after
commit
hook'
do
describe
'.update_invalid_gpg_signatures'
do
let
(
:user
)
do
create
(
:user
,
email:
'tula.torphy@abshire.ca'
).
tap
do
|
user
|
...
...
@@ -388,7 +388,7 @@ describe User do
end
it
'synchronizes the gpg keys when the email is updated'
do
expect
(
user
).
to
receive
(
:update_invalid_gpg_signatures
)
expect
(
user
).
to
receive
(
:update_invalid_gpg_signatures
)
.
at_most
(
:twice
)
user
.
update_attributes!
(
email:
'shawnee.ritchie@denesik.com'
)
end
end
...
...
@@ -407,11 +407,11 @@ describe User do
@user
.
update_attributes!
(
email:
'new_primary@example.com'
)
end
it
'
does not add old primary to secondary emails
'
do
it
'
adds old primary to secondary emails when secondary is a new email
'
do
@user
.
update_attributes!
(
email:
'new_primary@example.com'
)
@user
.
reload
expect
(
@user
.
emails
.
count
).
to
eq
1
expect
(
@user
.
emails
.
first
.
email
).
to
eq
@secondary
.
email
expect
(
@user
.
emails
.
count
).
to
eq
2
expect
(
@user
.
emails
.
pluck
(
:email
)).
to
match_array
([
@secondary
.
email
,
'primary@example.com'
])
end
it
'adds old primary to secondary emails if secondary is becoming a primary'
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