Read about our upcoming Code of Conduct on this issue

services_controller.rb 1.19 KB
Newer Older
1
2
# frozen_string_literal: true

3
class Admin::ServicesController < Admin::ApplicationController
4
5
  include ServiceParams

6
  before_action :whitelist_query_limiting, only: [:index]
7
  before_action :service, only: [:edit, :update]
8
9
10
11
12
13
14
15
16
17
18
19
20

  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
Lin Jen-Shin's avatar
Lin Jen-Shin committed
21
    if service.update(service_params[:service])
James Lopez's avatar
James Lopez committed
22
      PropagateServiceTemplateWorker.perform_async(service.id) if service.active?
23

24
25
26
27
28
29
30
31
32
33
      redirect_to admin_application_settings_services_path,
        notice: 'Application settings saved successfully'
    else
      render :edit
    end
  end

  private

  def services_templates
Lin Jen-Shin's avatar
Lin Jen-Shin committed
34
    Service.available_services_names.map do |service_name|
35
      service_template = "#{service_name}_service".camelize.constantize
Lin Jen-Shin's avatar
Lin Jen-Shin committed
36
      service_template.where(template: true).first_or_create
37
38
39
40
41
42
    end
  end

  def service
    @service ||= Service.where(id: params[:id], template: true).first
  end
43
44
45
46

  def whitelist_query_limiting
    Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42430')
  end
47
end