Class: ContainerRegistry::Protection::DeleteRuleService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Allowable
Defined in:
app/services/container_registry/protection/delete_rule_service.rb

Instance Method Summary collapse

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

#initialize(container_registry_protection_rule, current_user:) ⇒ DeleteRuleService

Returns a new instance of DeleteRuleService.



8
9
10
11
12
13
14
15
16
# File 'app/services/container_registry/protection/delete_rule_service.rb', line 8

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

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/container_registry/protection/delete_rule_service.rb', line 18

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