blob: 4f745042f074e9598f616368326c36f5a20f542b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# frozen_string_literal: true
module Ci
module JobTokenScope
class AddProjectService < ::BaseService
include EditScopeValidations
def execute(target_project, direction: :outbound)
validate_edit!(project, target_project, current_user)
link = allowlist(direction)
.add!(target_project, user: current_user)
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
private
def allowlist(direction)
Ci::JobToken::Allowlist.new(project, direction: direction)
end
end
end
end
|