2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
class Projects::RunnerProjectsController < Projects::ApplicationController
|
2016-04-02 18:10:28 +05:30
|
|
|
before_action :authorize_admin_build!
|
2015-12-23 02:04:40 +05:30
|
|
|
|
|
|
|
layout 'project_settings'
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
feature_category :runner
|
2022-07-16 23:28:13 +05:30
|
|
|
urgency :low
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
def create
|
|
|
|
@runner = Ci::Runner.find(params[:runner_project][:runner_id])
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
return head(:forbidden) unless can?(current_user, :assign_runner, @runner)
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
path = project_runners_path(project)
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
if ::Ci::Runners::AssignRunnerService.new(@runner, @project, current_user).execute.success?
|
2023-07-09 08:55:56 +05:30
|
|
|
flash[:success] = s_('Runners|Runner assigned to project.')
|
|
|
|
redirect_to path
|
2015-12-23 02:04:40 +05:30
|
|
|
else
|
2021-06-08 01:23:25 +05:30
|
|
|
assign_to_messages = @runner.errors.messages[:assign_to]
|
|
|
|
alert = assign_to_messages&.join(',') || 'Failed adding runner to project'
|
|
|
|
|
|
|
|
redirect_to path, alert: alert
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
runner_project = project.runner_projects.find(params[:id])
|
2022-05-07 20:08:51 +05:30
|
|
|
|
|
|
|
::Ci::Runners::UnassignRunnerService.new(runner_project, current_user).execute
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
flash[:success] = s_('Runners|Runner unassigned from project.')
|
|
|
|
redirect_to project_runners_path(project), status: :found
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
end
|