diff --git a/app/graphql/mutations/container_registry/protection/rule/create.rb b/app/graphql/mutations/container_registry/protection/rule/create.rb index 40aba6c57c7ccfe66bcd9743e5a8c0cab92287d2..2d72326ac6192cc712b6c5b836e72c07d56c2df5 100644 --- a/app/graphql/mutations/container_registry/protection/rule/create.rb +++ b/app/graphql/mutations/container_registry/protection/rule/create.rb @@ -49,7 +49,10 @@ class Create < ::Mutations::BaseMutation def resolve(project_path:, **kwargs) project = authorized_find!(project_path) - response = ::ContainerRegistry::Protection::CreateRuleService.new(project, current_user, kwargs).execute + response = + ::ContainerRegistry::Protection::CreateRuleService + .new(project: project, current_user: current_user, params: kwargs) + .execute { container_protection_repository_rule: response.payload[:container_registry_protection_rule], errors: response.errors } diff --git a/app/graphql/mutations/container_registry/protection/tag_rule/create.rb b/app/graphql/mutations/container_registry/protection/tag_rule/create.rb index 30a77521fbcefb203a449ab3b26f1f0cc99193ef..a260b8b8c416f4a18429d3a8ec09bb05b1550ff7 100644 --- a/app/graphql/mutations/container_registry/protection/tag_rule/create.rb +++ b/app/graphql/mutations/container_registry/protection/tag_rule/create.rb @@ -57,7 +57,10 @@ def resolve(project_path:, **kwargs) raise_resource_not_available_error!("'container_registry_protected_tags' feature flag is disabled") end - response = ::ContainerRegistry::Protection::CreateTagRuleService.new(project, current_user, kwargs).execute + response = + ::ContainerRegistry::Protection::CreateTagRuleService + .new(project: project, current_user: current_user, params: kwargs) + .execute { container_protection_tag_rule: response[:container_protection_tag_rule], errors: response.errors } diff --git a/app/services/container_registry/protection/create_rule_service.rb b/app/services/container_registry/protection/create_rule_service.rb index 574f124cd8130f9e56d3e92ab1e6e6454979e5e1..0c91af132130289b0d784b014e8f30c13a0bfd8e 100644 --- a/app/services/container_registry/protection/create_rule_service.rb +++ b/app/services/container_registry/protection/create_rule_service.rb @@ -2,7 +2,7 @@ module ContainerRegistry module Protection - class CreateRuleService < BaseService + class CreateRuleService < BaseProjectService ALLOWED_ATTRIBUTES = %i[ repository_path_pattern minimum_access_level_for_push diff --git a/app/services/container_registry/protection/create_tag_rule_service.rb b/app/services/container_registry/protection/create_tag_rule_service.rb index 4f56f9e950e7467421eed79a863c77e08a63e816..2b811564615bbb6032fd2c004dfaca103d1b5f03 100644 --- a/app/services/container_registry/protection/create_tag_rule_service.rb +++ b/app/services/container_registry/protection/create_tag_rule_service.rb @@ -2,7 +2,7 @@ module ContainerRegistry module Protection - class CreateTagRuleService < BaseService + class CreateTagRuleService < BaseProjectService ALLOWED_ATTRIBUTES = %i[ tag_name_pattern minimum_access_level_for_push diff --git a/lib/api/project_container_registry_protection_rules.rb b/lib/api/project_container_registry_protection_rules.rb index e22eebd75a566b2382d1a2acdcdb1308d3204763..0baad434e547cc536de8729ba62a7e47ca70f90a 100644 --- a/lib/api/project_container_registry_protection_rules.rb +++ b/lib/api/project_container_registry_protection_rules.rb @@ -55,8 +55,10 @@ class ProjectContainerRegistryProtectionRules < ::API::Base at_least_one_of :minimum_access_level_for_push, :minimum_access_level_for_delete end post do - response = ::ContainerRegistry::Protection::CreateRuleService.new(user_project, - current_user, declared_params).execute + response = + ::ContainerRegistry::Protection::CreateRuleService + .new(project: user_project, current_user: current_user, params: declared_params) + .execute render_api_error!({ error: response.message }, :unprocessable_entity) if response.error? diff --git a/spec/services/container_registry/protection/create_rule_service_spec.rb b/spec/services/container_registry/protection/create_rule_service_spec.rb index 637014b2d4c402c9a3a9fcfca26b757bf386aa83..bc31d5618766dc16927d82791e67fb32696ee34a 100644 --- a/spec/services/container_registry/protection/create_rule_service_spec.rb +++ b/spec/services/container_registry/protection/create_rule_service_spec.rb @@ -6,7 +6,7 @@ let_it_be(:project) { create(:project, :repository) } let_it_be(:current_user) { create(:user, maintainer_of: project) } - let(:service) { described_class.new(project, current_user, params) } + let(:service) { described_class.new(project: project, current_user: current_user, params: params) } let(:params) { attributes_for(:container_registry_protection_rule, project: project) } subject(:service_execute) { service.execute } diff --git a/spec/services/container_registry/protection/create_tag_rule_service_spec.rb b/spec/services/container_registry/protection/create_tag_rule_service_spec.rb index c65dcd6fe973fba48c3bf3a201fe606e751a02c5..547f2da89bf7d79d7221925ae6381c4d5ba2e0d0 100644 --- a/spec/services/container_registry/protection/create_tag_rule_service_spec.rb +++ b/spec/services/container_registry/protection/create_tag_rule_service_spec.rb @@ -8,7 +8,7 @@ let_it_be(:project) { create(:project, :repository) } let_it_be(:current_user) { create(:user, maintainer_of: project) } - let(:service) { described_class.new(project, current_user, params) } + let(:service) { described_class.new(project: project, current_user: current_user, params: params) } let(:params) { attributes_for(:container_registry_protection_tag_rule, project: project) } subject(:service_execute) { service.execute }