diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-13 12:09:23 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-13 12:09:23 +0300 |
commit | 4cb5e5011abfe8d50ac3a7ebd0018c563c6d7af4 (patch) | |
tree | 82591df15758864325897043f855b4e4dfcb6a56 /app/controllers/admin | |
parent | 0301a0cad0063d76b1607358dc6c711ea043fdda (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/controllers/admin')
-rw-r--r-- | app/controllers/admin/integrations_controller.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/app/controllers/admin/integrations_controller.rb b/app/controllers/admin/integrations_controller.rb new file mode 100644 index 00000000000..715aa882bda --- /dev/null +++ b/app/controllers/admin/integrations_controller.rb @@ -0,0 +1,67 @@ +# 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 + + private + + def instance_level_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 } + end +end |