Class: Packages::Protection::CheckRuleExistenceService

Inherits:
BaseProjectService show all
Defined in:
app/services/packages/protection/check_rule_existence_service.rb

Constant Summary collapse

SUCCESS_RESPONSE_RULE_EXISTS =
ServiceResponse.success(payload: { protection_rule_exists?: true }).freeze
SUCCESS_RESPONSE_RULE_DOESNT_EXIST =
ServiceResponse.success(payload: { protection_rule_exists?: false }).freeze
ERROR_RESPONSE_UNAUTHORIZED =
ServiceResponse.error(message: 'Unauthorized', reason: :unauthorized).freeze
ERROR_RESPONSE_INVALID_PACKAGE_TYPE =
ServiceResponse.error(message: 'Invalid package type',
reason: :invalid_package_type).freeze

Instance Attribute Summary

Attributes inherited from BaseProjectService

#project

Attributes inherited from BaseContainerService

#container, #current_user, #group, #params, #project

Instance Method Summary collapse

Methods inherited from BaseProjectService

#initialize

Methods inherited from BaseContainerService

#group_container?, #initialize, #namespace_container?, #project_container?, #project_group, #root_ancestor

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

This class inherits a constructor from BaseProjectService

Instance Method Details

#executeObject

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
# File 'app/services/packages/protection/check_rule_existence_service.rb', line 13

def execute
  return ERROR_RESPONSE_INVALID_PACKAGE_TYPE unless package_type_allowed?
  return ERROR_RESPONSE_UNAUTHORIZED unless current_user_can_create_package?

  return service_response_for(check_rule_exists_for_user) if current_user.is_a?(User)
  return service_response_for(check_rule_exists_for_deploy_token) if current_user.is_a?(DeployToken)

  raise ArgumentError, "Invalid user"
end