Class: ServiceDesk::CustomEmails::CreateService

Inherits:
BaseService show all
Defined in:
app/services/service_desk/custom_emails/create_service.rb

Instance Attribute Summary

Attributes inherited from BaseProjectService

#project

Attributes inherited from BaseContainerService

#container, #current_user, #group, #params, #project

Instance Method Summary collapse

Methods inherited from BaseProjectService

#initialize

Methods inherited from BaseContainerService

#group_container?, #initialize, #namespace_container?, #project_container?, #project_group

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseProjectService

Instance Method Details

#executeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/service_desk/custom_emails/create_service.rb', line 6

def execute
  return error_feature_flag_disabled unless feature_flag_enabled?
  return error_user_not_authorized unless legitimate_user?
  return error_params_missing unless has_required_params?
  return error_custom_email_exists if credential? || verification?

  return error_cannot_create_custom_email unless create_credential

  if update_settings.error?
    # We don't warp everything in a single transaction here and roll it back
    # because ServiceDeskSettings::UpdateService uses safe_find_or_create_by!
    rollback_credential
    return error_cannot_create_custom_email
  end

  project.reset

  # The create service may return an error response if the verification fails early.
  # Here We want to indicate whether adding a custom email address was successful, so
  # we don't use its response here.
  create_verification

  log_info
  ServiceResponse.success
end