runner_projects_controller.rb 847 Bytes
Newer Older
1 2
module Ci
  class RunnerProjectsController < Ci::ApplicationController
Valery Sizov's avatar
Valery Sizov committed
3 4 5
    before_action :authenticate_user!
    before_action :project
    before_action :authorize_manage_project!
6 7 8 9

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

10
      return head(403) unless current_user.ci_authorized_runners.include?(@runner)
11

12 13
      path = runners_path(@project.gl_project)

14
      if @runner.assign_to(project, current_user)
15
        redirect_to path
16
      else
17
        redirect_to path, alert: 'Failed adding runner to project'
18 19 20 21 22 23 24
      end
    end

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

25
      redirect_to runners_path(@project.gl_project)
26 27 28 29 30 31 32 33 34
    end

    private

    def project
      @project ||= Ci::Project.find(params[:project_id])
    end
  end
end