Welcome to mirror list, hosted at ThFree Co, Russian Federation.

runner_projects_controller.rb « projects « controllers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 34ce8df202b7e47ab83a416a58a1509b8a3fac6f (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
32
33
34
35
# frozen_string_literal: true

class Projects::RunnerProjectsController < Projects::ApplicationController
  before_action :authorize_admin_build!

  layout 'project_settings'

  feature_category :runner
  urgency :low

  def create
    @runner = Ci::Runner.find(params[:runner_project][:runner_id])

    return head(403) unless can?(current_user, :assign_runner, @runner)

    path = project_runners_path(project)

    if ::Ci::Runners::AssignRunnerService.new(@runner, @project, current_user).execute
      redirect_to path, notice: s_('Runners|Runner assigned to project.')
    else
      assign_to_messages = @runner.errors.messages[:assign_to]
      alert = assign_to_messages&.join(',') || 'Failed adding runner to project'

      redirect_to path, alert: alert
    end
  end

  def destroy
    runner_project = project.runner_projects.find(params[:id])

    ::Ci::Runners::UnassignRunnerService.new(runner_project, current_user).execute

    redirect_to project_runners_path(project), status: :found, notice: s_('Runners|Runner unassigned from project.')
  end
end