2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-02-11 20:34:41 -05:00
|
|
|
class Admin::ServicesController < Admin::ApplicationController
|
2016-07-12 16:00:49 -04:00
|
|
|
include ServiceParams
|
|
|
|
|
2018-01-15 10:21:04 -05:00
|
|
|
before_action :whitelist_query_limiting, only: [:index]
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :service, only: [:edit, :update]
|
2015-02-11 20:34:41 -05:00
|
|
|
|
|
|
|
def index
|
|
|
|
@services = services_templates
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
unless service.present?
|
|
|
|
redirect_to admin_application_settings_services_path,
|
|
|
|
alert: "Service is unknown or it doesn't exist"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2018-07-02 06:43:06 -04:00
|
|
|
if service.update(service_params[:service])
|
2017-05-05 12:18:39 -04:00
|
|
|
PropagateServiceTemplateWorker.perform_async(service.id) if service.active?
|
2017-05-04 12:11:28 -04:00
|
|
|
|
2015-02-11 20:34:41 -05:00
|
|
|
redirect_to admin_application_settings_services_path,
|
|
|
|
notice: 'Application settings saved successfully'
|
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2015-02-11 20:34:41 -05:00
|
|
|
def services_templates
|
2016-08-31 14:15:43 -04:00
|
|
|
Service.available_services_names.map do |service_name|
|
2018-07-25 05:30:33 -04:00
|
|
|
service_template = "#{service_name}_service".camelize.constantize
|
2016-08-31 14:15:43 -04:00
|
|
|
service_template.where(template: true).first_or_create
|
2015-02-11 20:34:41 -05:00
|
|
|
end
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2015-02-11 20:34:41 -05:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2015-02-11 20:34:41 -05:00
|
|
|
def service
|
|
|
|
@service ||= Service.where(id: params[:id], template: true).first
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-01-15 10:21:04 -05:00
|
|
|
|
|
|
|
def whitelist_query_limiting
|
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42430')
|
|
|
|
end
|
2015-02-11 20:34:41 -05:00
|
|
|
end
|