application_settings_controller.rb 3.02 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 13
    if @application_setting.update_attributes(application_setting_params)
      redirect_to admin_application_settings_path,
        notice: 'Application settings saved successfully'
    else
      render :show
    end
14 15
  end

16 17 18
  def reset_runners_token
    @application_setting.reset_runners_registration_token!
    flash[:notice] = 'New runners registration token has been generated!'
19
    redirect_to admin_runners_path
20 21
  end

22
  def clear_repository_check_states
23
    RepositoryCheck::ClearWorker.perform_async
24 25 26

    redirect_to(
      admin_application_settings_path,
27
      notice: 'Started asynchronous removal of all repository check states.'
28 29 30
    )
  end

31 32 33
  private

  def set_application_setting
34
    @application_setting = ApplicationSetting.current
35 36 37
  end

  def application_setting_params
38
    restricted_levels = params[:application_setting][:restricted_visibility_levels]
39 40 41
    if restricted_levels.nil?
      params[:application_setting][:restricted_visibility_levels] = []
    else
42 43 44 45 46
      restricted_levels.map! do |level|
        level.to_i
      end
    end

47 48 49 50 51 52 53 54 55
    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

56 57 58 59
    enabled_oauth_sign_in_sources = params[:application_setting][:enabled_oauth_sign_in_sources]

    params[:application_setting][:disabled_oauth_sign_in_sources] =
      AuthHelper.button_based_providers.map(&:to_s) -
60
      Array(enabled_oauth_sign_in_sources)
61 62

    params[:application_setting].delete(:enabled_oauth_sign_in_sources)
63

64 65
    params.require(:application_setting).permit(
      :default_projects_limit,
66
      :default_branch_protection,
67 68
      :signup_enabled,
      :signin_enabled,
69 70
      :require_two_factor_authentication,
      :two_factor_grace_period,
71 72
      :gravatar_enabled,
      :sign_in_text,
73
      :help_page_text,
74
      :home_page_url,
75
      :after_sign_out_path,
76
      :max_attachment_size,
77
      :session_expire_delay,
Vinnie Okada's avatar
Vinnie Okada committed
78 79
      :default_project_visibility,
      :default_snippet_visibility,
80
      :default_group_visibility,
81
      :restricted_signup_domains_raw,
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
82
      :version_check_enabled,
83
      :admin_notification_email,
84
      :user_oauth_applications,
85
      :shared_runners_enabled,
86
      :shared_runners_text,
87
      :max_artifacts_size,
88 89
      :metrics_enabled,
      :metrics_host,
90
      :metrics_port,
91 92 93
      :metrics_pool_size,
      :metrics_timeout,
      :metrics_method_call_threshold,
94
      :metrics_sample_interval,
95 96 97
      :recaptcha_enabled,
      :recaptcha_site_key,
      :recaptcha_private_key,
Jeroen Nijhof's avatar
Jeroen Nijhof committed
98 99
      :sentry_enabled,
      :sentry_dsn,
100 101
      :akismet_enabled,
      :akismet_api_key,
102
      :email_author_in_body,
103
      :repository_checks_enabled,
104
      :metrics_packet_size,
105
      restricted_visibility_levels: [],
106 107
      import_sources: [],
      disabled_oauth_sign_in_sources: []
108 109 110
    )
  end
end