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
ed3c25e4
Commit
ed3c25e4
authored
Oct 01, 2017
by
Alexandra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
spacing and small optimisations
parent
39fbac86
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
28 additions
and
24 deletions
+28
-24
app/controllers/confirmations_controller.rb
app/controllers/confirmations_controller.rb
+1
-1
app/controllers/profiles/emails_controller.rb
app/controllers/profiles/emails_controller.rb
+2
-1
app/models/user.rb
app/models/user.rb
+7
-7
app/services/emails/base_service.rb
app/services/emails/base_service.rb
+2
-3
app/services/emails/confirm_service.rb
app/services/emails/confirm_service.rb
+2
-2
app/services/emails/create_service.rb
app/services/emails/create_service.rb
+2
-2
app/services/emails/destroy_service.rb
app/services/emails/destroy_service.rb
+2
-2
app/views/profiles/emails/index.html.haml
app/views/profiles/emails/index.html.haml
+3
-3
spec/controllers/profiles/emails_controller_spec.rb
spec/controllers/profiles/emails_controller_spec.rb
+4
-3
spec/models/email_spec.rb
spec/models/email_spec.rb
+3
-0
No files found.
app/controllers/confirmations_controller.rb
View file @
ed3c25e4
...
...
@@ -10,7 +10,7 @@ class ConfirmationsController < Devise::ConfirmationsController
users_almost_there_path
end
def
after_confirmation_path_for
(
resource_name
,
resource
)
def
after_confirmation_path_for
(
_
resource_name
,
resource
)
# incoming resource can either be a :user or an :email
if
signed_in?
(
:user
)
after_sign_in_path_for
(
resource
)
...
...
app/controllers/profiles/emails_controller.rb
View file @
ed3c25e4
...
...
@@ -2,7 +2,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
before_action
:find_email
,
only:
[
:destroy
,
:resend_confirmation_instructions
]
def
index
@primary
=
current_user
.
email
@primary
_email
=
current_user
.
email
@emails
=
current_user
.
emails
.
order_id_desc
end
...
...
@@ -30,6 +30,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
else
flash
[
:alert
]
=
"There was a problem sending the confirmation email"
end
redirect_to
profile_emails_url
end
...
...
app/models/user.rb
View file @
ed3c25e4
...
...
@@ -164,7 +164,7 @@ class User < ActiveRecord::Base
before_save
:ensure_authentication_token
,
:ensure_incoming_email_token
before_save
:ensure_user_rights_and_limits
,
if: :external_changed?
before_save
:skip_reconfirmation!
,
if:
->
(
user
)
{
user
.
email_changed?
&&
user
.
read_only_attribute?
(
:email
)
}
before_save
:check_for_verified_email
,
if:
->
(
user
)
{
user
.
email_changed?
&&
!
user
.
new_record?
}
before_save
:check_for_verified_email
,
if:
->
(
user
)
{
user
.
email_changed?
&&
!
user
.
new_record?
}
after_save
:ensure_namespace_correct
after_destroy
:post_destroy_hook
after_commit
:update_emails_with_primary_email
,
on: :update
,
if:
->
{
previous_changes
.
key?
(
'email'
)
}
...
...
@@ -223,11 +223,6 @@ class User < ActiveRecord::Base
end
end
# see if the new email is already a verified secondary email
def
check_for_verified_email
skip_reconfirmation!
if
emails
.
find_by
(
email:
self
.
email
).
try
(
:confirmed?
)
end
mount_uploader
:avatar
,
AvatarUploader
has_many
:uploads
,
as: :model
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
...
...
@@ -529,6 +524,11 @@ class User < ActiveRecord::Base
errors
.
add
(
:public_email
,
"is not an email you own"
)
unless
all_emails
.
include?
(
public_email
)
end
# see if the new email is already a verified secondary email
def
check_for_verified_email
skip_reconfirmation!
if
emails
.
confirmed
.
where
(
email:
self
.
email
).
any?
end
# Note: the use of the Emails services will cause `saves` on the user object, running
# through the callbacks again and can have side effects, such as the `previous_changes`
# hash and `_was` variables getting munged.
...
...
@@ -843,7 +843,7 @@ class User < ActiveRecord::Base
def
verified_email?
(
check_email
)
downcased
=
check_email
.
downcase
(
email
==
downcased
&&
primary_email_verified?
)
||
emails
.
confirmed
.
where
(
email:
downcased
).
exists?
email
==
downcased
?
primary_email_verified?
:
emails
.
confirmed
.
where
(
email:
downcased
).
exists?
end
def
hook_attrs
...
...
app/services/emails/base_service.rb
View file @
ed3c25e4
module
Emails
class
BaseService
def
initialize
(
user
,
opts
=
{})
@user
=
user
@email
=
opts
[
:email
]
def
initialize
(
user
,
params
=
{})
@user
,
@params
=
user
,
params
.
dup
end
end
end
app/services/emails/confirm_service.rb
View file @
ed3c25e4
module
Emails
class
ConfirmService
<
::
Emails
::
BaseService
def
execute
(
email
_record
)
email
_record
.
resend_confirmation_instructions
def
execute
(
email
)
email
.
resend_confirmation_instructions
end
end
end
app/services/emails/create_service.rb
View file @
ed3c25e4
module
Emails
class
CreateService
<
::
Emails
::
BaseService
def
execute
(
option
s
=
{})
@user
.
emails
.
create
(
{
email:
@email
}.
merge
(
option
s
))
def
execute
(
extra_param
s
=
{})
@user
.
emails
.
create
(
@params
.
merge
(
extra_param
s
))
end
end
end
app/services/emails/destroy_service.rb
View file @
ed3c25e4
module
Emails
class
DestroyService
<
::
Emails
::
BaseService
def
execute
(
email
_record
)
email
_record
.
destroy
&&
update_secondary_emails!
def
execute
(
email
)
email
.
destroy
&&
update_secondary_emails!
end
private
...
...
app/views/profiles/emails/index.html.haml
View file @
ed3c25e4
...
...
@@ -32,12 +32,12 @@
All email addresses will be used to identify your commits.
%ul
.well-list
%li
=
render
partial:
'shared/email_with_badge'
,
locals:
{
email:
@primary
,
verified:
current_user
.
confirmed?
}
=
render
partial:
'shared/email_with_badge'
,
locals:
{
email:
@primary
_email
,
verified:
current_user
.
confirmed?
}
%span
.pull-right
%span
.label.label-success
Primary email
-
if
@primary
===
current_user
.
public_email
-
if
@primary
_email
===
current_user
.
public_email
%span
.label.label-info
Public email
-
if
@primary
===
current_user
.
notification_email
-
if
@primary
_email
===
current_user
.
notification_email
%span
.label.label-info
Notification email
-
@emails
.
each
do
|
email
|
%li
...
...
spec/controllers/profiles/emails_controller_spec.rb
View file @
ed3c25e4
...
...
@@ -11,7 +11,7 @@ describe Profiles::EmailsController do
let
(
:email_params
)
{
{
email:
"add_email@example.com"
}
}
it
'sends an email confirmation'
do
expect
{
post
(
:create
,
{
email:
email_params
})
}.
to
change
{
ActionMailer
::
Base
.
deliveries
.
size
}
expect
{
post
(
:create
,
{
email:
email_params
})
}.
to
change
{
ActionMailer
::
Base
.
deliveries
.
size
}
expect
(
ActionMailer
::
Base
.
deliveries
.
last
.
to
).
to
eq
[
email_params
[
:email
]]
expect
(
ActionMailer
::
Base
.
deliveries
.
last
.
subject
).
to
match
"Confirmation instructions"
end
...
...
@@ -22,13 +22,14 @@ describe Profiles::EmailsController do
it
'resends an email confirmation'
do
email
=
user
.
emails
.
create
(
email:
'add_email@example.com'
)
expect
{
put
(
:resend_confirmation_instructions
,
{
id:
email
})}.
to
change
{
ActionMailer
::
Base
.
deliveries
.
size
}
expect
{
put
(
:resend_confirmation_instructions
,
{
id:
email
})
}.
to
change
{
ActionMailer
::
Base
.
deliveries
.
size
}
expect
(
ActionMailer
::
Base
.
deliveries
.
last
.
to
).
to
eq
[
email_params
[
:email
]]
expect
(
ActionMailer
::
Base
.
deliveries
.
last
.
subject
).
to
match
"Confirmation instructions"
end
it
'unable to resend an email confirmation'
do
expect
{
put
(
:resend_confirmation_instructions
,
{
id:
1
})
}.
not_to
change
{
ActionMailer
::
Base
.
deliveries
.
size
}
expect
{
put
(
:resend_confirmation_instructions
,
{
id:
1
})
}.
not_to
change
{
ActionMailer
::
Base
.
deliveries
.
size
}
end
end
end
spec/models/email_spec.rb
View file @
ed3c25e4
...
...
@@ -22,7 +22,9 @@ describe Email do
it
'synchronizes the gpg keys when the email is updated'
do
email
=
user
.
emails
.
create
(
email:
'new@email.com'
)
expect
(
user
).
to
receive
(
:update_invalid_gpg_signatures
)
email
.
confirm
end
end
...
...
@@ -33,6 +35,7 @@ describe Email do
it
'scopes confirmed emails'
do
create
(
:email
,
:confirmed
,
user:
user
)
create
(
:email
,
user:
user
)
expect
(
user
.
emails
.
count
).
to
eq
2
expect
(
user
.
emails
.
confirmed
.
count
).
to
eq
1
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