Commit 48ee4c5e authored by Markus Koller's avatar Markus Koller

Merge branch '215539-jira-setup-redirect' into 'master'

Redirect to the referrer when updating a service

See merge request gitlab-org/gitlab!33165
parents db3f8632 4d66019e
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
class Projects::ServicesController < Projects::ApplicationController class Projects::ServicesController < Projects::ApplicationController
include ServiceParams include ServiceParams
include InternalRedirect
# Authorize # Authorize
before_action :authorize_admin_project! before_action :authorize_admin_project!
...@@ -26,8 +27,8 @@ class Projects::ServicesController < Projects::ApplicationController ...@@ -26,8 +27,8 @@ class Projects::ServicesController < Projects::ApplicationController
respond_to do |format| respond_to do |format|
format.html do format.html do
if saved if saved
redirect_to project_settings_integrations_path(@project), target_url = safe_redirect_path(params[:redirect_to]).presence || project_settings_integrations_path(@project)
notice: success_message redirect_to target_url, notice: success_message
else else
render 'edit' render 'edit'
end end
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
= form_for(@service, as: :service, url: scoped_integration_path(@service), method: :put, html: { class: 'gl-show-field-errors integration-settings-form js-integration-settings-form', data: { 'can-test' => @service.can_test?, 'test-url' => test_project_service_path(@project, @service) } }) do |form| = form_for(@service, as: :service, url: scoped_integration_path(@service), method: :put, html: { class: 'gl-show-field-errors integration-settings-form js-integration-settings-form', data: { 'can-test' => @service.can_test?, 'test-url' => test_project_service_path(@project, @service) } }) do |form|
= render 'shared/service_settings', form: form, service: @service = render 'shared/service_settings', form: form, service: @service
.footer-block.row-content-block .footer-block.row-content-block
%input{ id: 'services_redirect_to', type: 'hidden', name: 'redirect_to', value: request.referrer }
= service_save_button = service_save_button
&nbsp; &nbsp;
= link_to _('Cancel'), project_settings_integrations_path(@project), class: 'btn btn-cancel' = link_to _('Cancel'), project_settings_integrations_path(@project), class: 'btn btn-cancel'
......
...@@ -134,24 +134,50 @@ describe Projects::ServicesController do ...@@ -134,24 +134,50 @@ describe Projects::ServicesController do
describe 'PUT #update' do describe 'PUT #update' do
describe 'as HTML' do describe 'as HTML' do
let(:service_params) { { active: true } } let(:service_params) { { active: true } }
let(:params) { project_params(service: service_params) }
let(:message) { 'Jira activated.' }
let(:redirect_url) { project_settings_integrations_path(project) }
before do before do
put :update, params: project_params(service: service_params) put :update, params: params
end
shared_examples 'service update' do
it 'redirects to the correct url with a flash message' do
expect(response).to redirect_to(redirect_url)
expect(flash[:notice]).to eq(message)
end
end end
context 'when param `active` is set to true' do context 'when param `active` is set to true' do
it 'activates the service and redirects to integrations paths' do let(:params) { project_params(service: service_params, redirect_to: redirect) }
expect(response).to redirect_to(project_settings_integrations_path(project))
expect(flash[:notice]).to eq 'Jira activated.' context 'when redirect_to param is present' do
let(:redirect) { '/redirect_here' }
let(:redirect_url) { redirect }
it_behaves_like 'service update'
end
context 'when redirect_to is an external domain' do
let(:redirect) { 'http://examle.com' }
it_behaves_like 'service update'
end
context 'when redirect_to param is an empty string' do
let(:redirect) { '' }
it_behaves_like 'service update'
end end
end end
context 'when param `active` is set to false' do context 'when param `active` is set to false' do
let(:service_params) { { active: false } } let(:service_params) { { active: false } }
let(:message) { 'Jira settings saved, but not activated.' }
it 'does not activate the service but saves the settings' do it_behaves_like 'service update'
expect(flash[:notice]).to eq 'Jira settings saved, but not activated.'
end
end end
end end
......
...@@ -15,7 +15,8 @@ describe 'projects/services/_form' do ...@@ -15,7 +15,8 @@ describe 'projects/services/_form' do
allow(view).to receive_messages(current_user: user, allow(view).to receive_messages(current_user: user,
can?: true, can?: true,
current_application_settings: Gitlab::CurrentSettings.current_application_settings) current_application_settings: Gitlab::CurrentSettings.current_application_settings,
request: double(referrer: '/services'))
end end
context 'commit_events and merge_request_events' do context 'commit_events and merge_request_events' do
...@@ -30,6 +31,7 @@ describe 'projects/services/_form' do ...@@ -30,6 +31,7 @@ describe 'projects/services/_form' do
expect(rendered).to have_content('Event will be triggered when a commit is created/updated') expect(rendered).to have_content('Event will be triggered when a commit is created/updated')
expect(rendered).to have_content('Event will be triggered when a merge request is created/updated/merged') expect(rendered).to have_content('Event will be triggered when a merge request is created/updated/merged')
expect(rendered).to have_css("input[name='redirect_to'][value='/services']", count: 1, visible: false)
end end
end end
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