summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2017-06-22 08:55:07 +0200
committerJames Lopez <james@jameslopez.es>2017-06-23 11:41:42 +0200
commit785cbb79e255c8369ca5eb916207304f39d188ad (patch)
treeabd792d12be1f35d868db591793311eb32d92370 /app
parent0c8e7f49d1ef32ed5ea1bdd7e26dd5e169bad359 (diff)
downloadgitlab-ce-785cbb79e255c8369ca5eb916207304f39d188ad.tar.gz
refactor emails service
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin/users_controller.rb8
-rw-r--r--app/controllers/profiles/emails_controller.rb4
-rw-r--r--app/models/user.rb2
-rw-r--r--app/services/emails/destroy_service.rb12
4 files changed, 14 insertions, 12 deletions
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 4c43d12d317..065ebf81793 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -136,7 +136,7 @@ class Admin::UsersController < Admin::ApplicationController
# restore username to keep form action url.
user.username = params[:id]
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
@@ -152,11 +152,7 @@ class Admin::UsersController < Admin::ApplicationController
def remove_email
email = user.emails.find(params[:email_id])
- Emails::DestroyService.new(current_user, self, email: email.email).execute
-
- result = Users::UpdateService.new(current_user, @user).execute do |user|
- user.update_secondary_emails!
- end
+ Emails::DestroyService.new(current_user, user, email: email.email).execute
respond_to do |format|
if result[:status] == :success
diff --git a/app/controllers/profiles/emails_controller.rb b/app/controllers/profiles/emails_controller.rb
index 40b43278439..5c7a5fa9a64 100644
--- a/app/controllers/profiles/emails_controller.rb
+++ b/app/controllers/profiles/emails_controller.rb
@@ -18,9 +18,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
def destroy
@email = current_user.emails.find(params[:id])
- Emails::DestroyService.new(self, self, email: @email.email).execute
-
- Users::UpdateService.new(current_user, current_user).execute { |user| user.update_secondary_emails! }
+ Emails::DestroyService.new(current_user, current_user, email: @email.email).execute
respond_to do |format|
format.html { redirect_to profile_emails_url, status: 302 }
diff --git a/app/models/user.rb b/app/models/user.rb
index 117f54cf312..d53837fbdb2 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -496,8 +496,6 @@ class User < ActiveRecord::Base
if primary_email_record
Emails::DestroyService.new(self, self, email: email).execute
Emails::CreateService.new(self, self, email: email_was).execute
-
- update_secondary_emails!
end
end
diff --git a/app/services/emails/destroy_service.rb b/app/services/emails/destroy_service.rb
index 1275d31efb0..8150918986c 100644
--- a/app/services/emails/destroy_service.rb
+++ b/app/services/emails/destroy_service.rb
@@ -3,7 +3,17 @@ module Emails
def execute(skip_authorization: false)
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