Class: Ci::JobTokenScope::UpdatePoliciesService

Inherits:
BaseService
  • Object
show all
Includes:
EditScopeValidations, ScopeEventTracking
Defined in:
app/services/ci/job_token_scope/update_policies_service.rb

Constant Summary

Constants included from EditScopeValidations

EditScopeValidations::NotFoundError, EditScopeValidations::TARGET_DOES_NOT_EXIST, EditScopeValidations::TARGET_GROUP_UNAUTHORIZED_OR_UNFOUND, EditScopeValidations::TARGET_PROJECT_UNAUTHORIZED_OR_UNFOUND, EditScopeValidations::ValidationError

Constants inherited from BaseService

BaseService::UnauthorizedError

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from ScopeEventTracking

#track_event

Methods included from EditScopeValidations

#validate_group_remove!, #validate_source_project_and_target_group_access!, #validate_source_project_and_target_project_access!, #validate_target_exists!

Methods inherited from BaseService

#initialize

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 BaseService

Instance Method Details

#execute(target, default_permissions, policies) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/ci/job_token_scope/update_policies_service.rb', line 9

def execute(target, default_permissions, policies)
  validate_target_exists!(target)
  validate_permissions!(target)

  link = link_for(target)

  return error_link_not_found unless link

  if link.update(default_permissions: default_permissions, job_token_policies: policies)
    track_event(link, 'updated') if link.saved_change_to_default_permissions?

    ServiceResponse.success(payload: link)
  else
    error_updating(link)
  end

rescue EditScopeValidations::ValidationError
  error_no_permissions
rescue EditScopeValidations::NotFoundError
  error_target_not_found
end