2022-05-07 20:08:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
|
|
|
module Runners
|
|
|
|
class AssignRunnerService
|
|
|
|
# @param [Ci::Runner] runner: the runner to assign to a project
|
|
|
|
# @param [Project] project: the new project to assign the runner to
|
|
|
|
# @param [User] user: the user performing the operation
|
|
|
|
def initialize(runner, project, user)
|
|
|
|
@runner = runner
|
|
|
|
@project = project
|
|
|
|
@user = user
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2022-08-27 11:52:29 +05:30
|
|
|
unless @user.present? && @user.can?(:assign_runner, @runner)
|
|
|
|
return ServiceResponse.error(message: 'user not allowed to assign runner', http_status: :forbidden)
|
|
|
|
end
|
2022-05-07 20:08:51 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
if @runner.assign_to(@project, @user)
|
|
|
|
ServiceResponse.success
|
|
|
|
else
|
|
|
|
ServiceResponse.error(message: 'failed to assign runner')
|
|
|
|
end
|
2022-05-07 20:08:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :runner, :project, :user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Ci::Runners::AssignRunnerService.prepend_mod
|