BigW Consortium Gitlab

current_settings.rb 1.36 KB
Newer Older
1 2 3
module Gitlab
  module CurrentSettings
    def current_application_settings
4 5 6
      key = :current_application_settings

      RequestStore.store[key] ||= begin
7
        if connect_to_db?
8
          ApplicationSetting.current || ApplicationSetting.create_from_defaults
9 10 11
        else
          fake_application_settings
        end
12
      end
13
    end
14 15 16 17

    def fake_application_settings
      OpenStruct.new(
        default_projects_limit: Settings.gitlab['default_projects_limit'],
18
        default_branch_protection: Settings.gitlab['default_branch_protection'],
19 20 21 22
        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'],
23
        restricted_visibility_levels: Settings.gitlab['restricted_visibility_levels'],
24
        max_attachment_size: Settings.gitlab['max_attachment_size'],
25 26
        session_expire_delay: Settings.gitlab['session_expire_delay'],
        import_sources: Settings.gitlab['import_sources']
27 28
      )
    end
29 30 31 32 33 34 35 36 37 38 39 40

    private

    def connect_to_db?
      use_db = if ENV['USE_DB'] == "false"
                 false
               else
                 true
               end

      use_db && ActiveRecord::Base.connection.active? && ActiveRecord::Base.connection.table_exists?('application_settings')
    end
41 42
  end
end