2018-07-25 09:30:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-01-08 08:22:50 +00:00
|
|
|
class ApplicationSetting < ActiveRecord::Base
|
2018-05-04 17:23:50 +00:00
|
|
|
include CacheableAttributes
|
2016-10-06 21:17:11 +00:00
|
|
|
include CacheMarkdownField
|
2015-12-10 09:48:37 +00:00
|
|
|
include TokenAuthenticatable
|
2018-10-09 05:59:42 +00:00
|
|
|
include IgnorableColumn
|
2016-10-06 21:17:11 +00:00
|
|
|
|
2015-12-10 09:48:37 +00:00
|
|
|
add_authentication_token_field :runners_registration_token
|
2016-05-09 23:21:22 +00:00
|
|
|
add_authentication_token_field :health_check_access_token
|
2015-12-10 09:48:37 +00:00
|
|
|
|
2016-07-15 18:20:45 +00:00
|
|
|
DOMAIN_LIST_SEPARATOR = %r{\s*[,;]\s* # comma or semicolon, optionally surrounded by whitespace
|
|
|
|
| # or
|
|
|
|
\s # any whitespace character
|
|
|
|
| # or
|
|
|
|
[\r\n] # any number of newline characters
|
|
|
|
}x
|
2015-12-03 08:09:10 +00:00
|
|
|
|
2017-08-25 13:08:48 +00:00
|
|
|
# Setting a key restriction to `-1` means that all keys of this type are
|
|
|
|
# forbidden.
|
2017-08-28 20:58:36 +00:00
|
|
|
FORBIDDEN_KEY_VALUE = KeyRestrictionValidator::FORBIDDEN
|
2017-08-25 13:08:48 +00:00
|
|
|
SUPPORTED_KEY_TYPES = %i[rsa dsa ecdsa ed25519].freeze
|
|
|
|
|
2017-07-03 14:01:41 +00:00
|
|
|
serialize :restricted_visibility_levels # rubocop:disable Cop/ActiveRecordSerialize
|
|
|
|
serialize :import_sources # rubocop:disable Cop/ActiveRecordSerialize
|
|
|
|
serialize :disabled_oauth_sign_in_sources, Array # rubocop:disable Cop/ActiveRecordSerialize
|
|
|
|
serialize :domain_whitelist, Array # rubocop:disable Cop/ActiveRecordSerialize
|
|
|
|
serialize :domain_blacklist, Array # rubocop:disable Cop/ActiveRecordSerialize
|
|
|
|
serialize :repository_storages # rubocop:disable Cop/ActiveRecordSerialize
|
2016-07-14 18:19:40 +00:00
|
|
|
|
2018-10-09 05:59:42 +00:00
|
|
|
ignore_column :circuitbreaker_failure_count_threshold
|
|
|
|
ignore_column :circuitbreaker_failure_reset_time
|
|
|
|
ignore_column :circuitbreaker_storage_timeout
|
|
|
|
ignore_column :circuitbreaker_access_retries
|
|
|
|
ignore_column :circuitbreaker_check_interval
|
2018-10-13 00:54:08 +00:00
|
|
|
ignore_column :koding_url
|
|
|
|
ignore_column :koding_enabled
|
2018-10-09 05:59:42 +00:00
|
|
|
|
2016-10-06 21:17:11 +00:00
|
|
|
cache_markdown_field :sign_in_text
|
|
|
|
cache_markdown_field :help_page_text
|
|
|
|
cache_markdown_field :shared_runners_text, pipeline: :plain_markdown
|
|
|
|
cache_markdown_field :after_sign_up_text
|
|
|
|
|
2016-07-15 23:30:38 +00:00
|
|
|
attr_accessor :domain_whitelist_raw, :domain_blacklist_raw
|
2015-06-13 04:22:55 +00:00
|
|
|
|
2017-10-05 19:56:23 +00:00
|
|
|
default_value_for :id, 1
|
|
|
|
|
2017-04-24 19:12:05 +00:00
|
|
|
validates :uuid, presence: true
|
|
|
|
|
2015-06-13 04:22:55 +00:00
|
|
|
validates :session_expire_delay,
|
2015-12-28 20:21:34 +00:00
|
|
|
presence: true,
|
|
|
|
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
2015-03-01 15:06:46 +00:00
|
|
|
|
2015-02-03 05:15:44 +00:00
|
|
|
validates :home_page_url,
|
2015-12-28 20:21:34 +00:00
|
|
|
allow_blank: true,
|
|
|
|
url: true,
|
2017-06-13 16:46:02 +00:00
|
|
|
if: :home_page_url_column_exists?
|
|
|
|
|
|
|
|
validates :help_page_support_url,
|
|
|
|
allow_blank: true,
|
|
|
|
url: true,
|
|
|
|
if: :help_page_support_url_column_exists?
|
2015-01-17 00:01:15 +00:00
|
|
|
|
2015-05-29 15:42:27 +00:00
|
|
|
validates :after_sign_out_path,
|
2015-12-28 20:21:34 +00:00
|
|
|
allow_blank: true,
|
|
|
|
url: true
|
2015-05-29 15:42:27 +00:00
|
|
|
|
2015-10-18 09:58:59 +00:00
|
|
|
validates :admin_notification_email,
|
2016-02-09 16:59:47 +00:00
|
|
|
email: true,
|
2016-02-09 14:51:06 +00:00
|
|
|
allow_blank: true
|
2015-10-18 09:58:59 +00:00
|
|
|
|
2015-12-18 20:29:13 +00:00
|
|
|
validates :two_factor_grace_period,
|
2015-12-28 20:21:34 +00:00
|
|
|
numericality: { greater_than_or_equal_to: 0 }
|
|
|
|
|
|
|
|
validates :recaptcha_site_key,
|
|
|
|
presence: true,
|
|
|
|
if: :recaptcha_enabled
|
|
|
|
|
|
|
|
validates :recaptcha_private_key,
|
|
|
|
presence: true,
|
|
|
|
if: :recaptcha_enabled
|
2015-12-18 20:29:13 +00:00
|
|
|
|
2016-01-18 16:15:10 +00:00
|
|
|
validates :sentry_dsn,
|
|
|
|
presence: true,
|
|
|
|
if: :sentry_enabled
|
|
|
|
|
2017-04-28 12:23:34 +00:00
|
|
|
validates :clientside_sentry_dsn,
|
|
|
|
presence: true,
|
|
|
|
if: :clientside_sentry_enabled
|
|
|
|
|
2016-01-09 19:30:34 +00:00
|
|
|
validates :akismet_api_key,
|
|
|
|
presence: true,
|
|
|
|
if: :akismet_enabled
|
|
|
|
|
2017-02-17 13:04:10 +00:00
|
|
|
validates :unique_ips_limit_per_user,
|
|
|
|
numericality: { greater_than_or_equal_to: 1 },
|
|
|
|
presence: true,
|
|
|
|
if: :unique_ips_limit_enabled
|
|
|
|
|
|
|
|
validates :unique_ips_limit_time_window,
|
|
|
|
numericality: { greater_than_or_equal_to: 0 },
|
|
|
|
presence: true,
|
|
|
|
if: :unique_ips_limit_enabled
|
|
|
|
|
2016-11-28 17:41:29 +00:00
|
|
|
validates :plantuml_url,
|
|
|
|
presence: true,
|
|
|
|
if: :plantuml_enabled
|
|
|
|
|
2016-02-05 09:12:36 +00:00
|
|
|
validates :max_attachment_size,
|
|
|
|
presence: true,
|
|
|
|
numericality: { only_integer: true, greater_than: 0 }
|
|
|
|
|
2017-02-14 10:00:37 +00:00
|
|
|
validates :max_artifacts_size,
|
|
|
|
presence: true,
|
|
|
|
numericality: { only_integer: true, greater_than: 0 }
|
|
|
|
|
2017-02-24 09:28:24 +00:00
|
|
|
validates :default_artifacts_expire_in, presence: true, duration: true
|
2017-02-14 10:00:37 +00:00
|
|
|
|
2016-05-30 15:12:50 +00:00
|
|
|
validates :container_registry_token_expire_delay,
|
|
|
|
presence: true,
|
|
|
|
numericality: { only_integer: true, greater_than: 0 }
|
|
|
|
|
2016-11-03 14:12:20 +00:00
|
|
|
validates :repository_storages, presence: true
|
|
|
|
validate :check_repository_storages
|
2016-06-30 03:35:00 +00:00
|
|
|
|
2018-01-22 18:29:15 +00:00
|
|
|
validates :auto_devops_domain,
|
|
|
|
allow_blank: true,
|
|
|
|
hostname: { allow_numeric_hostname: true, require_valid_tld: true },
|
|
|
|
if: :auto_devops_enabled?
|
|
|
|
|
2016-06-29 19:30:27 +00:00
|
|
|
validates :enabled_git_access_protocol,
|
2016-06-21 01:40:56 +00:00
|
|
|
inclusion: { in: %w(ssh http), allow_blank: true, allow_nil: true }
|
2016-06-15 22:30:55 +00:00
|
|
|
|
2016-07-14 18:19:40 +00:00
|
|
|
validates :domain_blacklist,
|
2016-07-18 22:49:33 +00:00
|
|
|
presence: { message: 'Domain blacklist cannot be empty if Blacklist is enabled.' },
|
2016-07-14 18:19:40 +00:00
|
|
|
if: :domain_blacklist_enabled?
|
|
|
|
|
2016-10-27 12:59:52 +00:00
|
|
|
validates :housekeeping_incremental_repack_period,
|
|
|
|
presence: true,
|
|
|
|
numericality: { only_integer: true, greater_than: 0 }
|
|
|
|
|
|
|
|
validates :housekeeping_full_repack_period,
|
|
|
|
presence: true,
|
2017-08-21 09:51:45 +00:00
|
|
|
numericality: { only_integer: true, greater_than_or_equal_to: :housekeeping_incremental_repack_period }
|
2016-10-27 12:59:52 +00:00
|
|
|
|
|
|
|
validates :housekeeping_gc_period,
|
|
|
|
presence: true,
|
2017-08-21 09:51:45 +00:00
|
|
|
numericality: { only_integer: true, greater_than_or_equal_to: :housekeeping_full_repack_period }
|
2016-10-27 12:59:52 +00:00
|
|
|
|
2017-01-26 18:16:50 +00:00
|
|
|
validates :terminal_max_session_time,
|
|
|
|
presence: true,
|
|
|
|
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
|
|
|
|
2017-04-03 13:17:04 +00:00
|
|
|
validates :polling_interval_multiplier,
|
|
|
|
presence: true,
|
|
|
|
numericality: { greater_than_or_equal_to: 0 }
|
|
|
|
|
2017-11-29 09:12:12 +00:00
|
|
|
validates :gitaly_timeout_default,
|
|
|
|
presence: true,
|
|
|
|
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
|
|
|
|
|
|
|
validates :gitaly_timeout_medium,
|
|
|
|
presence: true,
|
|
|
|
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
|
|
|
validates :gitaly_timeout_medium,
|
|
|
|
numericality: { less_than_or_equal_to: :gitaly_timeout_default },
|
|
|
|
if: :gitaly_timeout_default
|
|
|
|
validates :gitaly_timeout_medium,
|
|
|
|
numericality: { greater_than_or_equal_to: :gitaly_timeout_fast },
|
|
|
|
if: :gitaly_timeout_fast
|
|
|
|
|
|
|
|
validates :gitaly_timeout_fast,
|
|
|
|
presence: true,
|
|
|
|
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
|
|
|
validates :gitaly_timeout_fast,
|
|
|
|
numericality: { less_than_or_equal_to: :gitaly_timeout_default },
|
|
|
|
if: :gitaly_timeout_default
|
|
|
|
|
2018-09-24 15:30:49 +00:00
|
|
|
validates :diff_max_patch_bytes,
|
|
|
|
presence: true,
|
|
|
|
numericality: { only_integer: true,
|
|
|
|
greater_than_or_equal_to: Gitlab::Git::Diff::DEFAULT_MAX_PATCH_BYTES,
|
|
|
|
less_than_or_equal_to: Gitlab::Git::Diff::MAX_PATCH_BYTES_UPPER_BOUND }
|
|
|
|
|
2018-08-30 12:53:06 +00:00
|
|
|
validates :user_default_internal_regex, js_regex: true, allow_nil: true
|
|
|
|
|
2017-08-25 13:08:48 +00:00
|
|
|
SUPPORTED_KEY_TYPES.each do |type|
|
2017-08-28 20:58:36 +00:00
|
|
|
validates :"#{type}_key_restriction", presence: true, key_restriction: { type: type }
|
2017-08-25 13:08:48 +00:00
|
|
|
end
|
2017-08-21 10:30:03 +00:00
|
|
|
|
2017-08-30 20:20:00 +00:00
|
|
|
validates :allowed_key_types, presence: true
|
|
|
|
|
2015-03-01 15:06:46 +00:00
|
|
|
validates_each :restricted_visibility_levels do |record, attr, value|
|
2017-02-07 14:16:46 +00:00
|
|
|
value&.each do |level|
|
2017-06-02 17:11:26 +00:00
|
|
|
unless Gitlab::VisibilityLevel.options.value?(level)
|
2017-02-07 14:16:46 +00:00
|
|
|
record.errors.add(attr, "'#{level}' is not a valid visibility level")
|
2015-03-01 15:06:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-12 06:13:20 +00:00
|
|
|
validates_each :import_sources do |record, attr, value|
|
2017-02-07 14:16:46 +00:00
|
|
|
value&.each do |source|
|
2017-06-02 17:11:26 +00:00
|
|
|
unless Gitlab::ImportSources.options.value?(source)
|
2017-02-07 14:16:46 +00:00
|
|
|
record.errors.add(attr, "'#{source}' is not a import source")
|
2015-08-12 06:13:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-24 16:28:04 +00:00
|
|
|
validate :terms_exist, if: :enforce_terms?
|
|
|
|
|
2017-04-24 19:12:05 +00:00
|
|
|
before_validation :ensure_uuid!
|
2018-09-12 12:55:29 +00:00
|
|
|
before_validation :strip_sentry_values
|
2017-08-21 10:30:03 +00:00
|
|
|
|
2015-12-10 12:05:59 +00:00
|
|
|
before_save :ensure_runners_registration_token
|
2016-05-09 23:21:22 +00:00
|
|
|
before_save :ensure_health_check_access_token
|
2015-12-10 12:05:59 +00:00
|
|
|
|
2015-11-12 09:19:03 +00:00
|
|
|
after_commit do
|
2018-04-24 16:28:04 +00:00
|
|
|
reset_memoized_terms
|
2017-03-18 09:29:25 +00:00
|
|
|
end
|
2018-05-25 16:44:15 +00:00
|
|
|
after_commit :expire_performance_bar_allowed_user_ids_cache, if: -> { previous_changes.key?('performance_bar_allowed_group_id') }
|
2017-03-18 09:29:25 +00:00
|
|
|
|
2017-06-01 14:27:35 +00:00
|
|
|
def self.defaults
|
2017-01-26 11:46:02 +00:00
|
|
|
{
|
|
|
|
after_sign_up_text: nil,
|
|
|
|
akismet_enabled: false,
|
2018-07-31 16:21:12 +00:00
|
|
|
allow_local_requests_from_hooks_and_services: false,
|
2017-05-30 23:24:45 +00:00
|
|
|
authorized_keys_enabled: true, # TODO default to false if the instance is configured to use AuthorizedKeysCommand
|
2017-01-26 11:46:02 +00:00
|
|
|
container_registry_token_expire_delay: 5,
|
2017-02-14 14:54:46 +00:00
|
|
|
default_artifacts_expire_in: '30 days',
|
2017-01-26 11:46:02 +00:00
|
|
|
default_branch_protection: Settings.gitlab['default_branch_protection'],
|
2018-07-30 10:16:54 +00:00
|
|
|
default_group_visibility: Settings.gitlab.default_projects_features['visibility_level'],
|
2017-01-26 11:46:02 +00:00
|
|
|
default_project_visibility: Settings.gitlab.default_projects_features['visibility_level'],
|
|
|
|
default_projects_limit: Settings.gitlab['default_projects_limit'],
|
|
|
|
default_snippet_visibility: Settings.gitlab.default_projects_features['visibility_level'],
|
|
|
|
disabled_oauth_sign_in_sources: [],
|
|
|
|
domain_whitelist: Settings.gitlab['domain_whitelist'],
|
2017-08-25 13:08:48 +00:00
|
|
|
dsa_key_restriction: 0,
|
|
|
|
ecdsa_key_restriction: 0,
|
|
|
|
ed25519_key_restriction: 0,
|
2018-07-30 10:16:54 +00:00
|
|
|
gitaly_timeout_default: 55,
|
|
|
|
gitaly_timeout_fast: 10,
|
|
|
|
gitaly_timeout_medium: 30,
|
2017-01-26 11:46:02 +00:00
|
|
|
gravatar_enabled: Settings.gravatar['enabled'],
|
2017-06-13 16:46:02 +00:00
|
|
|
help_page_hide_commercial_content: false,
|
2018-07-30 10:16:54 +00:00
|
|
|
help_page_text: nil,
|
|
|
|
hide_third_party_offers: false,
|
2017-01-26 11:46:02 +00:00
|
|
|
housekeeping_bitmaps_enabled: true,
|
|
|
|
housekeeping_enabled: true,
|
|
|
|
housekeeping_full_repack_period: 50,
|
|
|
|
housekeeping_gc_period: 200,
|
|
|
|
housekeeping_incremental_repack_period: 10,
|
2017-09-08 10:15:18 +00:00
|
|
|
import_sources: Settings.gitlab['import_sources'],
|
2017-01-26 11:46:02 +00:00
|
|
|
max_artifacts_size: Settings.artifacts['max_size'],
|
|
|
|
max_attachment_size: Settings.gitlab['max_attachment_size'],
|
2018-07-30 10:16:54 +00:00
|
|
|
mirror_available: true,
|
2017-11-23 13:16:14 +00:00
|
|
|
password_authentication_enabled_for_git: true,
|
2018-07-30 10:16:54 +00:00
|
|
|
password_authentication_enabled_for_web: Settings.gitlab['signin_enabled'],
|
2017-07-06 16:57:02 +00:00
|
|
|
performance_bar_allowed_group_id: nil,
|
2017-08-25 13:08:48 +00:00
|
|
|
rsa_key_restriction: 0,
|
2017-01-26 11:46:02 +00:00
|
|
|
plantuml_enabled: false,
|
|
|
|
plantuml_url: nil,
|
2018-07-30 10:16:54 +00:00
|
|
|
polling_interval_multiplier: 1,
|
2017-07-31 21:34:47 +00:00
|
|
|
project_export_enabled: true,
|
2017-01-26 11:46:02 +00:00
|
|
|
recaptcha_enabled: false,
|
|
|
|
repository_checks_enabled: true,
|
|
|
|
repository_storages: ['default'],
|
|
|
|
require_two_factor_authentication: false,
|
|
|
|
restricted_visibility_levels: Settings.gitlab['restricted_visibility_levels'],
|
|
|
|
session_expire_delay: Settings.gitlab['session_expire_delay'],
|
|
|
|
send_user_confirmation_email: false,
|
|
|
|
shared_runners_enabled: Settings.gitlab_ci['shared_runners_enabled'],
|
|
|
|
shared_runners_text: nil,
|
|
|
|
sign_in_text: nil,
|
|
|
|
signup_enabled: Settings.gitlab['signup_enabled'],
|
2017-02-14 10:00:37 +00:00
|
|
|
terminal_max_session_time: 0,
|
2017-10-06 23:33:49 +00:00
|
|
|
throttle_authenticated_api_enabled: false,
|
|
|
|
throttle_authenticated_api_period_in_seconds: 3600,
|
2018-07-30 10:16:54 +00:00
|
|
|
throttle_authenticated_api_requests_per_period: 7200,
|
|
|
|
throttle_authenticated_web_enabled: false,
|
|
|
|
throttle_authenticated_web_period_in_seconds: 3600,
|
|
|
|
throttle_authenticated_web_requests_per_period: 7200,
|
|
|
|
throttle_unauthenticated_enabled: false,
|
|
|
|
throttle_unauthenticated_period_in_seconds: 3600,
|
|
|
|
throttle_unauthenticated_requests_per_period: 3600,
|
2017-01-26 11:46:02 +00:00
|
|
|
two_factor_grace_period: 48,
|
2018-07-30 10:16:54 +00:00
|
|
|
unique_ips_limit_enabled: false,
|
|
|
|
unique_ips_limit_per_user: 10,
|
|
|
|
unique_ips_limit_time_window: 3600,
|
2017-11-29 09:12:12 +00:00
|
|
|
usage_ping_enabled: Settings.gitlab['usage_ping_enabled'],
|
2018-08-06 15:44:23 +00:00
|
|
|
instance_statistics_visibility_private: false,
|
2018-08-03 20:52:01 +00:00
|
|
|
user_default_external: false,
|
2018-08-30 12:53:06 +00:00
|
|
|
user_default_internal_regex: nil,
|
2018-09-07 14:32:28 +00:00
|
|
|
user_show_add_ssh_key_message: true,
|
2018-09-24 15:30:49 +00:00
|
|
|
usage_stats_set_by_user_id: nil,
|
|
|
|
diff_max_patch_bytes: Gitlab::Git::Diff::DEFAULT_MAX_PATCH_BYTES
|
2017-01-26 11:46:02 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-01-08 19:26:16 +00:00
|
|
|
def self.create_from_defaults
|
2017-01-26 11:46:02 +00:00
|
|
|
create(defaults)
|
2015-01-08 19:26:16 +00:00
|
|
|
end
|
2015-01-17 01:22:17 +00:00
|
|
|
|
2017-02-20 18:25:35 +00:00
|
|
|
def self.human_attribute_name(attr, _options = {})
|
|
|
|
if attr == :default_artifacts_expire_in
|
|
|
|
'Default artifacts expiration'
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-13 16:46:02 +00:00
|
|
|
def home_page_url_column_exists?
|
2018-03-15 19:50:31 +00:00
|
|
|
::Gitlab::Database.cached_column_exists?(:application_settings, :home_page_url)
|
2015-01-17 01:22:17 +00:00
|
|
|
end
|
2015-05-02 13:53:32 +00:00
|
|
|
|
2017-06-13 16:46:02 +00:00
|
|
|
def help_page_support_url_column_exists?
|
2018-03-15 19:50:31 +00:00
|
|
|
::Gitlab::Database.cached_column_exists?(:application_settings, :help_page_support_url)
|
2017-06-13 16:46:02 +00:00
|
|
|
end
|
|
|
|
|
2018-06-25 08:28:19 +00:00
|
|
|
def disabled_oauth_sign_in_sources=(sources)
|
|
|
|
sources = (sources || []).map(&:to_s) & Devise.omniauth_providers.map(&:to_s)
|
|
|
|
super(sources)
|
|
|
|
end
|
|
|
|
|
2016-07-15 23:30:38 +00:00
|
|
|
def domain_whitelist_raw
|
2017-02-07 14:16:46 +00:00
|
|
|
self.domain_whitelist&.join("\n")
|
2015-05-02 13:53:32 +00:00
|
|
|
end
|
|
|
|
|
2016-07-14 18:19:40 +00:00
|
|
|
def domain_blacklist_raw
|
2017-02-07 14:16:46 +00:00
|
|
|
self.domain_blacklist&.join("\n")
|
2016-07-14 18:19:40 +00:00
|
|
|
end
|
|
|
|
|
2016-07-15 23:30:38 +00:00
|
|
|
def domain_whitelist_raw=(values)
|
|
|
|
self.domain_whitelist = []
|
|
|
|
self.domain_whitelist = values.split(DOMAIN_LIST_SEPARATOR)
|
|
|
|
self.domain_whitelist.reject! { |d| d.empty? }
|
|
|
|
self.domain_whitelist
|
2015-05-02 13:53:32 +00:00
|
|
|
end
|
2015-12-23 09:48:10 +00:00
|
|
|
|
2016-07-14 18:19:40 +00:00
|
|
|
def domain_blacklist_raw=(values)
|
|
|
|
self.domain_blacklist = []
|
2016-07-15 18:20:45 +00:00
|
|
|
self.domain_blacklist = values.split(DOMAIN_LIST_SEPARATOR)
|
2016-07-14 18:19:40 +00:00
|
|
|
self.domain_blacklist.reject! { |d| d.empty? }
|
2016-07-15 18:20:45 +00:00
|
|
|
self.domain_blacklist
|
2016-07-14 18:19:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def domain_blacklist_file=(file)
|
|
|
|
self.domain_blacklist_raw = file.read
|
|
|
|
end
|
|
|
|
|
2016-11-03 14:12:20 +00:00
|
|
|
def repository_storages
|
2016-11-04 12:56:53 +00:00
|
|
|
Array(read_attribute(:repository_storages))
|
2016-11-03 14:12:20 +00:00
|
|
|
end
|
|
|
|
|
2017-03-02 08:22:44 +00:00
|
|
|
def default_project_visibility=(level)
|
|
|
|
super(Gitlab::VisibilityLevel.level_value(level))
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_snippet_visibility=(level)
|
|
|
|
super(Gitlab::VisibilityLevel.level_value(level))
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_group_visibility=(level)
|
|
|
|
super(Gitlab::VisibilityLevel.level_value(level))
|
|
|
|
end
|
|
|
|
|
|
|
|
def restricted_visibility_levels=(levels)
|
|
|
|
super(levels.map { |level| Gitlab::VisibilityLevel.level_value(level) })
|
|
|
|
end
|
|
|
|
|
2018-09-12 12:55:29 +00:00
|
|
|
def strip_sentry_values
|
|
|
|
sentry_dsn.strip! if sentry_dsn.present?
|
|
|
|
clientside_sentry_dsn.strip! if clientside_sentry_dsn.present?
|
|
|
|
end
|
|
|
|
|
2017-07-06 16:57:02 +00:00
|
|
|
def performance_bar_allowed_group
|
|
|
|
Group.find_by_id(performance_bar_allowed_group_id)
|
|
|
|
end
|
|
|
|
|
2017-07-07 00:34:51 +00:00
|
|
|
# Return true if the Performance Bar is enabled for a given group
|
|
|
|
def performance_bar_enabled
|
|
|
|
performance_bar_allowed_group_id.present?
|
2017-07-06 16:57:02 +00:00
|
|
|
end
|
|
|
|
|
2016-11-03 14:12:20 +00:00
|
|
|
# Choose one of the available repository storage options. Currently all have
|
|
|
|
# equal weighting.
|
|
|
|
def pick_repository_storage
|
|
|
|
repository_storages.sample
|
|
|
|
end
|
|
|
|
|
2015-12-23 09:48:10 +00:00
|
|
|
def runners_registration_token
|
|
|
|
ensure_runners_registration_token!
|
|
|
|
end
|
2016-05-09 23:21:22 +00:00
|
|
|
|
|
|
|
def health_check_access_token
|
|
|
|
ensure_health_check_access_token!
|
|
|
|
end
|
2016-11-03 14:12:20 +00:00
|
|
|
|
2017-05-09 19:40:19 +00:00
|
|
|
def usage_ping_can_be_configured?
|
|
|
|
Settings.gitlab.usage_ping_enabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def usage_ping_enabled
|
|
|
|
usage_ping_can_be_configured? && super
|
|
|
|
end
|
|
|
|
|
2017-08-25 13:08:48 +00:00
|
|
|
def allowed_key_types
|
|
|
|
SUPPORTED_KEY_TYPES.select do |type|
|
|
|
|
key_restriction_for(type) != FORBIDDEN_KEY_VALUE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def key_restriction_for(type)
|
|
|
|
attr_name = "#{type}_key_restriction"
|
|
|
|
|
2017-08-28 20:33:35 +00:00
|
|
|
has_attribute?(attr_name) ? public_send(attr_name) : FORBIDDEN_KEY_VALUE # rubocop:disable GitlabSecurity/PublicSend
|
2017-08-25 13:08:48 +00:00
|
|
|
end
|
|
|
|
|
2017-11-23 13:16:14 +00:00
|
|
|
def allow_signup?
|
|
|
|
signup_enabled? && password_authentication_enabled_for_web?
|
|
|
|
end
|
|
|
|
|
|
|
|
def password_authentication_enabled?
|
|
|
|
password_authentication_enabled_for_web? || password_authentication_enabled_for_git?
|
|
|
|
end
|
|
|
|
|
2018-08-30 12:53:06 +00:00
|
|
|
def user_default_internal_regex_enabled?
|
|
|
|
user_default_external? && user_default_internal_regex.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_default_internal_regex_instance
|
|
|
|
Regexp.new(user_default_internal_regex, Regexp::IGNORECASE)
|
|
|
|
end
|
|
|
|
|
2018-04-24 16:28:04 +00:00
|
|
|
delegate :terms, to: :latest_terms, allow_nil: true
|
|
|
|
def latest_terms
|
|
|
|
@latest_terms ||= Term.latest
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_memoized_terms
|
|
|
|
@latest_terms = nil
|
|
|
|
latest_terms
|
|
|
|
end
|
|
|
|
|
2016-11-03 14:12:20 +00:00
|
|
|
private
|
|
|
|
|
2017-04-24 19:12:05 +00:00
|
|
|
def ensure_uuid!
|
|
|
|
return if uuid?
|
|
|
|
|
|
|
|
self.uuid = SecureRandom.uuid
|
|
|
|
end
|
|
|
|
|
2016-11-03 14:12:20 +00:00
|
|
|
def check_repository_storages
|
|
|
|
invalid = repository_storages - Gitlab.config.repositories.storages.keys
|
|
|
|
errors.add(:repository_storages, "can't include: #{invalid.join(", ")}") unless
|
|
|
|
invalid.empty?
|
|
|
|
end
|
2018-04-24 16:28:04 +00:00
|
|
|
|
|
|
|
def terms_exist
|
|
|
|
return unless enforce_terms?
|
|
|
|
|
|
|
|
errors.add(:terms, "You need to set terms to be enforced") unless terms.present?
|
|
|
|
end
|
2018-05-25 16:44:15 +00:00
|
|
|
|
|
|
|
def expire_performance_bar_allowed_user_ids_cache
|
|
|
|
Gitlab::PerformanceBar.expire_allowed_user_ids_cache
|
|
|
|
end
|
2015-01-08 08:22:50 +00:00
|
|
|
end
|