Class: Packages::Protection::DeleteRuleService
- Inherits:
-
Object
- Object
- Packages::Protection::DeleteRuleService
- Includes:
- Gitlab::Allowable, Gitlab::InternalEventsTracking
- Defined in:
- app/services/packages/protection/delete_rule_service.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(package_protection_rule, current_user:) ⇒ DeleteRuleService
constructor
A new instance of DeleteRuleService.
Methods included from Gitlab::InternalEventsTracking
Methods included from Gitlab::Allowable
Constructor Details
#initialize(package_protection_rule, current_user:) ⇒ DeleteRuleService
Returns a new instance of DeleteRuleService.
9 10 11 12 13 14 15 16 |
# File 'app/services/packages/protection/delete_rule_service.rb', line 9 def initialize(package_protection_rule, current_user:) if package_protection_rule.blank? || current_user.blank? raise ArgumentError, 'package_protection_rule and current_user must be set' end @package_protection_rule = package_protection_rule @current_user = current_user end |
Instance Method Details
#execute ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/services/packages/protection/delete_rule_service.rb', line 18 def execute unless can?(current_user, :admin_package, package_protection_rule.project) = _('Unauthorized to delete a package protection rule') return service_response_error(message: ) end deleted_package_protection_rule = package_protection_rule.destroy! track_internal_event( 'delete_package_protection_rule', project: package_protection_rule.project, namespace: package_protection_rule.project.namespace, user: current_user, additional_properties: { package_type: deleted_package_protection_rule.package_type } ) ServiceResponse.success(payload: { package_protection_rule: deleted_package_protection_rule }) rescue StandardError => e service_response_error(message: e.) end |