Send continue parameter on for cancel_path

In https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/21595
`ContinueParams` was introducted in the `Projects::JobController#cancel`
since `continue` parameter is not present for in `cancel_path` for
`Projects::JobController#show.sjon` the user is being redirect to the
pipeline page, where it should be redirected to the current job page
instead.

Add the `continue` parameter as a query string for `cancel_path`.
This commit is contained in:
Steve Azzopardi 2018-10-31 09:44:22 +01:00
parent 98a504ecbb
commit 8f36f1cad2
No known key found for this signature in database
GPG Key ID: 605BD4706E7DB47D
3 changed files with 52 additions and 14 deletions

View File

@ -9,7 +9,7 @@ class JobEntity < Grape::Entity
expose :started?, as: :started
expose :build_path do |build|
build.target_url || path_to(:namespace_project_job, build)
build_path(build)
end
expose :retry_path, if: -> (*) { retryable? } do |build|
@ -17,7 +17,11 @@ class JobEntity < Grape::Entity
end
expose :cancel_path, if: -> (*) { cancelable? } do |build|
path_to(:cancel_namespace_project_job, build)
path_to(
:cancel_namespace_project_job,
build,
{ continue: { to: build_path(build) } }
)
end
expose :play_path, if: -> (*) { playable? } do |build|
@ -60,8 +64,12 @@ class JobEntity < Grape::Entity
build.detailed_status(request.current_user)
end
def path_to(route, build)
send("#{route}_path", build.project.namespace, build.project, build) # rubocop:disable GitlabSecurity/PublicSend
def path_to(route, build, params = {})
send("#{route}_path", build.project.namespace, build.project, build, params) # rubocop:disable GitlabSecurity/PublicSend
end
def build_path(build)
build.target_url || path_to(:namespace_project_job, build)
end
def failed?

View File

@ -157,6 +157,28 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
end
end
context 'when job is running' do
context 'job is cancelable' do
let(:job) { create(:ci_build, :running, pipeline: pipeline) }
it 'cancel_path is present with correct redirect' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('job/job_details')
expect(json_response['cancel_path']).to include(CGI.escape(json_response['build_path']))
end
end
context 'with web terminal' do
let(:job) { create(:ci_build, :running, :with_runner_session, pipeline: pipeline) }
it 'exposes the terminal path' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('job/job_details')
expect(json_response['terminal_path']).to match(%r{/terminal})
end
end
end
context 'when job has artifacts' do
context 'with not expiry date' do
let(:job) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }
@ -185,16 +207,6 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
end
end
context 'when job has terminal' do
let(:job) { create(:ci_build, :running, :with_runner_session, pipeline: pipeline) }
it 'exposes the terminal path' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('job/job_details')
expect(json_response['terminal_path']).to match(%r{/terminal})
end
end
context 'when job passed with no trace' do
let(:job) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }

View File

@ -198,6 +198,24 @@ describe 'Jobs', :clean_gitlab_redis_shared_state do
end
end
context 'when job is running', :js do
let(:job) { create(:ci_build, :running, pipeline: pipeline) }
let(:job_url) { project_job_path(project, job) }
before do
visit job_url
wait_for_requests
end
context 'job is cancelable' do
it 'shows cancel button' do
click_link 'Cancel'
expect(page.current_path).to eq(job_url)
end
end
end
context "Job from other project" do
before do
visit project_job_path(project, job2)