Class: Ci::JobTokenScope::AddProjectService

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

Constant Summary

Constants included from EditScopeValidations

EditScopeValidations::TARGET_PROJECT_UNAUTHORIZED_OR_UNFOUND, EditScopeValidations::ValidationError

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from EditScopeValidations

#validate_edit!

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?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#add_project!(target_project) ⇒ Object


22
23
24
25
26
27
28
# File 'app/services/ci/job_token_scope/add_project_service.rb', line 22

def add_project!(target_project)
  ::Ci::JobToken::ProjectScopeLink.create!(
    source_project: project,
    target_project: target_project,
    added_by: current_user
  )
end

#execute(target_project) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/ci/job_token_scope/add_project_service.rb', line 8

def execute(target_project)
  validate_edit!(project, target_project, current_user)

  link = add_project!(target_project)
  ServiceResponse.success(payload: { project_link: link })

rescue ActiveRecord::RecordNotUnique
  ServiceResponse.error(message: "Target project is already in the job token scope")
rescue ActiveRecord::RecordInvalid => e
  ServiceResponse.error(message: e.message)
rescue EditScopeValidations::ValidationError => e
  ServiceResponse.error(message: e.message)
end