gitlab-org--gitlab-foss/app/services/emails/destroy_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

24 lines
626 B
Ruby
Raw Normal View History

# frozen_string_literal: true
module Emails
2017-06-19 12:51:46 +00:00
class DestroyService < ::Emails::BaseService
2017-10-01 15:07:26 +00:00
def execute(email)
raise StandardError, 'Cannot delete primary email' if email.user_primary_email?
email.destroy && update_secondary_emails!(email.email)
2017-06-22 06:55:07 +00:00
end
private
def update_secondary_emails!(deleted_email)
2017-09-27 09:48:33 +00:00
result = ::Users::UpdateService.new(@current_user, user: @user).execute do |user|
user.unset_secondary_emails_matching_deleted_email!(deleted_email)
2017-06-22 06:55:07 +00:00
end
result[:status] == :success
end
end
end
Emails::DestroyService.prepend_mod_with('Emails::DestroyService')