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
785cbb79
Commit
785cbb79
authored
Jun 22, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor emails service
parent
0c8e7f49
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
20 deletions
+14
-20
app/controllers/admin/users_controller.rb
app/controllers/admin/users_controller.rb
+2
-6
app/controllers/profiles/emails_controller.rb
app/controllers/profiles/emails_controller.rb
+1
-3
app/models/user.rb
app/models/user.rb
+0
-2
app/services/emails/destroy_service.rb
app/services/emails/destroy_service.rb
+11
-1
lib/api/users.rb
lib/api/users.rb
+0
-8
No files found.
app/controllers/admin/users_controller.rb
View file @
785cbb79
...
@@ -136,7 +136,7 @@ class Admin::UsersController < Admin::ApplicationController
...
@@ -136,7 +136,7 @@ class Admin::UsersController < Admin::ApplicationController
# restore username to keep form action url.
# restore username to keep form action url.
user
.
username
=
params
[
:id
]
user
.
username
=
params
[
:id
]
format
.
html
{
render
"edit"
}
format
.
html
{
render
"edit"
}
format
.
json
{
render
json:
result
[
:message
],
status:
result
[
:status
]
}
format
.
json
{
render
json:
[
result
[
:message
]
],
status:
result
[
:status
]
}
end
end
end
end
end
end
...
@@ -152,11 +152,7 @@ class Admin::UsersController < Admin::ApplicationController
...
@@ -152,11 +152,7 @@ class Admin::UsersController < Admin::ApplicationController
def
remove_email
def
remove_email
email
=
user
.
emails
.
find
(
params
[
:email_id
])
email
=
user
.
emails
.
find
(
params
[
:email_id
])
Emails
::
DestroyService
.
new
(
current_user
,
self
,
email:
email
.
email
).
execute
Emails
::
DestroyService
.
new
(
current_user
,
user
,
email:
email
.
email
).
execute
result
=
Users
::
UpdateService
.
new
(
current_user
,
@user
).
execute
do
|
user
|
user
.
update_secondary_emails!
end
respond_to
do
|
format
|
respond_to
do
|
format
|
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
...
...
app/controllers/profiles/emails_controller.rb
View file @
785cbb79
...
@@ -18,9 +18,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
...
@@ -18,9 +18,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
def
destroy
def
destroy
@email
=
current_user
.
emails
.
find
(
params
[
:id
])
@email
=
current_user
.
emails
.
find
(
params
[
:id
])
Emails
::
DestroyService
.
new
(
self
,
self
,
email:
@email
.
email
).
execute
Emails
::
DestroyService
.
new
(
current_user
,
current_user
,
email:
@email
.
email
).
execute
Users
::
UpdateService
.
new
(
current_user
,
current_user
).
execute
{
|
user
|
user
.
update_secondary_emails!
}
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
{
redirect_to
profile_emails_url
,
status:
302
}
format
.
html
{
redirect_to
profile_emails_url
,
status:
302
}
...
...
app/models/user.rb
View file @
785cbb79
...
@@ -496,8 +496,6 @@ class User < ActiveRecord::Base
...
@@ -496,8 +496,6 @@ class User < ActiveRecord::Base
if
primary_email_record
if
primary_email_record
Emails
::
DestroyService
.
new
(
self
,
self
,
email:
email
).
execute
Emails
::
DestroyService
.
new
(
self
,
self
,
email:
email
).
execute
Emails
::
CreateService
.
new
(
self
,
self
,
email:
email_was
).
execute
Emails
::
CreateService
.
new
(
self
,
self
,
email:
email_was
).
execute
update_secondary_emails!
end
end
end
end
...
...
app/services/emails/destroy_service.rb
View file @
785cbb79
...
@@ -3,7 +3,17 @@ module Emails
...
@@ -3,7 +3,17 @@ module Emails
def
execute
(
skip_authorization:
false
)
def
execute
(
skip_authorization:
false
)
raise
Gitlab
::
Access
::
AccessDeniedError
unless
skip_authorization
||
can_manage_emails?
raise
Gitlab
::
Access
::
AccessDeniedError
unless
skip_authorization
||
can_manage_emails?
Email
.
find_by_email
(
@email
).
destroy
Email
.
find_by_email
(
@email
).
destroy
&&
update_secondary_emails!
end
private
def
update_secondary_emails!
result
=
::
Users
::
UpdateService
.
new
(
@current_user
,
@current_user
).
execute
do
|
user
|
user
.
update_secondary_emails!
end
result
[
:status
]
==
'success'
end
end
end
end
end
end
lib/api/users.rb
View file @
785cbb79
...
@@ -275,10 +275,6 @@ module API
...
@@ -275,10 +275,6 @@ module API
not_found!
(
'Email'
)
unless
email
not_found!
(
'Email'
)
unless
email
Emails
::
DestroyService
.
new
(
current_user
,
user
,
email:
email
.
email
).
execute
(
skip_authorization:
true
)
Emails
::
DestroyService
.
new
(
current_user
,
user
,
email:
email
.
email
).
execute
(
skip_authorization:
true
)
::
Users
::
UpdateService
.
new
(
current_user
,
user
).
execute
do
|
user
|
user
.
update_secondary_emails!
end
end
end
desc
'Delete a user. Available only for admins.'
do
desc
'Delete a user. Available only for admins.'
do
...
@@ -509,10 +505,6 @@ module API
...
@@ -509,10 +505,6 @@ module API
not_found!
(
'Email'
)
unless
email
not_found!
(
'Email'
)
unless
email
Emails
::
DestroyService
.
new
(
current_user
,
current_user
,
email:
email
.
email
).
execute
Emails
::
DestroyService
.
new
(
current_user
,
current_user
,
email:
email
.
email
).
execute
::
Users
::
UpdateService
.
new
(
current_user
,
current_user
).
execute
do
|
user
|
user
.
update_secondary_emails!
end
end
end
desc
'Get a list of user activities'
desc
'Get a list of user activities'
...
...
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