Commit 4193baf2 authored by Maxime Orefice's avatar Maxime Orefice

Refactor StagesController with abstract controller

This MR makes sure we do not leak pipeline actions to our
controller by inheriting from our new abstract controller.
parent ea86b698
# frozen_string_literal: true
module Projects
module Pipelines
class StagesController < Projects::Pipelines::ApplicationController
before_action :authorize_update_pipeline!
def play_manual
::Ci::PlayManualStageService
.new(@project, current_user, pipeline: pipeline)
.execute(stage)
respond_to do |format|
format.json do
render json: StageSerializer
.new(project: @project, current_user: @current_user)
.represent(stage)
end
end
end
private
def stage
@pipeline_stage ||= pipeline.find_stage_by_name!(params[:stage_name])
end
end
end
end
# frozen_string_literal: true
class Projects::StagesController < Projects::PipelinesController
before_action :authorize_update_pipeline!
def play_manual
::Ci::PlayManualStageService
.new(@project, current_user, pipeline: pipeline)
.execute(stage)
respond_to do |format|
format.json do
render json: StageSerializer
.new(project: @project, current_user: @current_user)
.represent(stage)
end
end
end
private
def stage
@pipeline_stage ||= pipeline.find_stage_by_name!(params[:stage_name])
end
end
......@@ -22,11 +22,9 @@ resources :pipelines, only: [:index, :new, :create, :show, :destroy] do
get :test_reports_count
end
member do
resources :stages, only: [], param: :name do
resources :stages, only: [], param: :name, controller: 'pipelines/stages' do
post :play_manual
end
end
resources :tests, only: [:show], param: :suite_name, controller: 'pipelines/tests' do
collection do
......
......@@ -18,7 +18,7 @@ module Gitlab
def action_path
pipeline = subject.pipeline
project_stage_play_manual_path(pipeline.project, pipeline, subject.name)
project_pipeline_stage_play_manual_path(pipeline.project, pipeline, subject.name)
end
def action_method
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Projects::StagesController do
RSpec.describe Projects::Pipelines::StagesController do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
......@@ -60,7 +60,7 @@ RSpec.describe Projects::StagesController do
post :play_manual, params: {
namespace_id: project.namespace,
project_id: project,
id: pipeline.id,
pipeline_id: pipeline.id,
stage_name: stage_name
}, format: :json
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment