diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-20 00:10:26 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-20 00:10:26 +0300 |
commit | b6bf52d3e274bd060a7b7e7a2812fda30e0d66d5 (patch) | |
tree | f4c98cfa82db4035744cd87c05d8a804c9b25e80 /app/services/ci | |
parent | 1e1012d3d28c426637eecc0909c415fe2c8b7c3a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/ci')
-rw-r--r-- | app/services/ci/catalog/add_resource_service.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/app/services/ci/catalog/add_resource_service.rb b/app/services/ci/catalog/add_resource_service.rb new file mode 100644 index 00000000000..c22e7e84c3c --- /dev/null +++ b/app/services/ci/catalog/add_resource_service.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Ci + module Catalog + class AddResourceService + 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) + + validation_response = Ci::Catalog::Resources::ValidateService.new(project, project.default_branch).execute + + if validation_response.success? + create_catalog_resource + else + ServiceResponse.error(message: validation_response.message) + end + end + + private + + def create_catalog_resource + 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 |