2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-01-08 03:22:50 -05:00
|
|
|
module ApplicationSettingsHelper
|
2017-07-13 12:03:52 -04:00
|
|
|
extend self
|
2017-08-31 05:47:03 -04:00
|
|
|
|
2017-11-23 08:16:14 -05:00
|
|
|
delegate :allow_signup?,
|
|
|
|
:gravatar_enabled?,
|
|
|
|
:password_authentication_enabled_for_web?,
|
2017-02-22 12:51:46 -05:00
|
|
|
:akismet_enabled?,
|
2018-02-02 13:39:55 -05:00
|
|
|
to: :'Gitlab::CurrentSettings.current_application_settings'
|
2015-01-08 12:53:35 -05:00
|
|
|
|
2015-05-29 07:29:16 -04:00
|
|
|
def user_oauth_applications?
|
2018-02-02 13:39:55 -05:00
|
|
|
Gitlab::CurrentSettings.user_oauth_applications
|
2015-05-29 07:29:16 -04:00
|
|
|
end
|
|
|
|
|
2016-06-15 18:30:55 -04:00
|
|
|
def allowed_protocols_present?
|
2018-02-02 13:39:55 -05:00
|
|
|
Gitlab::CurrentSettings.enabled_git_access_protocol.present?
|
2016-06-15 18:30:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def enabled_protocol
|
2018-02-02 13:39:55 -05:00
|
|
|
case Gitlab::CurrentSettings.enabled_git_access_protocol
|
2016-06-15 18:30:55 -04:00
|
|
|
when 'http'
|
2019-01-03 16:17:44 -05:00
|
|
|
Gitlab.config.gitlab.protocol
|
2016-06-15 18:30:55 -04:00
|
|
|
when 'ssh'
|
|
|
|
'ssh'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-23 23:58:24 -05:00
|
|
|
def all_protocols_enabled?
|
|
|
|
Gitlab::CurrentSettings.enabled_git_access_protocol.blank?
|
|
|
|
end
|
|
|
|
|
|
|
|
def ssh_enabled?
|
|
|
|
all_protocols_enabled? || enabled_protocol == 'ssh'
|
|
|
|
end
|
|
|
|
|
|
|
|
def http_enabled?
|
2019-01-03 16:17:44 -05:00
|
|
|
all_protocols_enabled? || Gitlab::CurrentSettings.enabled_git_access_protocol == 'http'
|
2018-12-23 23:58:24 -05:00
|
|
|
end
|
|
|
|
|
2016-06-29 16:25:04 -04:00
|
|
|
def enabled_project_button(project, protocol)
|
2016-06-15 18:30:55 -04:00
|
|
|
case protocol
|
|
|
|
when 'ssh'
|
2017-11-13 13:21:26 -05:00
|
|
|
ssh_clone_button(project, append_link: false)
|
2016-06-15 18:30:55 -04:00
|
|
|
else
|
2017-11-13 13:21:26 -05:00
|
|
|
http_clone_button(project, append_link: false)
|
2016-06-15 18:30:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-01 10:06:46 -05:00
|
|
|
# Return a group of checkboxes that use Bootstrap's button plugin for a
|
|
|
|
# toggle button effect.
|
2018-06-04 17:55:31 -04:00
|
|
|
def restricted_level_checkboxes(help_block_id, checkbox_name, options = {})
|
2017-07-12 13:38:02 -04:00
|
|
|
Gitlab::VisibilityLevel.values.map do |level|
|
2015-03-01 10:06:46 -05:00
|
|
|
checked = restricted_visibility_levels(true).include?(level)
|
2016-11-14 14:26:37 -05:00
|
|
|
css_class = checked ? 'active' : ''
|
2017-07-05 06:45:58 -04:00
|
|
|
tag_name = "application_setting_visibility_level_#{level}"
|
2015-03-01 10:06:46 -05:00
|
|
|
|
2017-07-05 06:45:58 -04:00
|
|
|
label_tag(tag_name, class: css_class) do
|
2015-03-10 20:21:09 -04:00
|
|
|
check_box_tag(checkbox_name, level, checked,
|
|
|
|
autocomplete: 'off',
|
2016-11-14 14:26:37 -05:00
|
|
|
'aria-describedby' => help_block_id,
|
2018-06-04 17:55:31 -04:00
|
|
|
'class' => options[:class],
|
2017-07-12 13:38:02 -04:00
|
|
|
id: tag_name) + visibility_level_icon(level) + visibility_level_label(level)
|
2015-03-01 10:06:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-08-12 02:13:20 -04:00
|
|
|
|
|
|
|
# Return a group of checkboxes that use Bootstrap's button plugin for a
|
|
|
|
# toggle button effect.
|
2018-06-04 17:55:31 -04:00
|
|
|
def import_sources_checkboxes(help_block_id, options = {})
|
2015-08-12 02:13:20 -04:00
|
|
|
Gitlab::ImportSources.options.map do |name, source|
|
2018-02-02 13:39:55 -05:00
|
|
|
checked = Gitlab::CurrentSettings.import_sources.include?(source)
|
2016-11-19 09:44:06 -05:00
|
|
|
css_class = checked ? 'active' : ''
|
2015-08-12 02:13:20 -04:00
|
|
|
checkbox_name = 'application_setting[import_sources][]'
|
|
|
|
|
2016-11-19 09:44:06 -05:00
|
|
|
label_tag(name, class: css_class) do
|
2015-08-12 02:13:20 -04:00
|
|
|
check_box_tag(checkbox_name, source, checked,
|
|
|
|
autocomplete: 'off',
|
2016-11-19 09:44:06 -05:00
|
|
|
'aria-describedby' => help_block_id,
|
2018-06-04 17:55:31 -04:00
|
|
|
'class' => options[:class],
|
2016-11-19 09:44:06 -05:00
|
|
|
id: name.tr(' ', '_')) + name
|
2015-08-12 02:13:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-05-04 06:33:33 -04:00
|
|
|
|
2016-05-12 06:43:12 -04:00
|
|
|
def oauth_providers_checkboxes
|
2016-05-04 06:33:33 -04:00
|
|
|
button_based_providers.map do |source|
|
2018-02-02 13:39:55 -05:00
|
|
|
disabled = Gitlab::CurrentSettings.disabled_oauth_sign_in_sources.include?(source.to_s)
|
2018-08-18 07:19:57 -04:00
|
|
|
css_class = ['btn']
|
|
|
|
css_class << 'active' unless disabled
|
2016-05-10 04:29:19 -04:00
|
|
|
checkbox_name = 'application_setting[enabled_oauth_sign_in_sources][]'
|
2018-04-13 11:54:08 -04:00
|
|
|
name = Gitlab::Auth::OAuth::Provider.label_for(source)
|
2016-05-04 06:33:33 -04:00
|
|
|
|
2018-08-18 07:19:57 -04:00
|
|
|
label_tag(checkbox_name, class: css_class.join(' ')) do
|
2016-05-10 04:29:19 -04:00
|
|
|
check_box_tag(checkbox_name, source, !disabled,
|
2018-04-13 11:54:08 -04:00
|
|
|
autocomplete: 'off',
|
|
|
|
id: name.tr(' ', '_')) + name
|
2016-05-04 06:33:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-29 23:35:00 -04:00
|
|
|
|
2017-08-25 09:08:48 -04: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 06:30:03 -04:00
|
|
|
end
|
2017-08-25 09:08:48 -04:00
|
|
|
|
|
|
|
[
|
|
|
|
['Are allowed', 0],
|
|
|
|
*bit_size_options,
|
|
|
|
['Are forbidden', ApplicationSetting::FORBIDDEN_KEY_VALUE]
|
|
|
|
]
|
2017-08-21 06:30:03 -04:00
|
|
|
end
|
|
|
|
|
2018-01-31 12:53:09 -05:00
|
|
|
def repository_storages_options_for_select(selected)
|
2017-02-28 16:08:40 -05:00
|
|
|
options = Gitlab.config.repositories.storages.map do |name, storage|
|
2018-03-23 08:01:40 -04:00
|
|
|
["#{name} - #{storage['gitaly_address']}", name]
|
2016-06-29 23:35:00 -04:00
|
|
|
end
|
|
|
|
|
2018-01-31 12:53:09 -05:00
|
|
|
options_for_select(options, selected)
|
2016-06-29 23:35:00 -04:00
|
|
|
end
|
2016-11-04 18:54:24 -04:00
|
|
|
|
2019-04-09 11:38:58 -04:00
|
|
|
def external_authorization_description
|
|
|
|
_("If enabled, access to projects will be validated on an external service"\
|
|
|
|
" using their classification label.")
|
|
|
|
end
|
|
|
|
|
|
|
|
def external_authorization_timeout_help_text
|
|
|
|
_("Time in seconds GitLab will wait for a response from the external "\
|
|
|
|
"service. When the service does not respond in time, access will be "\
|
|
|
|
"denied.")
|
|
|
|
end
|
|
|
|
|
|
|
|
def external_authorization_url_help_text
|
|
|
|
_("When leaving the URL blank, classification labels can still be "\
|
|
|
|
"specified without disabling cross project features or performing "\
|
|
|
|
"external authorization checks.")
|
|
|
|
end
|
|
|
|
|
|
|
|
def external_authorization_client_certificate_help_text
|
|
|
|
_("The X509 Certificate to use when mutual TLS is required to communicate "\
|
|
|
|
"with the external authorization service. If left blank, the server "\
|
|
|
|
"certificate is still validated when accessing over HTTPS.")
|
|
|
|
end
|
|
|
|
|
|
|
|
def external_authorization_client_key_help_text
|
|
|
|
_("The private key to use when a client certificate is provided. This value "\
|
|
|
|
"is encrypted at rest.")
|
|
|
|
end
|
|
|
|
|
|
|
|
def external_authorization_client_pass_help_text
|
|
|
|
_("The passphrase required to decrypt the private key. This is optional "\
|
|
|
|
"and the value is encrypted at rest.")
|
|
|
|
end
|
|
|
|
|
2017-07-13 12:03:52 -04:00
|
|
|
def visible_attributes
|
|
|
|
[
|
|
|
|
:admin_notification_email,
|
|
|
|
:after_sign_out_path,
|
|
|
|
:after_sign_up_text,
|
|
|
|
:akismet_api_key,
|
|
|
|
:akismet_enabled,
|
2018-07-30 06:16:54 -04:00
|
|
|
:allow_local_requests_from_hooks_and_services,
|
2018-10-23 06:58:41 -04:00
|
|
|
:archive_builds_in_human_readable,
|
2017-05-30 19:24:45 -04:00
|
|
|
:authorized_keys_enabled,
|
2017-08-24 07:01:33 -04:00
|
|
|
:auto_devops_enabled,
|
2018-01-22 13:31:03 -05:00
|
|
|
:auto_devops_domain,
|
2017-07-13 12:03:52 -04:00
|
|
|
:clientside_sentry_dsn,
|
|
|
|
:clientside_sentry_enabled,
|
|
|
|
:container_registry_token_expire_delay,
|
|
|
|
:default_artifacts_expire_in,
|
|
|
|
:default_branch_protection,
|
|
|
|
:default_group_visibility,
|
2019-04-05 14:49:46 -04:00
|
|
|
:default_project_creation,
|
2017-07-13 12:03:52 -04:00
|
|
|
: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 09:08:48 -04:00
|
|
|
:dsa_key_restriction,
|
|
|
|
:ecdsa_key_restriction,
|
|
|
|
:ed25519_key_restriction,
|
2017-07-13 12:03:52 -04:00
|
|
|
:email_author_in_body,
|
|
|
|
:enabled_git_access_protocol,
|
2018-07-30 06:16:54 -04:00
|
|
|
:enforce_terms,
|
2019-01-10 16:06:42 -05:00
|
|
|
:first_day_of_week,
|
2017-11-29 04:12:12 -05:00
|
|
|
:gitaly_timeout_default,
|
|
|
|
:gitaly_timeout_medium,
|
|
|
|
:gitaly_timeout_fast,
|
2017-07-13 12:03:52 -04:00
|
|
|
:gravatar_enabled,
|
2017-08-07 04:53:30 -04:00
|
|
|
:hashed_storage_enabled,
|
2017-07-13 12:03:52 -04:00
|
|
|
:help_page_hide_commercial_content,
|
|
|
|
:help_page_support_url,
|
|
|
|
:help_page_text,
|
2018-07-30 06:16:54 -04:00
|
|
|
:hide_third_party_offers,
|
2017-07-13 12:03:52 -04:00
|
|
|
:home_page_url,
|
|
|
|
:housekeeping_bitmaps_enabled,
|
|
|
|
:housekeeping_enabled,
|
|
|
|
:housekeeping_full_repack_period,
|
|
|
|
:housekeeping_gc_period,
|
|
|
|
:housekeeping_incremental_repack_period,
|
|
|
|
:html_emails_enabled,
|
|
|
|
:import_sources,
|
|
|
|
: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,
|
2018-07-30 06:16:54 -04:00
|
|
|
:mirror_available,
|
2018-02-06 08:25:46 -05:00
|
|
|
:pages_domain_verification_enabled,
|
2017-11-23 08:16:14 -05:00
|
|
|
:password_authentication_enabled_for_web,
|
2018-01-19 07:04:45 -05:00
|
|
|
:password_authentication_enabled_for_git,
|
2018-05-25 12:44:15 -04:00
|
|
|
:performance_bar_allowed_group_path,
|
2017-07-13 12:03:52 -04:00
|
|
|
:performance_bar_enabled,
|
|
|
|
:plantuml_enabled,
|
|
|
|
:plantuml_url,
|
|
|
|
:polling_interval_multiplier,
|
2017-07-31 17:34:47 -04:00
|
|
|
:project_export_enabled,
|
2017-07-13 12:03:52 -04:00
|
|
|
:prometheus_metrics_enabled,
|
|
|
|
:recaptcha_enabled,
|
|
|
|
:recaptcha_private_key,
|
|
|
|
:recaptcha_site_key,
|
2018-08-01 10:47:14 -04:00
|
|
|
:receive_max_input_size,
|
2017-07-13 12:03:52 -04:00
|
|
|
:repository_checks_enabled,
|
|
|
|
:repository_storages,
|
|
|
|
:require_two_factor_authentication,
|
|
|
|
:restricted_visibility_levels,
|
2017-08-25 09:08:48 -04:00
|
|
|
:rsa_key_restriction,
|
2017-07-13 12:03:52 -04:00
|
|
|
:send_user_confirmation_email,
|
|
|
|
:sentry_dsn,
|
|
|
|
:sentry_enabled,
|
|
|
|
:session_expire_delay,
|
|
|
|
:shared_runners_enabled,
|
|
|
|
:shared_runners_text,
|
|
|
|
:sign_in_text,
|
|
|
|
:signup_enabled,
|
|
|
|
:terminal_max_session_time,
|
2018-07-30 06:16:54 -04:00
|
|
|
:terms,
|
2017-09-15 13:31:32 -04:00
|
|
|
:throttle_authenticated_api_enabled,
|
|
|
|
:throttle_authenticated_api_period_in_seconds,
|
2018-07-31 12:21:12 -04:00
|
|
|
:throttle_authenticated_api_requests_per_period,
|
|
|
|
:throttle_authenticated_web_enabled,
|
|
|
|
:throttle_authenticated_web_period_in_seconds,
|
|
|
|
:throttle_authenticated_web_requests_per_period,
|
|
|
|
:throttle_unauthenticated_enabled,
|
|
|
|
:throttle_unauthenticated_period_in_seconds,
|
|
|
|
:throttle_unauthenticated_requests_per_period,
|
2017-07-13 12:03:52 -04:00
|
|
|
:two_factor_grace_period,
|
|
|
|
:unique_ips_limit_enabled,
|
|
|
|
:unique_ips_limit_per_user,
|
|
|
|
:unique_ips_limit_time_window,
|
|
|
|
:usage_ping_enabled,
|
2018-07-17 21:41:40 -04:00
|
|
|
:instance_statistics_visibility_private,
|
2017-07-13 12:03:52 -04:00
|
|
|
:user_default_external,
|
2018-08-03 16:52:01 -04:00
|
|
|
:user_show_add_ssh_key_message,
|
2018-08-30 08:53:06 -04:00
|
|
|
:user_default_internal_regex,
|
2017-07-13 12:03:52 -04:00
|
|
|
:user_oauth_applications,
|
2018-06-13 12:06:35 -04:00
|
|
|
:version_check_enabled,
|
2018-09-24 11:30:49 -04:00
|
|
|
:web_ide_clientside_preview_enabled,
|
2018-11-07 06:00:21 -05:00
|
|
|
:diff_max_patch_bytes,
|
2018-10-31 15:12:22 -04:00
|
|
|
:commit_email_hostname,
|
2019-01-31 06:28:31 -05:00
|
|
|
:protected_ci_variables,
|
|
|
|
:local_markdown_version
|
2017-07-13 12:03:52 -04:00
|
|
|
]
|
|
|
|
end
|
2018-09-19 06:57:57 -04:00
|
|
|
|
2019-04-09 11:38:58 -04:00
|
|
|
def external_authorization_service_attributes
|
|
|
|
[
|
|
|
|
:external_auth_client_cert,
|
|
|
|
:external_auth_client_key,
|
|
|
|
:external_auth_client_key_pass,
|
|
|
|
:external_authorization_service_default_label,
|
|
|
|
:external_authorization_service_enabled,
|
|
|
|
:external_authorization_service_timeout,
|
|
|
|
:external_authorization_service_url
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2018-09-19 06:57:57 -04:00
|
|
|
def expanded_by_default?
|
|
|
|
Rails.env.test?
|
|
|
|
end
|
2015-01-08 03:22:50 -05:00
|
|
|
end
|