diff options
author | James Lopez <james@jameslopez.es> | 2017-06-19 10:04:14 +0200 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2017-06-23 11:41:42 +0200 |
commit | 3bab585bec5529c06ba4b0c4ae7e953b99edf6d3 (patch) | |
tree | 2751c7f6bc3959204dbf5fb90d42f56c773650c6 | |
parent | ad44af2faaaa872ee30922699f66ac78fa402336 (diff) | |
download | gitlab-ce-3bab585bec5529c06ba4b0c4ae7e953b99edf6d3.tar.gz |
update to use emails destroy service
-rw-r--r-- | app/controllers/admin/users_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/profiles/emails_controller.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | app/services/emails/destroy_service.rb | 2 | ||||
-rw-r--r-- | lib/api/users.rb | 5 |
5 files changed, 7 insertions, 6 deletions
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 754d9209138..4c43d12d317 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -152,7 +152,7 @@ class Admin::UsersController < Admin::ApplicationController def remove_email email = user.emails.find(params[:email_id]) - email.destroy + Emails::DestroyService.new(current_user, self, email: email.email).execute result = Users::UpdateService.new(current_user, @user).execute do |user| user.update_secondary_emails! diff --git a/app/controllers/profiles/emails_controller.rb b/app/controllers/profiles/emails_controller.rb index b68ae3b0843..9159c217f1b 100644 --- a/app/controllers/profiles/emails_controller.rb +++ b/app/controllers/profiles/emails_controller.rb @@ -18,7 +18,7 @@ class Profiles::EmailsController < Profiles::ApplicationController def destroy @email = current_user.emails.find(params[:id]) - @email.destroy + Emails::DestroyService.new(self, self, email: @email.email).execute Users::UpdateService.new(current_user, current_user).execute { |user| user.update_secondary_emails! } diff --git a/app/models/user.rb b/app/models/user.rb index 954a30155f7..bc754768ab1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -494,7 +494,7 @@ class User < ActiveRecord::Base def update_emails_with_primary_email primary_email_record = emails.find_by(email: email) if primary_email_record - primary_email_record.destroy + Emails::DestroyService.new(self, self, email: email).execute emails.create(email: email_was) update_secondary_emails! diff --git a/app/services/emails/destroy_service.rb b/app/services/emails/destroy_service.rb index 5080c08c473..c5fbc32033b 100644 --- a/app/services/emails/destroy_service.rb +++ b/app/services/emails/destroy_service.rb @@ -3,7 +3,7 @@ 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 end end end diff --git a/lib/api/users.rb b/lib/api/users.rb index f79b61ad85e..236bae4a299 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -276,7 +276,7 @@ module API email = user.emails.find_by(id: params[:email_id]) not_found!('Email') unless email - email.destroy + Emails::DestroyService.new(current_user, self, email: email.email).execute ::Users::UpdateService.new(current_user, user).execute do |user| user.update_secondary_emails! @@ -510,7 +510,8 @@ module API email = current_user.emails.find_by(id: params[:email_id]) not_found!('Email') unless email - email.destroy + Emails::DestroyService.new(current_user, self, email: email.email).execute + ::Users::UpdateService.new(current_user, current_user).execute do |user| user.update_secondary_emails! end |