update to use emails destroy service

This commit is contained in:
James Lopez 2017-06-19 10:04:14 +02:00
parent ad44af2faa
commit 3bab585bec
5 changed files with 7 additions and 6 deletions

View file

@ -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!

View file

@ -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! }

View file

@ -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!

View file

@ -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

View file

@ -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