summaryrefslogtreecommitdiff
path: root/app/services/pages_domains/update_service.rb
blob: b038aaa95b6f788226bd454f01b127e8ad452977 (plain)
1
2
3
4
5
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
31
32
33
34
# frozen_string_literal: true

module PagesDomains
  class UpdateService < BaseService
    def execute(domain)
      return unless authorized?

      return false unless domain.update(params)

      publish_event(domain)

      true
    end

    private

    def authorized?
      current_user.can?(:update_pages, project)
    end

    def publish_event(domain)
      event = PagesDomainUpdatedEvent.new(
        data: {
          project_id: project.id,
          namespace_id: project.namespace_id,
          root_namespace_id: project.root_namespace.id,
          domain: domain.domain
        }
      )

      Gitlab::EventStore.publish(event)
    end
  end
end