debian-mirror-gitlab/app/services/ci/runners/unassign_runner_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
932 B
Ruby
Raw Normal View History

2022-05-07 20:08:51 +05:30
# frozen_string_literal: true
module Ci
module Runners
class UnassignRunnerService
# @param [Ci::RunnerProject] runner_project the runner/project association to destroy
# @param [User] user the user performing the operation
def initialize(runner_project, user)
@runner_project = runner_project
@runner = runner_project.runner
@project = 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')
end
2022-05-07 20:08:51 +05:30
2022-08-27 11:52:29 +05:30
if @runner_project.destroy
ServiceResponse.success
else
ServiceResponse.error(message: 'failed to destroy runner project')
end
2022-05-07 20:08:51 +05:30
end
private
attr_reader :runner, :project, :user
end
end
end
Ci::Runners::UnassignRunnerService.prepend_mod