2015-01-08 17:53:35 +00:00
|
|
|
module Gitlab
|
|
|
|
module CurrentSettings
|
|
|
|
def current_application_settings
|
2015-02-18 08:16:42 +00:00
|
|
|
key = :current_application_settings
|
|
|
|
|
|
|
|
RequestStore.store[key] ||= begin
|
2015-09-01 10:45:14 +00:00
|
|
|
if connect_to_db?
|
2015-03-01 15:06:46 +00:00
|
|
|
ApplicationSetting.current || ApplicationSetting.create_from_defaults
|
2015-02-18 08:16:42 +00:00
|
|
|
else
|
|
|
|
fake_application_settings
|
|
|
|
end
|
2015-01-08 18:30:35 +00:00
|
|
|
end
|
2015-01-08 17:53:35 +00:00
|
|
|
end
|
2015-01-08 19:26:16 +00:00
|
|
|
|
|
|
|
def fake_application_settings
|
|
|
|
OpenStruct.new(
|
|
|
|
default_projects_limit: Settings.gitlab['default_projects_limit'],
|
2015-01-25 17:38:35 +00:00
|
|
|
default_branch_protection: Settings.gitlab['default_branch_protection'],
|
2015-01-08 19:26:16 +00:00
|
|
|
signup_enabled: Settings.gitlab['signup_enabled'],
|
|
|
|
signin_enabled: Settings.gitlab['signin_enabled'],
|
|
|
|
gravatar_enabled: Settings.gravatar['enabled'],
|
|
|
|
sign_in_text: Settings.extra['sign_in_text'],
|
2015-03-20 12:11:12 +00:00
|
|
|
restricted_visibility_levels: Settings.gitlab['restricted_visibility_levels'],
|
2015-06-05 15:50:37 +00:00
|
|
|
max_attachment_size: Settings.gitlab['max_attachment_size'],
|
2015-08-12 06:13:20 +00:00
|
|
|
session_expire_delay: Settings.gitlab['session_expire_delay'],
|
2015-11-03 13:45:41 +00:00
|
|
|
import_sources: Settings.gitlab['import_sources'],
|
|
|
|
shared_runners_enabled: Settings.gitlab_ci['shared_runners_enabled'],
|
2015-11-22 13:27:30 +00:00
|
|
|
max_artifacts_size: Settings.artifacts['max_size'],
|
2015-01-08 19:26:16 +00:00
|
|
|
)
|
|
|
|
end
|
2015-09-01 10:45:14 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def connect_to_db?
|
|
|
|
use_db = if ENV['USE_DB'] == "false"
|
|
|
|
false
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2016-01-26 14:11:15 +00:00
|
|
|
use_db && ActiveRecord::Base.connected? &&
|
2016-01-25 19:00:59 +00:00
|
|
|
# The following condition is important: if a migrations adds a
|
|
|
|
# column to the application_settings table and a validation in
|
|
|
|
# the ApplicationSetting uses this new column we might end-up in
|
|
|
|
# a vicious circle where migration crash before being done.
|
|
|
|
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/12606 for
|
|
|
|
# a thorough explanation.
|
|
|
|
!ActiveRecord::Migrator.needs_migration? &&
|
2015-12-30 16:26:54 +00:00
|
|
|
ActiveRecord::Base.connection.table_exists?('application_settings')
|
2016-01-08 13:31:39 +00:00
|
|
|
|
|
|
|
rescue ActiveRecord::NoDatabaseError
|
|
|
|
false
|
2015-09-01 10:45:14 +00:00
|
|
|
end
|
2015-01-08 17:53:35 +00:00
|
|
|
end
|
|
|
|
end
|