Commit 37451dac authored by Justin Ho's avatar Justin Ho

Add feature flag to guard controller

- Use feature flag to render 404 Not Found while
feature is WIP
- Refactor private methods to be more readable
- Apply the refactor to projects/services_controller
parent bf0c1395
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
class Admin::IntegrationsController < Admin::ApplicationController class Admin::IntegrationsController < Admin::ApplicationController
include ServiceParams include ServiceParams
before_action :not_found, unless: :instance_level_integrations_enabled?
before_action :service, only: [:edit, :update, :test] before_action :service, only: [:edit, :update, :test]
def edit def edit
...@@ -28,6 +29,10 @@ class Admin::IntegrationsController < Admin::ApplicationController ...@@ -28,6 +29,10 @@ class Admin::IntegrationsController < Admin::ApplicationController
private private
def instance_level_integrations_enabled?
Feature.enabled?(:instance_level_integrations)
end
def project def project
# TODO: Change to something more meaningful # TODO: Change to something more meaningful
Project.first Project.first
...@@ -38,26 +43,24 @@ class Admin::IntegrationsController < Admin::ApplicationController ...@@ -38,26 +43,24 @@ class Admin::IntegrationsController < Admin::ApplicationController
end end
def success_message def success_message
if @service.active? message = @service.active? ? _('activated') : _('settings saved, but not activated')
_('%{service_title} activated.') % { service_title: @service.title }
else _('%{service_title} %{message}.') % { service_title: @service.title, message: message }
_('%{service_title} settings saved, but not activated.') % { service_title: @service.title }
end
end end
def service_test_response def service_test_response
if @service.update(service_params[:service]) unless @service.update(service_params[:service])
data = @service.test_data(project, current_user) return { error: true, message: _('Validations failed.'), service_response: @service.errors.full_messages.join(','), test_failed: false }
outcome = @service.test(data)
if outcome[:success]
{}
else
{ error: true, message: _('Test failed.'), service_response: outcome[:result].to_s, test_failed: true }
end
else
{ error: true, message: _('Validations failed.'), service_response: @service.errors.full_messages.join(','), test_failed: false }
end 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 rescue Gitlab::HTTP::BlockedUrlError => e
{ error: true, message: _('Test failed.'), service_response: e.message, test_failed: true } { error: true, message: _('Test failed.'), service_response: e.message, test_failed: true }
end end
......
...@@ -52,28 +52,26 @@ class Projects::ServicesController < Projects::ApplicationController ...@@ -52,28 +52,26 @@ class Projects::ServicesController < Projects::ApplicationController
private private
def service_test_response def service_test_response
if @service.update(service_params[:service]) unless @service.update(service_params[:service])
data = @service.test_data(project, current_user) return { error: true, message: _('Validations failed.'), service_response: @service.errors.full_messages.join(','), test_failed: false }
outcome = @service.test(data) end
if outcome[:success] data = @service.test_data(project, current_user)
{} outcome = @service.test(data)
else
{ error: true, message: _('Test failed.'), service_response: outcome[:result].to_s, test_failed: true } unless outcome[:success]
end return { error: true, message: _('Test failed.'), service_response: outcome[:result].to_s, test_failed: true }
else
{ error: true, message: _('Validations failed.'), service_response: @service.errors.full_messages.join(','), test_failed: false }
end end
{}
rescue Gitlab::HTTP::BlockedUrlError => e rescue Gitlab::HTTP::BlockedUrlError => e
{ error: true, message: _('Test failed.'), service_response: e.message, test_failed: true } { error: true, message: _('Test failed.'), service_response: e.message, test_failed: true }
end end
def success_message def success_message
if @service.active? message = @service.active? ? _('activated') : _('settings saved, but not activated')
_("%{service_title} activated.") % { service_title: @service.title }
else _('%{service_title} %{message}.') % { service_title: @service.title, message: message }
_("%{service_title} settings saved, but not activated.") % { service_title: @service.title }
end
end end
def service def service
......
...@@ -401,10 +401,7 @@ msgstr "" ...@@ -401,10 +401,7 @@ msgstr ""
msgid "%{screenreaderOnlyStart}Keyboard shorcuts%{screenreaderOnlyEnd} Enabled" msgid "%{screenreaderOnlyStart}Keyboard shorcuts%{screenreaderOnlyEnd} Enabled"
msgstr "" msgstr ""
msgid "%{service_title} activated." msgid "%{service_title} %{message}."
msgstr ""
msgid "%{service_title} settings saved, but not activated."
msgstr "" msgstr ""
msgid "%{size} GiB" msgid "%{size} GiB"
...@@ -23165,6 +23162,9 @@ msgid_plural "about %d hours" ...@@ -23165,6 +23162,9 @@ msgid_plural "about %d hours"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
msgid "activated"
msgstr ""
msgid "added %{created_at_timeago}" msgid "added %{created_at_timeago}"
msgstr "" msgstr ""
...@@ -24220,6 +24220,9 @@ msgstr "" ...@@ -24220,6 +24220,9 @@ msgstr ""
msgid "security Reports|There was an error creating the merge request" msgid "security Reports|There was an error creating the merge request"
msgstr "" msgstr ""
msgid "settings saved, but not activated"
msgstr ""
msgid "severity|Critical" msgid "severity|Critical"
msgstr "" msgstr ""
......
...@@ -11,6 +11,16 @@ describe Admin::IntegrationsController do ...@@ -11,6 +11,16 @@ describe Admin::IntegrationsController do
end end
describe '#edit' do describe '#edit' do
context 'when instance_level_integrations not enabled' do
it 'returns not_found' do
allow(Feature).to receive(:enabled?).with(:instance_level_integrations) { false }
get :edit, params: { id: Service.available_services_names.sample }
expect(response).to have_gitlab_http_status(:not_found)
end
end
Service.available_services_names.each do |integration_name| Service.available_services_names.each do |integration_name|
context "#{integration_name}" do context "#{integration_name}" do
it 'successfully displays the template' do it 'successfully displays the template' do
......
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