2015-01-08 08:22:50 +00:00
|
|
|
module ApplicationSettingsHelper
|
2017-07-13 16:03:52 +00:00
|
|
|
extend self
|
2017-08-31 09:47:03 +00:00
|
|
|
|
|
|
|
include Gitlab::CurrentSettings
|
|
|
|
|
2017-02-22 17:51:46 +00:00
|
|
|
delegate :gravatar_enabled?,
|
|
|
|
:signup_enabled?,
|
2017-06-27 18:02:09 +00:00
|
|
|
:password_authentication_enabled?,
|
2017-02-22 17:51:46 +00:00
|
|
|
:akismet_enabled?,
|
|
|
|
:koding_enabled?,
|
|
|
|
to: :current_application_settings
|
2015-01-08 17:53:35 +00:00
|
|
|
|
2015-05-29 11:29:16 +00:00
|
|
|
def user_oauth_applications?
|
|
|
|
current_application_settings.user_oauth_applications
|
|
|
|
end
|
|
|
|
|
2016-06-15 22:30:55 +00:00
|
|
|
def allowed_protocols_present?
|
2016-06-29 19:30:27 +00:00
|
|
|
current_application_settings.enabled_git_access_protocol.present?
|
2016-06-15 22:30:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def enabled_protocol
|
2016-06-29 19:30:27 +00:00
|
|
|
case current_application_settings.enabled_git_access_protocol
|
2016-06-15 22:30:55 +00:00
|
|
|
when 'http'
|
|
|
|
gitlab_config.protocol
|
|
|
|
when 'ssh'
|
|
|
|
'ssh'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-29 20:25:04 +00:00
|
|
|
def enabled_project_button(project, protocol)
|
2016-06-15 22:30:55 +00:00
|
|
|
case protocol
|
|
|
|
when 'ssh'
|
2016-07-05 21:48:48 +00:00
|
|
|
ssh_clone_button(project, 'bottom', append_link: false)
|
2016-06-15 22:30:55 +00:00
|
|
|
else
|
2016-07-05 21:48:48 +00:00
|
|
|
http_clone_button(project, 'bottom', append_link: false)
|
2016-06-15 22:30:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-01 15:06:46 +00:00
|
|
|
# Return a group of checkboxes that use Bootstrap's button plugin for a
|
|
|
|
# toggle button effect.
|
2017-07-05 10:45:58 +00:00
|
|
|
def restricted_level_checkboxes(help_block_id, checkbox_name)
|
2017-07-12 17:38:02 +00:00
|
|
|
Gitlab::VisibilityLevel.values.map do |level|
|
2015-03-01 15:06:46 +00:00
|
|
|
checked = restricted_visibility_levels(true).include?(level)
|
2016-11-14 19:26:37 +00:00
|
|
|
css_class = checked ? 'active' : ''
|
2017-07-05 10:45:58 +00:00
|
|
|
tag_name = "application_setting_visibility_level_#{level}"
|
2015-03-01 15:06:46 +00:00
|
|
|
|
2017-07-05 10:45:58 +00:00
|
|
|
label_tag(tag_name, class: css_class) do
|
2015-03-11 00:21:09 +00:00
|
|
|
check_box_tag(checkbox_name, level, checked,
|
|
|
|
autocomplete: 'off',
|
2016-11-14 19:26:37 +00:00
|
|
|
'aria-describedby' => help_block_id,
|
2017-07-12 17:38:02 +00:00
|
|
|
id: tag_name) + visibility_level_icon(level) + visibility_level_label(level)
|
2015-03-01 15:06:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-08-12 06:13:20 +00:00
|
|
|
|
|
|
|
# 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)
|
2016-11-19 14:44:06 +00:00
|
|
|
css_class = checked ? 'active' : ''
|
2015-08-12 06:13:20 +00:00
|
|
|
checkbox_name = 'application_setting[import_sources][]'
|
|
|
|
|
2016-11-19 14:44:06 +00:00
|
|
|
label_tag(name, class: css_class) do
|
2015-08-12 06:13:20 +00:00
|
|
|
check_box_tag(checkbox_name, source, checked,
|
|
|
|
autocomplete: 'off',
|
2016-11-19 14:44:06 +00:00
|
|
|
'aria-describedby' => help_block_id,
|
|
|
|
id: name.tr(' ', '_')) + name
|
2015-08-12 06:13:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-05-04 10:33:33 +00:00
|
|
|
|
2016-05-12 10:43:12 +00:00
|
|
|
def oauth_providers_checkboxes
|
2016-05-04 10:33:33 +00:00
|
|
|
button_based_providers.map do |source|
|
2016-05-10 08:29:19 +00:00
|
|
|
disabled = current_application_settings.disabled_oauth_sign_in_sources.include?(source.to_s)
|
2016-05-04 10:33:33 +00:00
|
|
|
css_class = 'btn'
|
2016-05-10 15:50:03 +00:00
|
|
|
css_class << ' active' unless disabled
|
2016-05-10 08:29:19 +00:00
|
|
|
checkbox_name = 'application_setting[enabled_oauth_sign_in_sources][]'
|
2016-05-04 10:33:33 +00:00
|
|
|
|
|
|
|
label_tag(checkbox_name, class: css_class) do
|
2016-05-10 08:29:19 +00:00
|
|
|
check_box_tag(checkbox_name, source, !disabled,
|
2016-05-12 10:43:12 +00:00
|
|
|
autocomplete: 'off') + Gitlab::OAuth::Provider.label_for(source)
|
2016-05-04 10:33:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-30 03:35:00 +00:00
|
|
|
|
2017-08-25 13:08:48 +00:00
|
|
|
def key_restriction_options_for_select(type)
|
|
|
|
bit_size_options = Gitlab::SSHPublicKey.supported_sizes(type).map do |bits|
|
|
|
|
["Must be at least #{bits} bits", bits]
|
2017-08-21 10:30:03 +00:00
|
|
|
end
|
2017-08-25 13:08:48 +00:00
|
|
|
|
|
|
|
[
|
|
|
|
['Are allowed', 0],
|
|
|
|
*bit_size_options,
|
|
|
|
['Are forbidden', ApplicationSetting::FORBIDDEN_KEY_VALUE]
|
|
|
|
]
|
2017-08-21 10:30:03 +00:00
|
|
|
end
|
|
|
|
|
2016-11-03 14:12:20 +00:00
|
|
|
def repository_storages_options_for_select
|
2017-02-28 21:08:40 +00:00
|
|
|
options = Gitlab.config.repositories.storages.map do |name, storage|
|
|
|
|
["#{name} - #{storage['path']}", name]
|
2016-06-30 03:35:00 +00:00
|
|
|
end
|
|
|
|
|
2016-11-03 14:12:20 +00:00
|
|
|
options_for_select(options, @application_setting.repository_storages)
|
2016-06-30 03:35:00 +00:00
|
|
|
end
|
2016-11-04 22:54:24 +00:00
|
|
|
|
|
|
|
def sidekiq_queue_options_for_select
|
|
|
|
options_for_select(Sidekiq::Queue.all.map(&:name), @application_setting.sidekiq_throttling_queues)
|
|
|
|
end
|
2017-07-13 16:03:52 +00:00
|
|
|
|
2017-10-12 14:35:59 +00:00
|
|
|
def circuitbreaker_failure_count_help_text
|
|
|
|
health_link = link_to(s_('AdminHealthPageLink|health page'), admin_health_check_path)
|
|
|
|
api_link = link_to(s_('CircuitBreakerApiLink|circuitbreaker api'), help_page_path("api/repository_storage_health"))
|
|
|
|
message = _("The number of failures of after which GitLab will completely "\
|
|
|
|
"prevent access to the storage. The number of failures can be "\
|
|
|
|
"reset in the admin interface: %{link_to_health_page} or using "\
|
|
|
|
"the %{api_documentation_link}.")
|
|
|
|
message = message % { link_to_health_page: health_link, api_documentation_link: api_link }
|
|
|
|
|
|
|
|
message.html_safe
|
|
|
|
end
|
|
|
|
|
|
|
|
def circuitbreaker_failure_wait_time_help_text
|
|
|
|
_("When access to a storage fails. GitLab will prevent access to the "\
|
|
|
|
"storage for the time specified here. This allows the filesystem to "\
|
|
|
|
"recover. Repositories on failing shards are temporarly unavailable")
|
|
|
|
end
|
|
|
|
|
|
|
|
def circuitbreaker_failure_reset_time_help_text
|
|
|
|
_("The time in seconds GitLab will keep failure information. When no "\
|
|
|
|
"failures occur during this time, information about the mount is reset.")
|
|
|
|
end
|
|
|
|
|
|
|
|
def circuitbreaker_storage_timeout_help_text
|
|
|
|
_("The time in seconds GitLab will try to access storage. After this time a "\
|
|
|
|
"timeout error will be raised.")
|
|
|
|
end
|
|
|
|
|
2017-07-13 16:03:52 +00:00
|
|
|
def visible_attributes
|
|
|
|
[
|
|
|
|
:admin_notification_email,
|
|
|
|
:after_sign_out_path,
|
|
|
|
:after_sign_up_text,
|
|
|
|
:akismet_api_key,
|
|
|
|
:akismet_enabled,
|
2017-08-24 11:01:33 +00:00
|
|
|
:auto_devops_enabled,
|
2017-10-12 14:35:59 +00:00
|
|
|
:circuitbreaker_failure_count_threshold,
|
|
|
|
:circuitbreaker_failure_reset_time,
|
|
|
|
:circuitbreaker_failure_wait_time,
|
|
|
|
:circuitbreaker_storage_timeout,
|
2017-07-13 16:03:52 +00:00
|
|
|
: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,
|
2017-08-25 13:08:48 +00:00
|
|
|
:dsa_key_restriction,
|
|
|
|
:ecdsa_key_restriction,
|
|
|
|
:ed25519_key_restriction,
|
2017-07-13 16:03:52 +00:00
|
|
|
:email_author_in_body,
|
|
|
|
:enabled_git_access_protocol,
|
|
|
|
:gravatar_enabled,
|
2017-08-07 08:53:30 +00:00
|
|
|
:hashed_storage_enabled,
|
2017-07-13 16:03:52 +00:00
|
|
|
: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,
|
2017-07-31 21:34:47 +00:00
|
|
|
:project_export_enabled,
|
2017-07-13 16:03:52 +00:00
|
|
|
:prometheus_metrics_enabled,
|
|
|
|
:recaptcha_enabled,
|
|
|
|
:recaptcha_private_key,
|
|
|
|
:recaptcha_site_key,
|
|
|
|
:repository_checks_enabled,
|
|
|
|
:repository_storages,
|
|
|
|
:require_two_factor_authentication,
|
|
|
|
:restricted_visibility_levels,
|
2017-08-25 13:08:48 +00:00
|
|
|
:rsa_key_restriction,
|
2017-07-13 16:03:52 +00:00
|
|
|
: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
|
2015-01-08 08:22:50 +00:00
|
|
|
end
|