Read about our upcoming Code of Conduct on this issue

Commit a4b6882f authored by Mario de la Ossa's avatar Mario de la Ossa Committed by Sean McGivern
Browse files

use Gitlab::UserSettings directly as a singleton instead of including/extending it

parent 149231b8a5e8
module API
module Helpers
module Runner
include Gitlab::CurrentSettings
JOB_TOKEN_HEADER = 'HTTP_JOB_TOKEN'.freeze
JOB_TOKEN_PARAM = :token
UPDATE_RUNNER_EVERY = 10 * 60
def runner_registration_token_valid?
ActiveSupport::SecurityUtils.variable_size_secure_compare(params[:token],
current_application_settings.runners_registration_token)
Gitlab::CurrentSettings.runners_registration_token)
end
def get_runner_version_from_params
......@@ -70,7 +68,7 @@ def job_token_valid?(job)
end
def max_artifacts_size
current_application_settings.max_artifacts_size.megabytes.to_i
Gitlab::CurrentSettings.max_artifacts_size.megabytes.to_i
end
end
end
......
# Read about interceptors in http://guides.rubyonrails.org/action_mailer_basics.html#intercepting-emails
class EmailTemplateInterceptor
extend Gitlab::CurrentSettings
def self.delivering_email(message)
# Remove HTML part if HTML emails are disabled.
unless current_application_settings.html_emails_enabled
unless Gitlab::CurrentSettings.html_emails_enabled
message.parts.delete_if do |part|
part.content_type.start_with?('text/html')
end
......
......@@ -6,8 +6,6 @@ module Gitlab
# Parser/renderer for the AsciiDoc format that uses Asciidoctor and filters
# the resulting HTML through HTML pipeline filters.
module Asciidoc
extend Gitlab::CurrentSettings
DEFAULT_ADOC_ATTRS = [
'showtitle', 'idprefix=user-content-', 'idseparator=-', 'env=gitlab',
'env-gitlab', 'source-highlighter=html-pipeline', 'icons=font'
......@@ -33,9 +31,9 @@ def self.render(input, context)
def self.plantuml_setup
Asciidoctor::PlantUml.configure do |conf|
conf.url = current_application_settings.plantuml_url
conf.svg_enable = current_application_settings.plantuml_enabled
conf.png_enable = current_application_settings.plantuml_enabled
conf.url = Gitlab::CurrentSettings.plantuml_url
conf.svg_enable = Gitlab::CurrentSettings.plantuml_enabled
conf.png_enable = Gitlab::CurrentSettings.plantuml_enabled
conf.txt_enable = false
end
end
......
......@@ -14,8 +14,6 @@ module Auth
DEFAULT_SCOPES = [:api].freeze
class << self
include Gitlab::CurrentSettings
def find_for_git_client(login, password, project:, ip:)
raise "Must provide an IP for rate limiting" if ip.nil?
......@@ -57,7 +55,7 @@ def find_with_user_password(login, password)
if user.nil? || user.ldap_user?
# Second chance - try LDAP authentication
Gitlab::LDAP::Authentication.login(login, password)
elsif current_application_settings.password_authentication_enabled_for_git?
elsif Gitlab::CurrentSettings.password_authentication_enabled_for_git?
user if user.active? && user.valid_password?(password)
end
end
......@@ -87,7 +85,7 @@ def rate_limit!(ip, success:, login:)
private
def authenticate_using_internal_or_ldap_password?
current_application_settings.password_authentication_enabled_for_git? || Gitlab::LDAP::Config.enabled?
Gitlab::CurrentSettings.password_authentication_enabled_for_git? || Gitlab::LDAP::Config.enabled?
end
def service_request_check(login, password, project)
......
module Gitlab
module CurrentSettings
extend self
class << self
def current_application_settings
if RequestStore.active?
RequestStore.fetch(:current_application_settings) { ensure_application_settings! }
......@@ -10,10 +9,16 @@ def current_application_settings
end
end
delegate :sidekiq_throttling_enabled?, to: :current_application_settings
def fake_application_settings(defaults = ::ApplicationSetting.defaults)
FakeApplicationSettings.new(defaults)
Gitlab::FakeApplicationSettings.new(defaults)
end
def method_missing(name, *args, &block)
current_application_settings.send(name, *args, &block) # rubocop:disable GitlabSecurity/PublicSend
end
def respond_to_missing?(name, include_private = false)
current_application_settings.respond_to?(name, include_private) || super
end
private
......@@ -70,4 +75,5 @@ def connect_to_db?
false
end
end
end
end
......@@ -3,12 +3,11 @@
module Gitlab
module GonHelper
include WebpackHelper
include Gitlab::CurrentSettings
def add_gon_variables
gon.api_version = 'v4'
gon.default_avatar_url = URI.join(Gitlab.config.gitlab.url, ActionController::Base.helpers.image_path('no_avatar.png')).to_s
gon.max_file_size = current_application_settings.max_attachment_size
gon.max_file_size = Gitlab::CurrentSettings.max_attachment_size
gon.asset_host = ActionController::Base.asset_host
gon.webpack_public_path = webpack_public_path
gon.relative_url_root = Gitlab.config.gitlab.relative_url_root
......@@ -16,7 +15,7 @@ def add_gon_variables
gon.user_color_scheme = Gitlab::ColorSchemes.for_user(current_user).css_class
gon.katex_css_url = ActionController::Base.helpers.asset_path('katex.css')
gon.katex_js_url = ActionController::Base.helpers.asset_path('katex.js')
gon.sentry_dsn = current_application_settings.clientside_sentry_dsn if current_application_settings.clientside_sentry_enabled
gon.sentry_dsn = Gitlab::CurrentSettings.clientside_sentry_dsn if Gitlab::CurrentSettings.clientside_sentry_enabled
gon.gitlab_url = Gitlab.config.gitlab.url
gon.revision = Gitlab::REVISION
gon.gitlab_logo = ActionController::Base.helpers.asset_path('gitlab_logo.png')
......
module Gitlab
module LegacyGithubImport
class ProjectCreator
include Gitlab::CurrentSettings
attr_reader :repo, :name, :namespace, :current_user, :session_data, :type
def initialize(repo, name, namespace, current_user, session_data, type: 'github')
......@@ -36,7 +34,7 @@ def import_url
end
def visibility_level
repo.private ? Gitlab::VisibilityLevel::PRIVATE : current_application_settings.default_project_visibility
repo.private ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::CurrentSettings.default_project_visibility
end
#
......
......@@ -71,8 +71,7 @@ def provide_metric(name)
end
def prometheus_metrics_enabled_unmemoized
metrics_folder_present? &&
Gitlab::CurrentSettings.current_application_settings[:prometheus_metrics_enabled] || false
metrics_folder_present? && Gitlab::CurrentSettings.prometheus_metrics_enabled || false
end
end
end
......
......@@ -4,7 +4,6 @@ module Gitlab
module Middleware
class Go
include ActionView::Helpers::TagHelper
include Gitlab::CurrentSettings
PROJECT_PATH_REGEX = %r{\A(#{Gitlab::PathRegex.full_namespace_route_regex}/#{Gitlab::PathRegex.project_route_regex})/}.freeze
......@@ -42,7 +41,7 @@ def go_body(path)
project_url = URI.join(config.gitlab.url, path)
import_prefix = strip_url(project_url.to_s)
repository_url = if current_application_settings.enabled_git_access_protocol == 'ssh'
repository_url = if Gitlab::CurrentSettings.enabled_git_access_protocol == 'ssh'
shell = config.gitlab_shell
port = ":#{shell.ssh_port}" unless shell.ssh_port == 22
"ssh://#{shell.ssh_user}@#{shell.ssh_host}#{port}/#{path}.git"
......
module Gitlab
module PerformanceBar
extend Gitlab::CurrentSettings
ALLOWED_USER_IDS_KEY = 'performance_bar_allowed_user_ids:v2'.freeze
EXPIRY_TIME = 5.minutes
......@@ -13,7 +11,7 @@ def self.enabled?(user = nil)
end
def self.allowed_group_id
current_application_settings.performance_bar_allowed_group_id
Gitlab::CurrentSettings.performance_bar_allowed_group_id
end
def self.allowed_user_ids
......
module Gitlab
class PollingInterval
extend Gitlab::CurrentSettings
HEADER_NAME = 'Poll-Interval'.freeze
def self.set_header(response, interval:)
if polling_enabled?
multiplier = current_application_settings.polling_interval_multiplier
multiplier = Gitlab::CurrentSettings.polling_interval_multiplier
value = (interval * multiplier).to_i
else
value = -1
......@@ -16,7 +14,7 @@ def self.set_header(response, interval:)
end
def self.polling_enabled?
!current_application_settings.polling_interval_multiplier.zero?
!Gitlab::CurrentSettings.polling_interval_multiplier.zero?
end
end
end
module Gitlab
module ProtocolAccess
extend Gitlab::CurrentSettings
def self.allowed?(protocol)
if protocol == 'web'
true
elsif current_application_settings.enabled_git_access_protocol.blank?
elsif Gitlab::CurrentSettings.enabled_git_access_protocol.blank?
true
else
protocol == current_application_settings.enabled_git_access_protocol
protocol == Gitlab::CurrentSettings.enabled_git_access_protocol
end
end
end
......
module Gitlab
module Recaptcha
extend Gitlab::CurrentSettings
def self.load_configurations!
if current_application_settings.recaptcha_enabled
if Gitlab::CurrentSettings.recaptcha_enabled
::Recaptcha.configure do |config|
config.public_key = current_application_settings.recaptcha_site_key
config.private_key = current_application_settings.recaptcha_private_key
config.public_key = Gitlab::CurrentSettings.recaptcha_site_key
config.private_key = Gitlab::CurrentSettings.recaptcha_private_key
end
true
......@@ -14,7 +12,7 @@ def self.load_configurations!
end
def self.enabled?
current_application_settings.recaptcha_enabled
Gitlab::CurrentSettings.recaptcha_enabled
end
end
end
module Gitlab
module Sentry
extend Gitlab::CurrentSettings
def self.enabled?
Rails.env.production? && current_application_settings.sentry_enabled?
Rails.env.production? && Gitlab::CurrentSettings.sentry_enabled?
end
def self.context(current_user = nil)
......
module Gitlab
class UsageData
class << self
include Gitlab::CurrentSettings
def data(force_refresh: false)
Rails.cache.fetch('usage_data', force: force_refresh, expires_in: 2.weeks) { uncached_data }
end
......@@ -19,7 +17,7 @@ def to_json(force_refresh: false)
def license_usage_data
usage_data = {
uuid: current_application_settings.uuid,
uuid: Gitlab::CurrentSettings.uuid,
hostname: Gitlab.config.gitlab.host,
version: Gitlab::VERSION,
active_user_count: User.active.count,
......@@ -79,9 +77,9 @@ def features_usage_data
def features_usage_data_ce
{
signup: current_application_settings.allow_signup?,
signup: Gitlab::CurrentSettings.allow_signup?,
ldap: Gitlab.config.ldap.enabled,
gravatar: current_application_settings.gravatar_enabled?,
gravatar: Gitlab::CurrentSettings.gravatar_enabled?,
omniauth: Gitlab.config.omniauth.enabled,
reply_by_email: Gitlab::IncomingEmail.enabled?,
container_registry: Gitlab.config.registry.enabled,
......
......@@ -5,7 +5,6 @@
#
module Gitlab
module VisibilityLevel
extend CurrentSettings
extend ActiveSupport::Concern
included do
......@@ -58,7 +57,7 @@ def string_options
end
def allowed_levels
restricted_levels = current_application_settings.restricted_visibility_levels
restricted_levels = Gitlab::CurrentSettings.restricted_visibility_levels
self.values - restricted_levels
end
......@@ -81,7 +80,7 @@ def allowed_level?(level)
end
def non_restricted_level?(level)
restricted_levels = current_application_settings.restricted_visibility_levels
restricted_levels = Gitlab::CurrentSettings.restricted_visibility_levels
if restricted_levels.nil?
true
......
......@@ -5,7 +5,7 @@
let(:json_response) { JSON.parse(response.body) }
let(:xml_response) { Hash.from_xml(response.body)['hash'] }
let(:token) { current_application_settings.health_check_access_token }
let(:token) { Gitlab::CurrentSettings.health_check_access_token }
let(:whitelisted_ip) { '127.0.0.1' }
let(:not_whitelisted_ip) { '127.0.0.2' }
......
......@@ -4,7 +4,7 @@
include StubENV
let(:json_response) { JSON.parse(response.body) }
let(:token) { current_application_settings.health_check_access_token }
let(:token) { Gitlab::CurrentSettings.health_check_access_token }
let(:whitelisted_ip) { '127.0.0.1' }
let(:not_whitelisted_ip) { '127.0.0.2' }
......
......@@ -16,8 +16,7 @@
end
it 'redirects back to profile page if OAuth applications are disabled' do
settings = double(user_oauth_applications?: false)
allow_any_instance_of(Gitlab::CurrentSettings).to receive(:current_application_settings).and_return(settings)
allow(Gitlab::CurrentSettings.current_application_settings).to receive(:user_oauth_applications?).and_return(false)
get :index
......
......@@ -17,7 +17,7 @@
page.has_text? 'Health Check'
page.has_text? 'Health information can be retrieved'
token = current_application_settings.health_check_access_token
token = Gitlab::CurrentSettings.health_check_access_token
expect(page).to have_content("Access token is #{token}")
expect(page).to have_selector('#health-check-token', text: token)
......@@ -25,7 +25,7 @@
describe 'reload access token' do
it 'changes the access token' do
orig_token = current_application_settings.health_check_access_token
orig_token = Gitlab::CurrentSettings.health_check_access_token
click_button 'Reset health check access token'
expect(page).to have_content('New health check access token has been generated!')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment