2015-01-08 08:22:50 +00:00
|
|
|
class ApplicationSetting < ActiveRecord::Base
|
2016-10-06 21:17:11 +00:00
|
|
|
include CacheMarkdownField
|
2015-12-10 09:48:37 +00:00
|
|
|
include TokenAuthenticatable
|
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
|
|
|
|
2017-02-21 23:32:18 +00:00
|
|
|
CACHE_KEY = 'application_setting.last'.freeze
|
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
|
|
|
|
2015-03-01 15:06:46 +00:00
|
|
|
serialize :restricted_visibility_levels
|
2015-08-12 06:13:20 +00:00
|
|
|
serialize :import_sources
|
2016-05-23 04:36:25 +00:00
|
|
|
serialize :disabled_oauth_sign_in_sources, Array
|
2016-07-15 23:30:38 +00:00
|
|
|
serialize :domain_whitelist, Array
|
2016-07-14 18:19:40 +00:00
|
|
|
serialize :domain_blacklist, Array
|
2016-11-03 14:12:20 +00:00
|
|
|
serialize :repository_storages
|
2016-11-10 17:36:52 +00:00
|
|
|
serialize :sidekiq_throttling_queues, Array
|
2016-07-14 18:19:40 +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
|
|
|
|
|
|
|
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,
|
|
|
|
if: :home_page_url_column_exist
|
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
|
|
|
|
|
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-07-26 03:59:39 +00:00
|
|
|
validates :koding_url,
|
|
|
|
presence: true,
|
|
|
|
if: :koding_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
|
|
|
|
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-11-04 22:54:24 +00:00
|
|
|
validates :sidekiq_throttling_factor,
|
|
|
|
numericality: { greater_than: 0, less_than: 1 },
|
|
|
|
presence: { message: 'Throttling factor cannot be empty if Sidekiq Throttling is enabled.' },
|
|
|
|
if: :sidekiq_throttling_enabled?
|
|
|
|
|
|
|
|
validates :sidekiq_throttling_queues,
|
|
|
|
presence: { message: 'Queues to throttle cannot be empty if Sidekiq Throttling is enabled.' },
|
|
|
|
if: :sidekiq_throttling_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,
|
|
|
|
numericality: { only_integer: true, greater_than: :housekeeping_incremental_repack_period }
|
|
|
|
|
|
|
|
validates :housekeeping_gc_period,
|
|
|
|
presence: true,
|
|
|
|
numericality: { only_integer: true, greater_than: :housekeeping_full_repack_period }
|
|
|
|
|
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 }
|
|
|
|
|
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|
|
|
|
|
unless Gitlab::VisibilityLevel.options.has_value?(level)
|
|
|
|
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|
|
|
|
|
unless Gitlab::ImportSources.options.has_value?(source)
|
|
|
|
record.errors.add(attr, "'#{source}' is not a import source")
|
2015-08-12 06:13:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-04 12:57:00 +00:00
|
|
|
validates_each :disabled_oauth_sign_in_sources do |record, attr, value|
|
2017-02-07 14:16:46 +00:00
|
|
|
value&.each do |source|
|
|
|
|
unless Devise.omniauth_providers.include?(source.to_sym)
|
|
|
|
record.errors.add(attr, "'#{source}' is not an OAuth sign-in source")
|
2016-05-04 12:57:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
|
2015-12-03 08:09:10 +00:00
|
|
|
Rails.cache.write(CACHE_KEY, self)
|
2015-11-12 09:19:03 +00:00
|
|
|
end
|
|
|
|
|
2015-01-08 08:22:50 +00:00
|
|
|
def self.current
|
2017-03-18 09:29:25 +00:00
|
|
|
ensure_cache_setup
|
|
|
|
|
2015-12-03 08:09:10 +00:00
|
|
|
Rails.cache.fetch(CACHE_KEY) do
|
2015-11-12 09:19:03 +00:00
|
|
|
ApplicationSetting.last
|
|
|
|
end
|
2015-01-08 08:22:50 +00:00
|
|
|
end
|
2015-01-08 19:26:16 +00:00
|
|
|
|
2015-11-25 19:30:33 +00:00
|
|
|
def self.expire
|
2015-12-03 08:09:10 +00:00
|
|
|
Rails.cache.delete(CACHE_KEY)
|
2017-01-26 11:45:14 +00:00
|
|
|
rescue
|
|
|
|
# Gracefully handle when Redis is not available. For example,
|
2017-01-27 20:36:52 +00:00
|
|
|
# omnibus may fail here during gitlab:assets:compile.
|
2015-11-25 19:30:33 +00:00
|
|
|
end
|
|
|
|
|
2016-05-29 19:53:30 +00:00
|
|
|
def self.cached
|
2017-03-18 09:29:25 +00:00
|
|
|
ensure_cache_setup
|
2016-05-29 19:53:30 +00:00
|
|
|
Rails.cache.fetch(CACHE_KEY)
|
|
|
|
end
|
|
|
|
|
2017-03-18 09:29:25 +00:00
|
|
|
def self.ensure_cache_setup
|
|
|
|
# This is a workaround for a Rails bug that causes attribute methods not
|
|
|
|
# to be loaded when read from cache: https://github.com/rails/rails/issues/27348
|
|
|
|
ApplicationSetting.define_attribute_methods
|
|
|
|
end
|
|
|
|
|
2017-01-26 11:46:02 +00:00
|
|
|
def self.defaults_ce
|
|
|
|
{
|
|
|
|
after_sign_up_text: nil,
|
|
|
|
akismet_enabled: false,
|
|
|
|
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'],
|
|
|
|
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'],
|
2017-02-17 13:50:02 +00:00
|
|
|
default_group_visibility: Settings.gitlab.default_projects_features['visibility_level'],
|
2017-01-26 11:46:02 +00:00
|
|
|
disabled_oauth_sign_in_sources: [],
|
|
|
|
domain_whitelist: Settings.gitlab['domain_whitelist'],
|
|
|
|
gravatar_enabled: Settings.gravatar['enabled'],
|
|
|
|
help_page_text: nil,
|
2017-02-06 12:48:46 +00:00
|
|
|
unique_ips_limit_per_user: 10,
|
|
|
|
unique_ips_limit_time_window: 3600,
|
|
|
|
unique_ips_limit_enabled: 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,
|
|
|
|
import_sources: Gitlab::ImportSources.values,
|
|
|
|
koding_enabled: false,
|
|
|
|
koding_url: nil,
|
|
|
|
max_artifacts_size: Settings.artifacts['max_size'],
|
|
|
|
max_attachment_size: Settings.gitlab['max_attachment_size'],
|
|
|
|
plantuml_enabled: false,
|
|
|
|
plantuml_url: nil,
|
|
|
|
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,
|
|
|
|
sidekiq_throttling_enabled: false,
|
|
|
|
sign_in_text: nil,
|
|
|
|
signin_enabled: Settings.gitlab['signin_enabled'],
|
|
|
|
signup_enabled: Settings.gitlab['signup_enabled'],
|
2017-02-14 10:00:37 +00:00
|
|
|
terminal_max_session_time: 0,
|
2017-01-26 11:46:02 +00:00
|
|
|
two_factor_grace_period: 48,
|
2017-04-03 13:17:04 +00:00
|
|
|
user_default_external: false,
|
|
|
|
polling_interval_multiplier: 1
|
2017-01-26 11:46:02 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.defaults
|
|
|
|
defaults_ce
|
|
|
|
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
|
|
|
|
|
2015-01-17 01:22:17 +00:00
|
|
|
def home_page_url_column_exist
|
|
|
|
ActiveRecord::Base.connection.column_exists?(:application_settings, :home_page_url)
|
|
|
|
end
|
2015-05-02 13:53:32 +00:00
|
|
|
|
2016-11-13 00:00:21 +00:00
|
|
|
def sidekiq_throttling_column_exists?
|
|
|
|
ActiveRecord::Base.connection.column_exists?(:application_settings, :sidekiq_throttling_enabled)
|
|
|
|
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
|
|
|
|
|
|
|
|
# repository_storage is still required in the API. Remove in 9.0
|
|
|
|
def repository_storage
|
|
|
|
repository_storages.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def repository_storage=(value)
|
|
|
|
self.repository_storages = [value]
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
2016-11-13 00:00:21 +00:00
|
|
|
def sidekiq_throttling_enabled?
|
|
|
|
return false unless sidekiq_throttling_column_exists?
|
|
|
|
|
|
|
|
sidekiq_throttling_enabled
|
|
|
|
end
|
|
|
|
|
2016-11-03 14:12:20 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
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
|
2015-01-08 08:22:50 +00:00
|
|
|
end
|