BigW Consortium Gitlab

application_settings_controller.rb 4.67 KB
Newer Older
1
class Admin::ApplicationSettingsController < Admin::ApplicationController
2
  before_action :set_application_setting
3 4 5 6 7

  def show
  end

  def update
8 9 10 11 12
    successful = ApplicationSettings::UpdateService
      .new(@application_setting, current_user, application_setting_params)
      .execute

    if successful
13 14 15 16 17
      redirect_to admin_application_settings_path,
        notice: 'Application settings saved successfully'
    else
      render :show
    end
18 19
  end

20 21
  def usage_data
    respond_to do |format|
22 23 24 25 26 27
      format.html do
        usage_data = Gitlab::UsageData.data
        usage_data_json = params[:pretty] ? JSON.pretty_generate(usage_data) : usage_data.to_json

        render html: Gitlab::Highlight.highlight('payload.json', usage_data_json)
      end
28 29 30 31
      format.json { render json: Gitlab::UsageData.to_json }
    end
  end

32 33 34
  def reset_runners_token
    @application_setting.reset_runners_registration_token!
    flash[:notice] = 'New runners registration token has been generated!'
35
    redirect_to admin_runners_path
36 37
  end

38 39 40 41 42 43
  def reset_health_check_token
    @application_setting.reset_health_check_access_token!
    flash[:notice] = 'New health check access token has been generated!'
    redirect_to :back
  end

44
  def clear_repository_check_states
45
    RepositoryCheck::ClearWorker.perform_async
46 47 48

    redirect_to(
      admin_application_settings_path,
49
      notice: 'Started asynchronous removal of all repository check states.'
50 51 52
    )
  end

53 54 55
  private

  def set_application_setting
56
    @application_setting = ApplicationSetting.current
57 58 59
  end

  def application_setting_params
60 61 62 63 64 65 66 67 68
    import_sources = params[:application_setting][:import_sources]
    if import_sources.nil?
      params[:application_setting][:import_sources] = []
    else
      import_sources.map! do |source|
        source.to_str
      end
    end

69
    enabled_oauth_sign_in_sources = params[:application_setting].delete(:enabled_oauth_sign_in_sources)
70 71 72

    params[:application_setting][:disabled_oauth_sign_in_sources] =
      AuthHelper.button_based_providers.map(&:to_s) -
73
      Array(enabled_oauth_sign_in_sources)
74 75

    params[:application_setting][:restricted_visibility_levels]&.delete("")
76
    params.delete(:domain_blacklist_raw) if params[:domain_blacklist_file]
77

78
    params.require(:application_setting).permit(
79 80 81 82 83 84 85
      application_setting_params_ce
    )
  end

  def application_setting_params_ce
    [
      :admin_notification_email,
86
      :after_sign_out_path,
87 88 89 90
      :after_sign_up_text,
      :akismet_api_key,
      :akismet_enabled,
      :container_registry_token_expire_delay,
91
      :default_artifacts_expire_in,
92 93
      :default_branch_protection,
      :default_group_visibility,
Vinnie Okada committed
94
      :default_project_visibility,
95
      :default_projects_limit,
Vinnie Okada committed
96
      :default_snippet_visibility,
97 98
      :domain_blacklist_enabled,
      :domain_blacklist_file,
99 100 101 102 103 104
      :domain_blacklist_raw,
      :domain_whitelist_raw,
      :email_author_in_body,
      :enabled_git_access_protocol,
      :gravatar_enabled,
      :help_page_text,
105 106
      :help_page_hide_commercial_content,
      :help_page_support_url,
107 108 109 110 111 112 113 114 115
      :home_page_url,
      :housekeeping_bitmaps_enabled,
      :housekeeping_enabled,
      :housekeeping_full_repack_period,
      :housekeeping_gc_period,
      :housekeeping_incremental_repack_period,
      :html_emails_enabled,
      :koding_enabled,
      :koding_url,
116 117
      :plantuml_enabled,
      :plantuml_url,
118
      :max_artifacts_size,
119
      :max_attachment_size,
Kamil Trzcinski committed
120
      :max_pages_size,
121 122 123
      :metrics_enabled,
      :metrics_host,
      :metrics_method_call_threshold,
124 125 126
      :metrics_packet_size,
      :metrics_pool_size,
      :metrics_port,
127
      :metrics_sample_interval,
128
      :metrics_timeout,
129 130
      :recaptcha_enabled,
      :recaptcha_private_key,
131
      :recaptcha_site_key,
132
      :repository_checks_enabled,
133 134 135 136 137 138 139
      :require_two_factor_authentication,
      :session_expire_delay,
      :sign_in_text,
      :signin_enabled,
      :signup_enabled,
      :sentry_dsn,
      :sentry_enabled,
140 141
      :clientside_sentry_dsn,
      :clientside_sentry_enabled,
142
      :send_user_confirmation_email,
143 144
      :shared_runners_enabled,
      :shared_runners_text,
145
      :sidekiq_throttling_enabled,
146
      :sidekiq_throttling_factor,
147 148 149
      :two_factor_grace_period,
      :user_default_external,
      :user_oauth_applications,
150 151 152
      :unique_ips_limit_per_user,
      :unique_ips_limit_time_window,
      :unique_ips_limit_enabled,
153
      :version_check_enabled,
154
      :terminal_max_session_time,
155
      :polling_interval_multiplier,
Pawel Chojnacki committed
156
      :prometheus_metrics_enabled,
157
      :usage_ping_enabled,
158 159 160

      disabled_oauth_sign_in_sources: [],
      import_sources: [],
161
      repository_storages: [],
162
      restricted_visibility_levels: [],
163
      sidekiq_throttling_queues: []
164
    ]
165 166
  end
end