2018-07-16 16:31:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-16 13:06:14 +00:00
|
|
|
module Emails
|
2017-06-19 12:51:46 +00:00
|
|
|
class CreateService < ::Emails::BaseService
|
2017-10-01 15:07:26 +00:00
|
|
|
def execute(extra_params = {})
|
2019-02-06 12:41:17 +00:00
|
|
|
skip_confirmation = params.delete(:skip_confirmation)
|
2018-09-09 21:04:11 +00:00
|
|
|
|
2019-02-06 12:41:17 +00:00
|
|
|
user.emails.create(params.merge(extra_params)).tap do |email|
|
|
|
|
email&.confirm if skip_confirmation && current_user.admin?
|
2022-03-18 15:07:23 +00:00
|
|
|
notification_service.new_email_address_added(user, email.email) if email.persisted? && !email.user_primary_email?
|
2019-02-06 12:41:17 +00:00
|
|
|
end
|
2017-06-16 13:06:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
Emails::CreateService.prepend_mod_with('Emails::CreateService')
|