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,10 +22,8 @@ resources :pipelines, only: [:index, :new, :create, :show, :destroy] do ...@@ -22,10 +22,8 @@ resources :pipelines, only: [:index, :new, :create, :show, :destroy] do
get :test_reports_count get :test_reports_count
end end
member do resources :stages, only: [], param: :name, controller: 'pipelines/stages' do
resources :stages, only: [], param: :name do post :play_manual
post :play_manual
end
end end
resources :tests, only: [:show], param: :suite_name, controller: 'pipelines/tests' do resources :tests, only: [:show], param: :suite_name, controller: 'pipelines/tests' do
......
...@@ -18,7 +18,7 @@ module Gitlab ...@@ -18,7 +18,7 @@ module Gitlab
def action_path def action_path
pipeline = subject.pipeline 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 end
def action_method def action_method
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Projects::StagesController do RSpec.describe Projects::Pipelines::StagesController do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
...@@ -60,7 +60,7 @@ RSpec.describe Projects::StagesController do ...@@ -60,7 +60,7 @@ RSpec.describe Projects::StagesController do
post :play_manual, params: { post :play_manual, params: {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project, project_id: project,
id: pipeline.id, pipeline_id: pipeline.id,
stage_name: stage_name stage_name: stage_name
}, format: :json }, format: :json
end 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