Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
4d66019e
Commit
4d66019e
authored
May 27, 2020
by
Jarka Košanová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Redirect to the referrer when updating a service
- if a referrer is not empty
parent
1b3d3066
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
10 deletions
+40
-10
app/controllers/projects/services_controller.rb
app/controllers/projects/services_controller.rb
+3
-2
app/views/projects/services/_form.html.haml
app/views/projects/services/_form.html.haml
+1
-0
spec/controllers/projects/services_controller_spec.rb
spec/controllers/projects/services_controller_spec.rb
+33
-7
spec/views/projects/services/_form.haml_spec.rb
spec/views/projects/services/_form.haml_spec.rb
+3
-1
No files found.
app/controllers/projects/services_controller.rb
View file @
4d66019e
...
...
@@ -2,6 +2,7 @@
class
Projects::ServicesController
<
Projects
::
ApplicationController
include
ServiceParams
include
InternalRedirect
# Authorize
before_action
:authorize_admin_project!
...
...
@@ -26,8 +27,8 @@ class Projects::ServicesController < Projects::ApplicationController
respond_to
do
|
format
|
format
.
html
do
if
saved
redirect_to
project_settings_integrations_path
(
@project
),
notice:
success_message
target_url
=
safe_redirect_path
(
params
[
:redirect_to
]).
presence
||
project_settings_integrations_path
(
@project
)
redirect_to
target_url
,
notice:
success_message
else
render
'edit'
end
...
...
app/views/projects/services/_form.html.haml
View file @
4d66019e
...
...
@@ -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
|
=
render
'shared/service_settings'
,
form:
form
,
service:
@service
.footer-block.row-content-block
%input
{
id:
'services_redirect_to'
,
type:
'hidden'
,
name:
'redirect_to'
,
value:
request
.
referrer
}
=
service_save_button
=
link_to
_
(
'Cancel'
),
project_settings_integrations_path
(
@project
),
class:
'btn btn-cancel'
...
...
spec/controllers/projects/services_controller_spec.rb
View file @
4d66019e
...
...
@@ -134,24 +134,50 @@ describe Projects::ServicesController do
describe
'PUT #update'
do
describe
'as HTML'
do
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
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
context
'when param `active` is set to true'
do
it
'activates the service and redirects to integrations paths'
do
expect
(
response
).
to
redirect_to
(
project_settings_integrations_path
(
project
))
expect
(
flash
[
:notice
]).
to
eq
'Jira activated.'
let
(
:params
)
{
project_params
(
service:
service_params
,
redirect_to:
redirect
)
}
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
context
'when param `active` is set to false'
do
let
(
:service_params
)
{
{
active:
false
}
}
let
(
:message
)
{
'Jira settings saved, but not activated.'
}
it
'does not activate the service but saves the settings'
do
expect
(
flash
[
:notice
]).
to
eq
'Jira settings saved, but not activated.'
end
it_behaves_like
'service update'
end
end
...
...
spec/views/projects/services/_form.haml_spec.rb
View file @
4d66019e
...
...
@@ -15,7 +15,8 @@ describe 'projects/services/_form' do
allow
(
view
).
to
receive_messages
(
current_user:
user
,
can?:
true
,
current_application_settings:
Gitlab
::
CurrentSettings
.
current_application_settings
)
current_application_settings:
Gitlab
::
CurrentSettings
.
current_application_settings
,
request:
double
(
referrer:
'/services'
))
end
context
'commit_events and merge_request_events'
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 merge request is created/updated/merged'
)
expect
(
rendered
).
to
have_css
(
"input[name='redirect_to'][value='/services']"
,
count:
1
,
visible:
false
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment