application_settings_controller.rb 3.34 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 23 24 25 26 27
  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

28
  def clear_repository_check_states
29
    RepositoryCheck::ClearWorker.perform_async
30 31 32

    redirect_to(
      admin_application_settings_path,
33
      notice: 'Started asynchronous removal of all repository check states.'
34 35 36
    )
  end

37 38 39
  private

  def set_application_setting
40
    @application_setting = ApplicationSetting.current
41 42 43
  end

  def application_setting_params
44
    restricted_levels = params[:application_setting][:restricted_visibility_levels]
45 46 47
    if restricted_levels.nil?
      params[:application_setting][:restricted_visibility_levels] = []
    else
48 49 50 51 52
      restricted_levels.map! do |level|
        level.to_i
      end
    end

53 54 55 56 57 58 59 60 61
    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

62
    enabled_oauth_sign_in_sources = params[:application_setting].delete(:enabled_oauth_sign_in_sources)
63 64 65

    params[:application_setting][:disabled_oauth_sign_in_sources] =
      AuthHelper.button_based_providers.map(&:to_s) -
66
      Array(enabled_oauth_sign_in_sources)
67

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