Read about our upcoming Code of Conduct on this issue

application_settings_controller.rb 4.09 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
22
  def reset_runners_token
    @application_setting.reset_runners_registration_token!
    flash[:notice] = 'New runners registration token has been generated!'
23
    redirect_to admin_runners_path
24
25
  end

26
27
28
29
30
31
  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

32
  def clear_repository_check_states
33
    RepositoryCheck::ClearWorker.perform_async
34
35
36

    redirect_to(
      admin_application_settings_path,
37
      notice: 'Started asynchronous removal of all repository check states.'
38
39
40
    )
  end

41
42
43
  private

  def set_application_setting
44
    @application_setting = ApplicationSetting.current
45
46
47
  end

  def application_setting_params
48
    restricted_levels = params[:application_setting][:restricted_visibility_levels]
Vinnie Okada's avatar
Vinnie Okada committed
49
50
51
    if restricted_levels.nil?
      params[:application_setting][:restricted_visibility_levels] = []
    else
52
53
54
55
56
      restricted_levels.map! do |level|
        level.to_i
      end
    end

57
58
59
60
61
62
63
64
65
    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

66
    enabled_oauth_sign_in_sources = params[:application_setting].delete(:enabled_oauth_sign_in_sources)
67
68
69

    params[:application_setting][:disabled_oauth_sign_in_sources] =
      AuthHelper.button_based_providers.map(&:to_s) -
70
      Array(enabled_oauth_sign_in_sources)
71
    params.delete(:domain_blacklist_raw) if params[:domain_blacklist_file]
72

73
    params.require(:application_setting).permit(
74
75
76
77
78
79
80
      application_setting_params_ce
    )
  end

  def application_setting_params_ce
    [
      :admin_notification_email,
81
      :after_sign_out_path,
82
83
84
85
86
87
      :after_sign_up_text,
      :akismet_api_key,
      :akismet_enabled,
      :container_registry_token_expire_delay,
      :default_branch_protection,
      :default_group_visibility,
Vinnie Okada's avatar
Vinnie Okada committed
88
      :default_project_visibility,
89
      :default_projects_limit,
Vinnie Okada's avatar
Vinnie Okada committed
90
      :default_snippet_visibility,
91
92
      :domain_blacklist_enabled,
      :domain_blacklist_file,
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
      :domain_blacklist_raw,
      :domain_whitelist_raw,
      :email_author_in_body,
      :enabled_git_access_protocol,
      :gravatar_enabled,
      :help_page_text,
      :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,
108
109
      :plantuml_enabled,
      :plantuml_url,
Kamil Trzcinski's avatar
Kamil Trzcinski committed
110
      :max_artifacts_size,
111
      :max_attachment_size,
Kamil Trzcinski's avatar
Kamil Trzcinski committed
112
      :max_pages_size,
113
114
115
      :metrics_enabled,
      :metrics_host,
      :metrics_method_call_threshold,
116
117
118
      :metrics_packet_size,
      :metrics_pool_size,
      :metrics_port,
119
      :metrics_sample_interval,
120
      :metrics_timeout,
121
122
      :recaptcha_enabled,
      :recaptcha_private_key,
123
      :recaptcha_site_key,
124
      :repository_checks_enabled,
125
126
127
128
129
130
131
      :require_two_factor_authentication,
      :session_expire_delay,
      :sign_in_text,
      :signin_enabled,
      :signup_enabled,
      :sentry_dsn,
      :sentry_enabled,
132
      :send_user_confirmation_email,
133
134
      :shared_runners_enabled,
      :shared_runners_text,
135
      :sidekiq_throttling_enabled,
136
      :sidekiq_throttling_factor,
137
138
139
140
141
142
143
      :two_factor_grace_period,
      :user_default_external,
      :user_oauth_applications,
      :version_check_enabled,

      disabled_oauth_sign_in_sources: [],
      import_sources: [],
144
      repository_storages: [],
145
      restricted_visibility_levels: [],
146
      sidekiq_throttling_queues: []
147
    ]
148
149
  end
end