Commit c796f829 authored by Justin Ho's avatar Justin Ho

Add CRUD for Group-Level Integrations

Add routes, controller, views, assets to allow user to
edit / update / test a group-level integration.
parent 550d687c
import IntegrationSettingsForm from '~/integrations/integration_settings_form';
import PrometheusMetrics from '~/prometheus_metrics/prometheus_metrics';
import initAlertsSettings from '~/alerts_service_settings';
document.addEventListener('DOMContentLoaded', () => {
const prometheusSettingsWrapper = document.querySelector('.js-prometheus-metrics-monitoring');
const integrationSettingsForm = new IntegrationSettingsForm('.js-integration-settings-form');
integrationSettingsForm.init();
if (prometheusSettingsWrapper) {
const prometheusMetrics = new PrometheusMetrics('.js-prometheus-metrics-monitoring');
prometheusMetrics.loadActiveMetrics();
}
initAlertsSettings(document.querySelector('.js-alerts-service-settings'));
});
# frozen_string_literal: true
module Groups
module Settings
class IntegrationsController < Groups::ApplicationController
include ServiceParams
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?
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 }
end
end
end
end
%h3.page-title
= @service.title
%p= @service.description
= form_for @service, as: :service, url: group_settings_integration_path, method: :put, html: { class: 'gl-show-field-errors fieldset-form integration-settings-form js-integration-settings-form', data: { 'can-test' => @service.can_test?, 'test-url' => test_group_settings_integration_path(@group, @service) } } do |form|
= render 'shared/service_settings', form: form, service: @service
- if @service.editable?
.footer-block.row-content-block
= service_save_button(@service)
= link_to _('Cancel'), group_settings_integration_path, class: 'btn btn-cancel'
- add_to_breadcrumbs _('Integrations'), group_settings_integration_path
- breadcrumb_title @service.title
- page_title @service.title, _('Integrations')
= render 'form'
......@@ -121,7 +121,7 @@ namespace :admin do
get '/', to: redirect('admin/application_settings/general'), as: nil
resources :services, only: [:index, :edit, :update]
resources :integrations, only: [:edit, :update, :test] do
resources :integrations, only: [:edit, :update] do
member do
put :test
end
......
......@@ -31,6 +31,12 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
patch :update_auto_devops
post :create_deploy_token, path: 'deploy_token/create'
end
resources :integrations, only: [:edit, :update] do
member do
put :test
end
end
end
resource :variables, only: [:show, :update]
......
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