Read about our upcoming Code of Conduct on this issue

application_settings_helper.rb 5.64 KB
Newer Older
1
module ApplicationSettingsHelper
2
  extend self
3
4
5

  include Gitlab::CurrentSettings

Douwe Maan's avatar
Douwe Maan committed
6
7
  delegate  :gravatar_enabled?,
            :signup_enabled?,
8
            :password_authentication_enabled?,
Douwe Maan's avatar
Douwe Maan committed
9
10
11
            :akismet_enabled?,
            :koding_enabled?,
            to: :current_application_settings
12

13
14
15
16
  def user_oauth_applications?
    current_application_settings.user_oauth_applications
  end

17
  def allowed_protocols_present?
18
    current_application_settings.enabled_git_access_protocol.present?
19
20
21
  end

  def enabled_protocol
22
    case current_application_settings.enabled_git_access_protocol
23
24
25
26
27
28
29
    when 'http'
      gitlab_config.protocol
    when 'ssh'
      'ssh'
    end
  end

30
  def enabled_project_button(project, protocol)
31
32
    case protocol
    when 'ssh'
33
      ssh_clone_button(project, 'bottom', append_link: false)
34
    else
35
      http_clone_button(project, 'bottom', append_link: false)
36
37
38
    end
  end

39
40
  # Return a group of checkboxes that use Bootstrap's button plugin for a
  # toggle button effect.
41
  def restricted_level_checkboxes(help_block_id, checkbox_name)
42
    Gitlab::VisibilityLevel.values.map do |level|
43
      checked = restricted_visibility_levels(true).include?(level)
44
      css_class = checked ? 'active' : ''
45
      tag_name = "application_setting_visibility_level_#{level}"
46

47
      label_tag(tag_name, class: css_class) do
48
49
        check_box_tag(checkbox_name, level, checked,
                      autocomplete: 'off',
50
                      'aria-describedby' => help_block_id,
51
                      id: tag_name) + visibility_level_icon(level) + visibility_level_label(level)
52
53
54
      end
    end
  end
55
56
57
58
59
60

  # Return a group of checkboxes that use Bootstrap's button plugin for a
  # toggle button effect.
  def import_sources_checkboxes(help_block_id)
    Gitlab::ImportSources.options.map do |name, source|
      checked = current_application_settings.import_sources.include?(source)
61
      css_class = checked ? 'active' : ''
62
63
      checkbox_name = 'application_setting[import_sources][]'

64
      label_tag(name, class: css_class) do
65
66
        check_box_tag(checkbox_name, source, checked,
                      autocomplete: 'off',
67
68
                      'aria-describedby' => help_block_id,
                      id: name.tr(' ', '_')) + name
69
70
71
      end
    end
  end
72

73
  def oauth_providers_checkboxes
74
    button_based_providers.map do |source|
75
      disabled = current_application_settings.disabled_oauth_sign_in_sources.include?(source.to_s)
76
      css_class = 'btn'
Andrei Gliga's avatar
Andrei Gliga committed
77
      css_class << ' active' unless disabled
78
      checkbox_name = 'application_setting[enabled_oauth_sign_in_sources][]'
79
80

      label_tag(checkbox_name, class: css_class) do
81
        check_box_tag(checkbox_name, source, !disabled,
82
                      autocomplete: 'off') + Gitlab::OAuth::Provider.label_for(source)
83
84
85
      end
    end
  end
86

87
  def repository_storages_options_for_select
88
89
    options = Gitlab.config.repositories.storages.map do |name, storage|
      ["#{name} - #{storage['path']}", name]
90
91
    end

92
    options_for_select(options, @application_setting.repository_storages)
93
  end
94
95
96
97

  def sidekiq_queue_options_for_select
    options_for_select(Sidekiq::Queue.all.map(&:name), @application_setting.sidekiq_throttling_queues)
  end
98
99
100
101
102
103
104
105

  def visible_attributes
    [
      :admin_notification_email,
      :after_sign_out_path,
      :after_sign_up_text,
      :akismet_api_key,
      :akismet_enabled,
106
      :auto_devops_enabled,
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
      :clientside_sentry_dsn,
      :clientside_sentry_enabled,
      :container_registry_token_expire_delay,
      :default_artifacts_expire_in,
      :default_branch_protection,
      :default_group_visibility,
      :default_project_visibility,
      :default_projects_limit,
      :default_snippet_visibility,
      :disabled_oauth_sign_in_sources,
      :domain_blacklist_enabled,
      :domain_blacklist_raw,
      :domain_whitelist_raw,
      :email_author_in_body,
      :enabled_git_access_protocol,
      :gravatar_enabled,
123
      :hashed_storage_enabled,
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
      :help_page_hide_commercial_content,
      :help_page_support_url,
      :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,
      :import_sources,
      :koding_enabled,
      :koding_url,
      :max_artifacts_size,
      :max_attachment_size,
      :max_pages_size,
      :metrics_enabled,
      :metrics_host,
      :metrics_method_call_threshold,
      :metrics_packet_size,
      :metrics_pool_size,
      :metrics_port,
      :metrics_sample_interval,
      :metrics_timeout,
      :password_authentication_enabled,
      :performance_bar_allowed_group_id,
      :performance_bar_enabled,
      :plantuml_enabled,
      :plantuml_url,
      :polling_interval_multiplier,
154
      :project_export_enabled,
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
      :prometheus_metrics_enabled,
      :recaptcha_enabled,
      :recaptcha_private_key,
      :recaptcha_site_key,
      :repository_checks_enabled,
      :repository_storages,
      :require_two_factor_authentication,
      :restricted_visibility_levels,
      :send_user_confirmation_email,
      :sentry_dsn,
      :sentry_enabled,
      :session_expire_delay,
      :shared_runners_enabled,
      :shared_runners_text,
      :sidekiq_throttling_enabled,
      :sidekiq_throttling_factor,
      :sidekiq_throttling_queues,
      :sign_in_text,
      :signup_enabled,
      :terminal_max_session_time,
      :two_factor_grace_period,
      :unique_ips_limit_enabled,
      :unique_ips_limit_per_user,
      :unique_ips_limit_time_window,
      :usage_ping_enabled,
      :user_default_external,
      :user_oauth_applications,
      :version_check_enabled
    ]
  end
185
end