Merge branch 'Fix-pipeline-redirect' into 'master'
Redirect to the pipeline builds page when a build is canceled Closes #39161 See merge request gitlab-org/gitlab-ce!21595
This commit is contained in:
commit
6d7b9cf210
4 changed files with 62 additions and 18 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
class Projects::JobsController < Projects::ApplicationController
|
||||
include SendFileUpload
|
||||
include ContinueParams
|
||||
|
||||
before_action :build, except: [:index, :cancel_all]
|
||||
before_action :authorize_read_build!
|
||||
|
@ -107,7 +108,12 @@ class Projects::JobsController < Projects::ApplicationController
|
|||
return respond_422 unless @build.cancelable?
|
||||
|
||||
@build.cancel
|
||||
redirect_to build_path(@build)
|
||||
|
||||
if continue_params
|
||||
redirect_to continue_params[:to]
|
||||
else
|
||||
redirect_to builds_project_pipeline_path(@project, @build.pipeline.id)
|
||||
end
|
||||
end
|
||||
|
||||
def unschedule
|
||||
|
|
|
@ -101,7 +101,7 @@
|
|||
= sprite_icon('download')
|
||||
- if can?(current_user, :update_build, job)
|
||||
- if job.active?
|
||||
= link_to cancel_project_job_path(job.project, job, return_to: request.original_url), method: :post, title: 'Cancel', class: 'btn btn-build' do
|
||||
= link_to cancel_project_job_path(job.project, job, continue: { to: request.fullpath }), method: :post, title: 'Cancel', class: 'btn btn-build' do
|
||||
= icon('remove', class: 'cred')
|
||||
- elsif job.scheduled?
|
||||
.btn-group
|
||||
|
|
5
changelogs/unreleased/Fix-pipeline-redirect.yml
Normal file
5
changelogs/unreleased/Fix-pipeline-redirect.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Redirect to the pipeline builds page when a build is canceled
|
||||
merge_request:
|
||||
author: Eva Kadlecova
|
||||
type: fixed
|
|
@ -599,35 +599,68 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
|
|||
before do
|
||||
project.add_developer(user)
|
||||
sign_in(user)
|
||||
|
||||
post_cancel
|
||||
end
|
||||
|
||||
context 'when job is cancelable' do
|
||||
context 'when continue url is present' do
|
||||
let(:job) { create(:ci_build, :cancelable, pipeline: pipeline) }
|
||||
|
||||
it 'redirects to the canceled job page' do
|
||||
expect(response).to have_gitlab_http_status(:found)
|
||||
expect(response).to redirect_to(namespace_project_job_path(id: job.id))
|
||||
context 'when continue to is a safe url' do
|
||||
let(:url) { '/test' }
|
||||
|
||||
before do
|
||||
post_cancel(continue: { to: url })
|
||||
end
|
||||
|
||||
it 'redirects to the continue url' do
|
||||
expect(response).to have_gitlab_http_status(:found)
|
||||
expect(response).to redirect_to(url)
|
||||
end
|
||||
|
||||
it 'transits to canceled' do
|
||||
expect(job.reload).to be_canceled
|
||||
end
|
||||
end
|
||||
|
||||
it 'transits to canceled' do
|
||||
expect(job.reload).to be_canceled
|
||||
context 'when continue to is not a safe url' do
|
||||
let(:url) { 'http://example.com' }
|
||||
|
||||
it 'raises an error' do
|
||||
expect { cancel_with_redirect(url) }.to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when job is not cancelable' do
|
||||
let(:job) { create(:ci_build, :canceled, pipeline: pipeline) }
|
||||
context 'when continue url is not present' do
|
||||
before do
|
||||
post_cancel
|
||||
end
|
||||
|
||||
it 'returns unprocessable_entity' do
|
||||
expect(response).to have_gitlab_http_status(:unprocessable_entity)
|
||||
context 'when job is cancelable' do
|
||||
let(:job) { create(:ci_build, :cancelable, pipeline: pipeline) }
|
||||
|
||||
it 'redirects to the builds page' do
|
||||
expect(response).to have_gitlab_http_status(:found)
|
||||
expect(response).to redirect_to(builds_namespace_project_pipeline_path(id: pipeline.id))
|
||||
end
|
||||
|
||||
it 'transits to canceled' do
|
||||
expect(job.reload).to be_canceled
|
||||
end
|
||||
end
|
||||
|
||||
context 'when job is not cancelable' do
|
||||
let(:job) { create(:ci_build, :canceled, pipeline: pipeline) }
|
||||
|
||||
it 'returns unprocessable_entity' do
|
||||
expect(response).to have_gitlab_http_status(:unprocessable_entity)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def post_cancel
|
||||
post :cancel, namespace_id: project.namespace,
|
||||
project_id: project,
|
||||
id: job.id
|
||||
def post_cancel(additional_params = {})
|
||||
post :cancel, { namespace_id: project.namespace,
|
||||
project_id: project,
|
||||
id: job.id }.merge(additional_params)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue