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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-12-06 06:14:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-12-06 06:14:51 +0300
commit313ce461cafef54a87c1943b941dc1327246e1e2 (patch)
tree1abfbf775593a2fbcff01a78a9a5389dfd12f2cc /app/services
parent1e2aa980a7214f025d22e1d8936147391b670a89 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r--app/services/container_registry/protection/delete_rule_service.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/app/services/container_registry/protection/delete_rule_service.rb b/app/services/container_registry/protection/delete_rule_service.rb
new file mode 100644
index 00000000000..bfd91c75b8b
--- /dev/null
+++ b/app/services/container_registry/protection/delete_rule_service.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+module ContainerRegistry
+ module Protection
+ class DeleteRuleService
+ include Gitlab::Allowable
+
+ def initialize(container_registry_protection_rule, current_user:)
+ if container_registry_protection_rule.blank? || current_user.blank?
+ raise ArgumentError,
+ 'container_registry_protection_rule and current_user must be set'
+ end
+
+ @container_registry_protection_rule = container_registry_protection_rule
+ @current_user = current_user
+ end
+
+ def execute
+ unless can?(current_user, :admin_container_image, container_registry_protection_rule.project)
+ error_message = _('Unauthorized to delete a container registry protection rule')
+ return service_response_error(message: error_message)
+ end
+
+ deleted_container_registry_protection_rule = container_registry_protection_rule.destroy!
+
+ ServiceResponse.success(
+ payload: { container_registry_protection_rule: deleted_container_registry_protection_rule }
+ )
+ rescue StandardError => e
+ service_response_error(message: e.message)
+ end
+
+ private
+
+ attr_reader :container_registry_protection_rule, :current_user
+
+ def service_response_error(message:)
+ ServiceResponse.error(
+ message: message,
+ payload: { container_registry_protection_rule: nil }
+ )
+ end
+ end
+ end
+end