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
class Admin::CohortsController < Admin::ApplicationController class Admin::CohortsController < Admin::ApplicationController
def index def index
if current_application_settings.usage_ping_enabled if Gitlab::CurrentSettings.usage_ping_enabled
cohorts_results = Rails.cache.fetch('cohorts', expires_in: 1.day) do cohorts_results = Rails.cache.fetch('cohorts', expires_in: 1.day) do
CohortsService.new.execute CohortsService.new.execute
end end
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
require 'fogbugz' require 'fogbugz'
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
include Gitlab::CurrentSettings
include Gitlab::GonHelper include Gitlab::GonHelper
include GitlabRoutingHelper include GitlabRoutingHelper
include PageLayoutHelper include PageLayoutHelper
...@@ -28,7 +27,7 @@ class ApplicationController < ActionController::Base ...@@ -28,7 +27,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception protect_from_forgery with: :exception
helper_method :can?, :current_application_settings helper_method :can?
helper_method :import_sources_enabled?, :github_import_enabled?, :gitea_import_enabled?, :github_import_configured?, :gitlab_import_enabled?, :gitlab_import_configured?, :bitbucket_import_enabled?, :bitbucket_import_configured?, :google_code_import_enabled?, :fogbugz_import_enabled?, :git_import_enabled?, :gitlab_project_import_enabled? helper_method :import_sources_enabled?, :github_import_enabled?, :gitea_import_enabled?, :github_import_configured?, :gitlab_import_enabled?, :gitlab_import_configured?, :bitbucket_import_enabled?, :bitbucket_import_configured?, :google_code_import_enabled?, :fogbugz_import_enabled?, :git_import_enabled?, :gitlab_project_import_enabled?
rescue_from Encoding::CompatibilityError do |exception| rescue_from Encoding::CompatibilityError do |exception|
...@@ -120,7 +119,7 @@ def after_sign_in_path_for(resource) ...@@ -120,7 +119,7 @@ def after_sign_in_path_for(resource)
end end
def after_sign_out_path_for(resource) def after_sign_out_path_for(resource)
current_application_settings.after_sign_out_path.presence || new_user_session_path Gitlab::CurrentSettings.after_sign_out_path.presence || new_user_session_path
end end
def can?(object, action, subject = :global) def can?(object, action, subject = :global)
...@@ -268,15 +267,15 @@ def require_email ...@@ -268,15 +267,15 @@ def require_email
end end
def import_sources_enabled? def import_sources_enabled?
!current_application_settings.import_sources.empty? !Gitlab::CurrentSettings.import_sources.empty?
end end
def github_import_enabled? def github_import_enabled?
current_application_settings.import_sources.include?('github') Gitlab::CurrentSettings.import_sources.include?('github')
end end
def gitea_import_enabled? def gitea_import_enabled?
current_application_settings.import_sources.include?('gitea') Gitlab::CurrentSettings.import_sources.include?('gitea')
end end
def github_import_configured? def github_import_configured?
...@@ -284,7 +283,7 @@ def github_import_configured? ...@@ -284,7 +283,7 @@ def github_import_configured?
end end
def gitlab_import_enabled? def gitlab_import_enabled?
request.host != 'gitlab.com' && current_application_settings.import_sources.include?('gitlab') request.host != 'gitlab.com' && Gitlab::CurrentSettings.import_sources.include?('gitlab')
end end
def gitlab_import_configured? def gitlab_import_configured?
...@@ -292,7 +291,7 @@ def gitlab_import_configured? ...@@ -292,7 +291,7 @@ def gitlab_import_configured?
end end
def bitbucket_import_enabled? def bitbucket_import_enabled?
current_application_settings.import_sources.include?('bitbucket') Gitlab::CurrentSettings.import_sources.include?('bitbucket')
end end
def bitbucket_import_configured? def bitbucket_import_configured?
...@@ -300,19 +299,19 @@ def bitbucket_import_configured? ...@@ -300,19 +299,19 @@ def bitbucket_import_configured?
end end
def google_code_import_enabled? def google_code_import_enabled?
current_application_settings.import_sources.include?('google_code') Gitlab::CurrentSettings.import_sources.include?('google_code')
end end
def fogbugz_import_enabled? def fogbugz_import_enabled?
current_application_settings.import_sources.include?('fogbugz') Gitlab::CurrentSettings.import_sources.include?('fogbugz')
end end
def git_import_enabled? def git_import_enabled?
current_application_settings.import_sources.include?('git') Gitlab::CurrentSettings.import_sources.include?('git')
end end
def gitlab_project_import_enabled? def gitlab_project_import_enabled?
current_application_settings.import_sources.include?('gitlab_project') Gitlab::CurrentSettings.import_sources.include?('gitlab_project')
end end
# U2F (universal 2nd factor) devices need a unique identifier for the application # U2F (universal 2nd factor) devices need a unique identifier for the application
......
...@@ -20,13 +20,13 @@ def check_two_factor_requirement ...@@ -20,13 +20,13 @@ def check_two_factor_requirement
end end
def two_factor_authentication_required? def two_factor_authentication_required?
current_application_settings.require_two_factor_authentication? || Gitlab::CurrentSettings.require_two_factor_authentication? ||
current_user.try(:require_two_factor_authentication_from_group?) current_user.try(:require_two_factor_authentication_from_group?)
end end
def two_factor_authentication_reason(global: -> {}, group: -> {}) def two_factor_authentication_reason(global: -> {}, group: -> {})
if two_factor_authentication_required? if two_factor_authentication_required?
if current_application_settings.require_two_factor_authentication? if Gitlab::CurrentSettings.require_two_factor_authentication?
global.call global.call
else else
groups = current_user.expanded_groups_requiring_two_factor_authentication.reorder(name: :asc) groups = current_user.expanded_groups_requiring_two_factor_authentication.reorder(name: :asc)
...@@ -36,7 +36,7 @@ def two_factor_authentication_reason(global: -> {}, group: -> {}) ...@@ -36,7 +36,7 @@ def two_factor_authentication_reason(global: -> {}, group: -> {})
end end
def two_factor_grace_period def two_factor_grace_period
periods = [current_application_settings.two_factor_grace_period] periods = [Gitlab::CurrentSettings.two_factor_grace_period]
periods << current_user.two_factor_grace_period if current_user.try(:require_two_factor_authentication_from_group?) periods << current_user.two_factor_grace_period if current_user.try(:require_two_factor_authentication_from_group?)
periods.min periods.min
end end
......
module RequiresWhitelistedMonitoringClient module RequiresWhitelistedMonitoringClient
extend ActiveSupport::Concern extend ActiveSupport::Concern
include Gitlab::CurrentSettings
included do included do
before_action :validate_ip_whitelisted_or_valid_token! before_action :validate_ip_whitelisted_or_valid_token!
end end
...@@ -26,7 +24,7 @@ def valid_token? ...@@ -26,7 +24,7 @@ def valid_token?
token.present? && token.present? &&
ActiveSupport::SecurityUtils.variable_size_secure_compare( ActiveSupport::SecurityUtils.variable_size_secure_compare(
token, token,
current_application_settings.health_check_access_token Gitlab::CurrentSettings.health_check_access_token
) )
end end
......
...@@ -51,7 +51,7 @@ def authenticate_user! ...@@ -51,7 +51,7 @@ def authenticate_user!
return if current_user return if current_user
notice = "To accept this invitation, sign in" notice = "To accept this invitation, sign in"
notice << " or create an account" if current_application_settings.allow_signup? notice << " or create an account" if Gitlab::CurrentSettings.allow_signup?
notice << "." notice << "."
store_location_for :user, request.fullpath store_location_for :user, request.fullpath
......
...@@ -10,6 +10,6 @@ def index ...@@ -10,6 +10,6 @@ def index
private private
def check_integration! def check_integration!
render_404 unless current_application_settings.koding_enabled? render_404 unless Gitlab::CurrentSettings.koding_enabled?
end end
end end
class Oauth::ApplicationsController < Doorkeeper::ApplicationsController class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
include Gitlab::CurrentSettings
include Gitlab::GonHelper include Gitlab::GonHelper
include PageLayoutHelper include PageLayoutHelper
include OauthApplications include OauthApplications
...@@ -31,7 +30,7 @@ def create ...@@ -31,7 +30,7 @@ def create
private private
def verify_user_oauth_applications_enabled def verify_user_oauth_applications_enabled
return if current_application_settings.user_oauth_applications? return if Gitlab::CurrentSettings.user_oauth_applications?
redirect_to profile_path redirect_to profile_path
end end
......
...@@ -145,7 +145,7 @@ def handle_signup_error ...@@ -145,7 +145,7 @@ def handle_signup_error
label = Gitlab::OAuth::Provider.label_for(oauth['provider']) label = Gitlab::OAuth::Provider.label_for(oauth['provider'])
message = "Signing in using your #{label} account without a pre-existing GitLab account is not allowed." message = "Signing in using your #{label} account without a pre-existing GitLab account is not allowed."
if current_application_settings.allow_signup? if Gitlab::CurrentSettings.allow_signup?
message << " Create a GitLab account first, and then connect it to your #{label} account." message << " Create a GitLab account first, and then connect it to your #{label} account."
end end
......
class PasswordsController < Devise::PasswordsController class PasswordsController < Devise::PasswordsController
include Gitlab::CurrentSettings
skip_before_action :require_no_authentication, only: [:edit, :update] skip_before_action :require_no_authentication, only: [:edit, :update]
before_action :resource_from_email, only: [:create] before_action :resource_from_email, only: [:create]
...@@ -46,7 +44,7 @@ def check_password_authentication_available ...@@ -46,7 +44,7 @@ def check_password_authentication_available
if resource if resource
return if resource.allow_password_authentication? return if resource.allow_password_authentication?
else else
return if current_application_settings.password_authentication_enabled? return if Gitlab::CurrentSettings.password_authentication_enabled?
end end
redirect_to after_sending_reset_password_instructions_path_for(resource_name), redirect_to after_sending_reset_password_instructions_path_for(resource_name),
......
...@@ -394,7 +394,7 @@ def build_canonical_path(project) ...@@ -394,7 +394,7 @@ def build_canonical_path(project)
end end
def project_export_enabled def project_export_enabled
render_404 unless current_application_settings.project_export_enabled? render_404 unless Gitlab::CurrentSettings.project_export_enabled?
end end
def redirect_git_extension def redirect_git_extension
......
...@@ -23,7 +23,7 @@ def index ...@@ -23,7 +23,7 @@ def index
def redirect_unlogged_user def redirect_unlogged_user
if redirect_to_home_page_url? if redirect_to_home_page_url?
redirect_to(current_application_settings.home_page_url) redirect_to(Gitlab::CurrentSettings.home_page_url)
else else
redirect_to(new_user_session_path) redirect_to(new_user_session_path)
end end
...@@ -48,9 +48,9 @@ def redirect_logged_user ...@@ -48,9 +48,9 @@ def redirect_logged_user
def redirect_to_home_page_url? def redirect_to_home_page_url?
# If user is not signed-in and tries to access root_path - redirect him to landing page # If user is not signed-in and tries to access root_path - redirect him to landing page
# Don't redirect to the default URL to prevent endless redirections # Don't redirect to the default URL to prevent endless redirections
return false unless current_application_settings.home_page_url.present? return false unless Gitlab::CurrentSettings.home_page_url.present?
home_page_url = current_application_settings.home_page_url.chomp('/') home_page_url = Gitlab::CurrentSettings.home_page_url.chomp('/')
root_urls = [Gitlab.config.gitlab['url'].chomp('/'), root_url.chomp('/')] root_urls = [Gitlab.config.gitlab['url'].chomp('/'), root_url.chomp('/')]
root_urls.exclude?(home_page_url) root_urls.exclude?(home_page_url)
......
module ApplicationSettingsHelper module ApplicationSettingsHelper
extend self extend self
include Gitlab::CurrentSettings
delegate :allow_signup?, delegate :allow_signup?,
:gravatar_enabled?, :gravatar_enabled?,
:password_authentication_enabled_for_web?, :password_authentication_enabled_for_web?,
:akismet_enabled?, :akismet_enabled?,
:koding_enabled?, :koding_enabled?,
to: :current_application_settings to: :'Gitlab::CurrentSettings.current_application_settings'
def user_oauth_applications? def user_oauth_applications?
current_application_settings.user_oauth_applications Gitlab::CurrentSettings.user_oauth_applications
end end
def allowed_protocols_present? def allowed_protocols_present?
current_application_settings.enabled_git_access_protocol.present? Gitlab::CurrentSettings.enabled_git_access_protocol.present?
end end
def enabled_protocol def enabled_protocol
case current_application_settings.enabled_git_access_protocol case Gitlab::CurrentSettings.enabled_git_access_protocol
when 'http' when 'http'
gitlab_config.protocol gitlab_config.protocol
when 'ssh' when 'ssh'
...@@ -57,7 +55,7 @@ def restricted_level_checkboxes(help_block_id, checkbox_name) ...@@ -57,7 +55,7 @@ def restricted_level_checkboxes(help_block_id, checkbox_name)
# toggle button effect. # toggle button effect.
def import_sources_checkboxes(help_block_id) def import_sources_checkboxes(help_block_id)
Gitlab::ImportSources.options.map do |name, source| Gitlab::ImportSources.options.map do |name, source|
checked = current_application_settings.import_sources.include?(source) checked = Gitlab::CurrentSettings.import_sources.include?(source)
css_class = checked ? 'active' : '' css_class = checked ? 'active' : ''
checkbox_name = 'application_setting[import_sources][]' checkbox_name = 'application_setting[import_sources][]'
...@@ -72,7 +70,7 @@ def import_sources_checkboxes(help_block_id) ...@@ -72,7 +70,7 @@ def import_sources_checkboxes(help_block_id)
def oauth_providers_checkboxes def oauth_providers_checkboxes
button_based_providers.map do |source| button_based_providers.map do |source|
disabled = current_application_settings.disabled_oauth_sign_in_sources.include?(source.to_s) disabled = Gitlab::CurrentSettings.disabled_oauth_sign_in_sources.include?(source.to_s)
css_class = 'btn' css_class = 'btn'
css_class << ' active' unless disabled css_class << ' active' unless disabled
checkbox_name = 'application_setting[enabled_oauth_sign_in_sources][]' checkbox_name = 'application_setting[enabled_oauth_sign_in_sources][]'
......
module AuthHelper module AuthHelper
include Gitlab::CurrentSettings
PROVIDERS_WITH_ICONS = %w(twitter github gitlab bitbucket google_oauth2 facebook azure_oauth2 authentiq).freeze PROVIDERS_WITH_ICONS = %w(twitter github gitlab bitbucket google_oauth2 facebook azure_oauth2 authentiq).freeze
FORM_BASED_PROVIDERS = [/\Aldap/, 'crowd'].freeze FORM_BASED_PROVIDERS = [/\Aldap/, 'crowd'].freeze
...@@ -41,7 +39,7 @@ def button_based_providers ...@@ -41,7 +39,7 @@ def button_based_providers
end end
def enabled_button_based_providers def enabled_button_based_providers
disabled_providers = current_application_settings.disabled_oauth_sign_in_sources || [] disabled_providers = Gitlab::CurrentSettings.disabled_oauth_sign_in_sources || []
button_based_providers.map(&:to_s) - disabled_providers button_based_providers.map(&:to_s) - disabled_providers
end end
......
module ProjectsHelper module ProjectsHelper
include Gitlab::CurrentSettings
def link_to_project(project) def link_to_project(project)
link_to [project.namespace.becomes(Namespace), project], title: h(project.name) do link_to [project.namespace.becomes(Namespace), project], title: h(project.name) do
title = content_tag(:span, project.name, class: 'project-name') title = content_tag(:span, project.name, class: 'project-name')
...@@ -214,7 +212,7 @@ def project_list_cache_key(project) ...@@ -214,7 +212,7 @@ def project_list_cache_key(project)
project.cache_key, project.cache_key,
controller.controller_name, controller.controller_name,
controller.action_name, controller.action_name,
current_application_settings.cache_key, Gitlab::CurrentSettings.cache_key,
'v2.5' 'v2.5'
] ]
...@@ -447,10 +445,10 @@ def koding_project_url(project = nil, branch = nil, sha = nil) ...@@ -447,10 +445,10 @@ def koding_project_url(project = nil, branch = nil, sha = nil)
path = "#{import_path}?repo=#{repo}&branch=#{branch}&sha=#{sha}" path = "#{import_path}?repo=#{repo}&branch=#{branch}&sha=#{sha}"
return URI.join(current_application_settings.koding_url, path).to_s return URI.join(Gitlab::CurrentSettings.koding_url, path).to_s
end end
current_application_settings.koding_url Gitlab::CurrentSettings.koding_url
end end
def contribution_guide_path(project) def contribution_guide_path(project)
...@@ -559,7 +557,7 @@ def visibility_select_options(project, selected_level) ...@@ -559,7 +557,7 @@ def visibility_select_options(project, selected_level)
def restricted_levels def restricted_levels
return [] if current_user.admin? return [] if current_user.admin?
current_application_settings.restricted_visibility_levels || [] Gitlab::CurrentSettings.restricted_visibility_levels || []
end end
def project_permissions_settings(project) def project_permissions_settings(project)
......
module VersionCheckHelper module VersionCheckHelper
def version_status_badge def version_status_badge
if Rails.env.production? && current_application_settings.version_check_enabled if Rails.env.production? && Gitlab::CurrentSettings.version_check_enabled
image_url = VersionCheck.new.url image_url = VersionCheck.new.url
image_tag image_url, class: 'js-version-status-badge' image_tag image_url, class: 'js-version-status-badge'
end end
......
...@@ -151,12 +151,12 @@ def visibility_level_label(level) ...@@ -151,12 +151,12 @@ def visibility_level_label(level)
def restricted_visibility_levels(show_all = false) def restricted_visibility_levels(show_all = false)
return [] if current_user.admin? && !show_all return [] if current_user.admin? && !show_all
current_application_settings.restricted_visibility_levels || [] Gitlab::CurrentSettings.restricted_visibility_levels || []
end end
delegate :default_project_visibility, delegate :default_project_visibility,
:default_group_visibility, :default_group_visibility,
to: :current_application_settings to: :'Gitlab::CurrentSettings.current_application_settings'
def disallowed_visibility_level?(form_model, level) def disallowed_visibility_level?(form_model, level)
return false unless form_model.respond_to?(:visibility_level_allowed?) return false unless form_model.respond_to?(:visibility_level_allowed?)
......
class AbuseReportMailer < BaseMailer class AbuseReportMailer < BaseMailer
include Gitlab::CurrentSettings
def notify(abuse_report_id) def notify(abuse_report_id)
return unless deliverable? return unless deliverable?
@abuse_report = AbuseReport.find(abuse_report_id) @abuse_report = AbuseReport.find(abuse_report_id)
mail( mail(
to: current_application_settings.admin_notification_email, to: Gitlab::CurrentSettings.admin_notification_email,
subject: "#{@abuse_report.user.name} (#{@abuse_report.user.username}) was reported for abuse" subject: "#{@abuse_report.user.name} (#{@abuse_report.user.username}) was reported for abuse"
) )
end end
...@@ -15,6 +13,6 @@ def notify(abuse_report_id) ...@@ -15,6 +13,6 @@ def notify(abuse_report_id)
private private
def deliverable? def deliverable?
current_application_settings.admin_notification_email.present? Gitlab::CurrentSettings.admin_notification_email.present?
end end
end end
class BaseMailer < ActionMailer::Base class BaseMailer < ActionMailer::Base
include Gitlab::CurrentSettings
around_action :render_with_default_locale around_action :render_with_default_locale
helper ApplicationHelper helper ApplicationHelper
helper MarkupHelper helper MarkupHelper
attr_accessor :current_user attr_accessor :current_user
helper_method :current_user, :can?, :current_application_settings helper_method :current_user, :can?
default from: proc { default_sender_address.format } default from: proc { default_sender_address.format }
default reply_to: proc { default_reply_to_address.format } default reply_to: proc { default_reply_to_address.format }
......
module Clusters module Clusters
module Platforms module Platforms
class Kubernetes < ActiveRecord::Base class Kubernetes < ActiveRecord::Base
include Gitlab::CurrentSettings
include Gitlab::Kubernetes include Gitlab::Kubernetes
include ReactiveCaching include ReactiveCaching
...@@ -169,7 +168,7 @@ def terminal_auth ...@@ -169,7 +168,7 @@ def terminal_auth
{ {
token: token, token: token,