Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create_service.rb « resources « catalog « ci « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 89367c70e82c2a82db7ec935068e039d68ca9b2e (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
# frozen_string_literal: true

module Ci
  module Catalog
    module Resources
      class CreateService
        include Gitlab::Allowable

        attr_reader :project, :current_user

        def initialize(project, user)
          @current_user = user
          @project = project
        end

        def execute
          raise Gitlab::Access::AccessDeniedError unless can?(current_user, :add_catalog_resource, project)

          catalog_resource = Ci::Catalog::Resource.new(project: project)

          if catalog_resource.valid?
            catalog_resource.save!
            ServiceResponse.success(payload: catalog_resource)
          else
            ServiceResponse.error(message: catalog_resource.errors.full_messages.join(', '))
          end
        end
      end
    end
  end
end