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
26ac363c
Commit
26ac363c
authored
Mar 20, 2020
by
Justin Ho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract shared integration controller actions
Use a single concern for all integrations code
parent
c796f829
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
129 deletions
+101
-129
app/controllers/admin/integrations_controller.rb
app/controllers/admin/integrations_controller.rb
+4
-56
app/controllers/concerns/integrations_actions.rb
app/controllers/concerns/integrations_actions.rb
+93
-0
app/controllers/groups/settings/integrations_controller.rb
app/controllers/groups/settings/integrations_controller.rb
+4
-73
No files found.
app/controllers/admin/integrations_controller.rb
View file @
26ac363c
# frozen_string_literal: true
class
Admin::IntegrationsController
<
Admin
::
ApplicationController
include
ServiceParams
before_action
:not_found
,
unless: :instance_level_integrations_enabled?
before_action
:service
,
only:
[
:edit
,
:update
,
:test
]
def
edit
end
def
update
@service
.
attributes
=
service_params
[
:service
]
if
@service
.
save
(
context: :manual_change
)
redirect_to
edit_admin_application_settings_integration_path
(
@service
),
notice:
success_message
else
render
:edit
end
end
def
test
if
@service
.
can_test?
render
json:
service_test_response
,
status: :ok
else
render
json:
{},
status: :not_found
end
end
include
IntegrationsActions
private
def
in
stance_level_in
tegrations_enabled?
def
integrations_enabled?
Feature
.
enabled?
(
:instance_level_integrations
)
end
def
project
# TODO: Change to something more meaningful
Project
.
first
end
def
service
@service
||=
project
.
find_or_initialize_service
(
params
[
:id
])
end
def
success_message
message
=
@service
.
active?
?
_
(
'activated'
)
:
_
(
'settings saved, but not activated'
)
_
(
'%{service_title} %{message}.'
)
%
{
service_title:
@service
.
title
,
message:
message
}
end
def
service_test_response
unless
@service
.
update
(
service_params
[
:service
])
return
{
error:
true
,
message:
_
(
'Validations failed.'
),
service_response:
@service
.
errors
.
full_messages
.
join
(
','
),
test_failed:
false
}
end
data
=
@service
.
test_data
(
project
,
current_user
)
outcome
=
@service
.
test
(
data
)
unless
outcome
[
:success
]
return
{
error:
true
,
message:
_
(
'Test failed.'
),
service_response:
outcome
[
:result
].
to_s
,
test_failed:
true
}
end
{}
rescue
Gitlab
::
HTTP
::
BlockedUrlError
=>
e
{
error:
true
,
message:
_
(
'Test failed.'
),
service_response:
e
.
message
,
test_failed:
true
}
def
scoped_edit_integration_path
(
integration
)
edit_admin_application_settings_integration_path
(
integration
)
end
end
app/controllers/concerns/integrations_actions.rb
0 → 100644
View file @
26ac363c
# frozen_string_literal: true
module
IntegrationsActions
extend
ActiveSupport
::
Concern
included
do
include
ServiceParams
before_action
:not_found
,
unless: :integrations_enabled?
before_action
:integration
,
only:
[
:edit
,
:update
,
:test
]
end
def
edit
render
'shared/integrations/edit'
end
def
update
integration
.
attributes
=
service_params
[
:service
]
saved
=
integration
.
save
(
context: :manual_change
)
respond_to
do
|
format
|
format
.
html
do
if
saved
redirect_to
scoped_edit_integration_path
(
integration
),
notice:
success_message
else
render
'shared/integrations/edit'
end
end
format
.
json
do
status
=
saved
?
:ok
:
:unprocessable_entity
render
json:
serialize_as_json
,
status:
status
end
end
end
def
test
if
integration
.
can_test?
render
json:
service_test_response
,
status: :ok
else
render
json:
{},
status: :not_found
end
end
private
def
integrations_enabled?
false
end
def
project
# TODO: Change to something more meaningful
Project
.
first
end
def
integration
# Using instance variable `@service` still required as it's used in ServiceParams
# and app/views/shared/_service_settings.html.haml. Should be removed once
# those 2 are refactored to use `@integration`.
@integration
=
@service
||=
project
.
find_or_initialize_service
(
params
[
:id
])
# rubocop:disable Gitlab/ModuleWithInstanceVariables
end
def
success_message
message
=
integration
.
active?
?
_
(
'activated'
)
:
_
(
'settings saved, but not activated'
)
_
(
'%{service_title} %{message}.'
)
%
{
service_title:
integration
.
title
,
message:
message
}
end
def
serialize_as_json
integration
.
as_json
(
only:
integration
.
json_fields
)
.
merge
(
errors:
integration
.
errors
.
as_json
)
end
def
service_test_response
unless
integration
.
update
(
service_params
[
:service
])
return
{
error:
true
,
message:
_
(
'Validations failed.'
),
service_response:
integration
.
errors
.
full_messages
.
join
(
','
),
test_failed:
false
}
end
data
=
integration
.
test_data
(
project
,
current_user
)
outcome
=
integration
.
test
(
data
)
unless
outcome
[
:success
]
return
{
error:
true
,
message:
_
(
'Test failed.'
),
service_response:
outcome
[
:result
].
to_s
,
test_failed:
true
}
end
{}
rescue
Gitlab
::
HTTP
::
BlockedUrlError
=>
e
{
error:
true
,
message:
_
(
'Test failed.'
),
service_response:
e
.
message
,
test_failed:
true
}
end
end
app/controllers/groups/settings/integrations_controller.rb
View file @
26ac363c
...
...
@@ -3,87 +3,18 @@
module
Groups
module
Settings
class
IntegrationsController
<
Groups
::
ApplicationController
include
ServiceParam
s
include
IntegrationsAction
s
before_action
:not_found
,
unless: :group_level_integrations_enabled?
before_action
:authorize_admin_group!
before_action
:service
,
only:
[
:edit
,
:update
,
:test
]
def
edit
end
def
update
@service
.
attributes
=
service_params
[
:service
]
saved
=
@service
.
save
(
context: :manual_change
)
respond_to
do
|
format
|
format
.
html
do
if
saved
redirect_to
edit_group_settings_integration_path
(
@group
,
@service
),
notice:
success_message
else
render
:edit
end
end
format
.
json
do
status
=
saved
?
:ok
:
:unprocessable_entity
render
json:
serialize_as_json
,
status:
status
end
end
end
def
test
if
@service
.
can_test?
render
json:
service_test_response
,
status: :ok
else
render
json:
{},
status: :not_found
end
end
private
def
group_level_
integrations_enabled?
def
integrations_enabled?
Feature
.
enabled?
(
:group_level_integrations
)
end
def
project
# TODO: Change to something more meaningful
Project
.
first
end
def
service
@service
||=
project
.
find_or_initialize_service
(
params
[
:id
])
end
def
success_message
message
=
@service
.
active?
?
_
(
'activated'
)
:
_
(
'settings saved, but not activated'
)
_
(
'%{service_title} %{message}.'
)
%
{
service_title:
@service
.
title
,
message:
message
}
end
def
serialize_as_json
@service
.
as_json
(
only:
@service
.
json_fields
)
.
merge
(
errors:
@service
.
errors
.
as_json
)
end
def
service_test_response
unless
@service
.
update
(
service_params
[
:service
])
return
{
error:
true
,
message:
_
(
'Validations failed.'
),
service_response:
@service
.
errors
.
full_messages
.
join
(
','
),
test_failed:
false
}
end
data
=
@service
.
test_data
(
project
,
current_user
)
outcome
=
@service
.
test
(
data
)
unless
outcome
[
:success
]
return
{
error:
true
,
message:
_
(
'Test failed.'
),
service_response:
outcome
[
:result
].
to_s
,
test_failed:
true
}
end
{}
rescue
Gitlab
::
HTTP
::
BlockedUrlError
=>
e
{
error:
true
,
message:
_
(
'Test failed.'
),
service_response:
e
.
message
,
test_failed:
true
}
def
scoped_edit_integration_path
(
integration
)
edit_group_settings_integration_path
(
@group
,
integration
)
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