Class: PagesDomains::CreateService

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

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

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?, #can_all?, #can_any?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#executeObject



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

def execute
  return unless authorized?

  existing_domain = find_existing_domain

  if existing_domain
    domain = PagesDomain.new(domain: params[:domain])
    error_message = if current_user.can?(:admin_pages, existing_domain.project)
                      "is already in use by project #{existing_domain.project.full_path}"
                    else
                      "is already in use by another project"
                    end

    domain.errors.add(:domain, error_message)
    return domain
  end

  domain = project.pages_domains.create(params)

  publish_event(domain) if domain.persisted?

  domain
end