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
require 'digest/md5'
class Key < ActiveRecord::Base
include Gitlab::CurrentSettings
include AfterCommitQueue
include Sortable
......@@ -104,7 +103,7 @@ def generate_fingerprint
end
def key_meets_restrictions
restriction = current_application_settings.key_restriction_for(public_key.type)
restriction = Gitlab::CurrentSettings.key_restriction_for(public_key.type)
if restriction == ApplicationSetting::FORBIDDEN_KEY_VALUE
errors.add(:key, forbidden_key_type_message)
......@@ -115,7 +114,7 @@ def key_meets_restrictions
def forbidden_key_type_message
allowed_types =
current_application_settings
Gitlab::CurrentSettings
.allowed_key_types
.map(&:upcase)
.to_sentence(last_word_connector: ', or ', two_words_connector: ' or ')
......
......@@ -2,7 +2,6 @@ class Namespace < ActiveRecord::Base
include CacheMarkdownField
include Sortable
include Gitlab::ShellAdapter
include Gitlab::CurrentSettings
include Gitlab::VisibilityLevel
include Routable
include AfterCommitQueue
......
......@@ -3,7 +3,6 @@
# A note of this type is never resolvable.
class Note < ActiveRecord::Base
extend ActiveModel::Naming
include Gitlab::CurrentSettings
include Participable
include Mentionable
include Awardable
......@@ -196,7 +195,7 @@ def active?
end
def max_attachment_size
current_application_settings.max_attachment_size.megabytes.to_i
Gitlab::CurrentSettings.max_attachment_size.megabytes.to_i
end
def hook_attrs
......
......@@ -4,7 +4,6 @@ class Project < ActiveRecord::Base
include Gitlab::ConfigHelper
include Gitlab::ShellAdapter
include Gitlab::VisibilityLevel
include Gitlab::CurrentSettings
include AccessRequestable
include Avatarable
include CacheMarkdownField
......@@ -23,7 +22,6 @@ class Project < ActiveRecord::Base
include ::Gitlab::Utils::StrongMemoize
extend Gitlab::ConfigHelper
extend Gitlab::CurrentSettings
BoardLimitExceeded = Class.new(StandardError)
......@@ -51,8 +49,8 @@ class Project < ActiveRecord::Base
default_value_for :visibility_level, gitlab_config_features.visibility_level
default_value_for :resolve_outdated_diff_discussions, false
default_value_for :container_registry_enabled, gitlab_config_features.container_registry
default_value_for(:repository_storage) { current_application_settings.pick_repository_storage }
default_value_for(:shared_runners_enabled) { current_application_settings.shared_runners_enabled }
default_value_for(:repository_storage) { Gitlab::CurrentSettings.pick_repository_storage }
default_value_for(:shared_runners_enabled) { Gitlab::CurrentSettings.shared_runners_enabled }
default_value_for :issues_enabled, gitlab_config_features.issues
default_value_for :merge_requests_enabled, gitlab_config_features.merge_requests
default_value_for :builds_enabled, gitlab_config_features.builds
......@@ -486,14 +484,14 @@ def lfs_enabled?
def auto_devops_enabled?
if auto_devops&.enabled.nil?
current_application_settings.auto_devops_enabled?
Gitlab::CurrentSettings.auto_devops_enabled?
else
auto_devops.enabled?
end
end
def has_auto_devops_implicitly_disabled?
auto_devops&.enabled.nil? && !current_application_settings.auto_devops_enabled?
auto_devops&.enabled.nil? && !Gitlab::CurrentSettings.auto_devops_enabled?
end
def empty_repo?
......@@ -1471,14 +1469,14 @@ def after_create_default_branch
# Ensure HEAD points to the default branch in case it is not master
change_head(default_branch)
if current_application_settings.default_branch_protection != Gitlab::Access::PROTECTION_NONE && !ProtectedBranch.protected?(self, default_branch)
if Gitlab::CurrentSettings.default_branch_protection != Gitlab::Access::PROTECTION_NONE && !ProtectedBranch.protected?(self, default_branch)
params = {
name: default_branch,
push_access_levels_attributes: [{
access_level: current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_PUSH ? Gitlab::Access::DEVELOPER : Gitlab::Access::MASTER
access_level: Gitlab::CurrentSettings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_PUSH ? Gitlab::Access::DEVELOPER : Gitlab::Access::MASTER
}],
merge_access_levels_attributes: [{
access_level: current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE ? Gitlab::Access::DEVELOPER : Gitlab::Access::MASTER
access_level: Gitlab::CurrentSettings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE ? Gitlab::Access::DEVELOPER : Gitlab::Access::MASTER
}]
}
......@@ -1773,7 +1771,7 @@ def storage
end
def use_hashed_storage
if self.new_record? && current_application_settings.hashed_storage_enabled
if self.new_record? && Gitlab::CurrentSettings.hashed_storage_enabled
self.storage_version = LATEST_STORAGE_VERSION
end
end
......
......@@ -4,7 +4,6 @@
# After we've migrated data, we'll remove KubernetesService. This would happen in a few months.
# If you're modyfiyng this class, please note that you should update the same change in Clusters::Platforms::Kubernetes.
class KubernetesService < DeploymentService
include Gitlab::CurrentSettings
include Gitlab::Kubernetes
include ReactiveCaching
......@@ -231,7 +230,7 @@ def terminal_auth
{
token: token,
ca_pem: ca_pem,
max_session_time: current_application_settings.terminal_max_session_time
max_session_time: Gitlab::CurrentSettings.terminal_max_session_time
}
end
......
......@@ -2,8 +2,6 @@ class ProtectedBranch < ActiveRecord::Base
include Gitlab::ShellAdapter
include ProtectedRef
extend Gitlab::CurrentSettings
protected_ref_access_levels :merge, :push
# Check if branch name is marked as protected in the system
......@@ -16,7 +14,7 @@ def self.protected?(project, ref_name)
end
def self.default_branch_protected?
current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_FULL ||
current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE
Gitlab::CurrentSettings.default_branch_protection == Gitlab::Access::PROTECTION_FULL ||
Gitlab::CurrentSettings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE
end
end
......@@ -11,8 +11,6 @@ class Snippet < ActiveRecord::Base
include Editable
include Gitlab::SQL::Pattern
extend Gitlab::CurrentSettings
cache_markdown_field :title, pipeline: :single_line
cache_markdown_field :description
cache_markdown_field :content
......@@ -28,7 +26,7 @@ def content_html_invalidated?
default_content_html_invalidator || file_name_changed?
end
default_value_for(:visibility_level) { current_application_settings.default_snippet_visibility }
default_value_for(:visibility_level) { Gitlab::CurrentSettings.default_snippet_visibility }
belongs_to :author, class_name: 'User'
belongs_to :project
......
......@@ -2,10 +2,8 @@
class User < ActiveRecord::Base
extend Gitlab::ConfigHelper
extend Gitlab::CurrentSettings
include Gitlab::ConfigHelper
include Gitlab::CurrentSettings
include Gitlab::SQL::Pattern
include AfterCommitQueue
include Avatarable
......@@ -30,7 +28,7 @@ class User < ActiveRecord::Base
add_authentication_token_field :rss_token
default_value_for :admin, false
default_value_for(:external) { current_application_settings.user_default_external }
default_value_for(:external) { Gitlab::CurrentSettings.user_default_external }
default_value_for :can_create_group, gitlab_config.default_can_create_group
default_value_for :can_create_team, false
default_value_for :hide_no_ssh_key, false
......@@ -660,11 +658,11 @@ def allow_password_authentication?
end
def allow_password_authentication_for_web?
current_application_settings.password_authentication_enabled_for_web? && !ldap_user?
Gitlab::CurrentSettings.password_authentication_enabled_for_web? && !ldap_user?
end
def allow_password_authentication_for_git?
current_application_settings.password_authentication_enabled_for_git? && !ldap_user?
Gitlab::CurrentSettings.password_authentication_enabled_for_git? && !ldap_user?
end
def can_change_username?
......@@ -792,7 +790,7 @@ def set_projects_limit
# without this safeguard!
return unless has_attribute?(:projects_limit) && projects_limit.nil?
self.projects_limit = current_application_settings.default_projects_limit
self.projects_limit = Gitlab::CurrentSettings.default_projects_limit
end
def requires_ldap_check?
......@@ -1215,7 +1213,7 @@ def ensure_user_rights_and_limits
else
# Only revert these back to the default if they weren't specifically changed in this update.
self.can_create_group = gitlab_config.default_can_create_group unless can_create_group_changed?
self.projects_limit = current_application_settings.default_projects_limit unless projects_limit_changed?
self.projects_limit = Gitlab::CurrentSettings.default_projects_limit unless projects_limit_changed?
end
end
......@@ -1223,15 +1221,15 @@ def signup_domain_valid?
valid = true
error = nil
if current_application_settings.domain_blacklist_enabled?
blocked_domains = current_application_settings.domain_blacklist
if Gitlab::CurrentSettings.domain_blacklist_enabled?
blocked_domains = Gitlab::CurrentSettings.domain_blacklist
if domain_matches?(blocked_domains, email)
error = 'is not from an allowed domain.'
valid = false
end
end
allowed_domains = current_application_settings.domain_whitelist
allowed_domains = Gitlab::CurrentSettings.domain_whitelist
unless allowed_domains.blank?
if domain_matches?(allowed_domains, email)
valid = true
......
class AkismetService
include Gitlab::CurrentSettings
attr_accessor :owner, :text, :options
def initialize(owner, text, options = {})
......@@ -41,12 +39,12 @@ def submit_spam
private
def akismet_client
@akismet_client ||= ::Akismet::Client.new(current_application_settings.akismet_api_key,
@akismet_client ||= ::Akismet::Client.new(Gitlab::CurrentSettings.akismet_api_key,
Gitlab.config.gitlab.url)
end
def akismet_enabled?
current_application_settings.akismet_enabled
Gitlab::CurrentSettings.akismet_enabled
end
def submit(type)
......
module Auth
class ContainerRegistryAuthenticationService < BaseService
extend Gitlab::CurrentSettings
AUDIENCE = 'container_registry'.freeze
def execute(authentication_abilities:)
......@@ -32,7 +30,7 @@ def self.full_access_token(*names)
end
def self.token_expire_at
Time.now + current_application_settings.container_registry_token_expire_delay.minutes
Time.now + Gitlab::CurrentSettings.container_registry_token_expire_delay.minutes
end
private
......
class BaseService
include Gitlab::Allowable
include Gitlab::CurrentSettings
attr_accessor :project, :current_user, :params
......
......@@ -2,8 +2,6 @@ module Ci
# This class responsible for assigning
# proper pending build to runner on runner API request
class RegisterJobService
include Gitlab::CurrentSettings
attr_reader :runner
Result = Struct.new(:build, :valid?)
......
class GitPushService < BaseService
attr_accessor :push_data, :push_commits
include Gitlab::CurrentSettings
include Gitlab::Access
# The N most recent commits to process in a single push payload.
......
class GravatarService
include Gitlab::CurrentSettings
def execute(email, size = nil, scale = 2, username: nil)
return unless current_application_settings.gravatar_enabled?
return unless Gitlab::CurrentSettings.gravatar_enabled?
identifier = email.presence || username.presence
return unless identifier
......
......@@ -7,8 +7,6 @@
#
module Projects
class HousekeepingService < BaseService
include Gitlab::CurrentSettings
# Timeout set to 24h
LEASE_TIMEOUT = 86400
......@@ -83,19 +81,19 @@ def period_match?
end
def housekeeping_enabled?
current_application_settings.housekeeping_enabled
Gitlab::CurrentSettings.housekeeping_enabled
end
def gc_period
current_application_settings.housekeeping_gc_period
Gitlab::CurrentSettings.housekeeping_gc_period
end
def full_repack_period
current_application_settings.housekeeping_full_repack_period
Gitlab::CurrentSettings.housekeeping_full_repack_period
end
def repack_period
current_application_settings.housekeeping_incremental_repack_period
Gitlab::CurrentSettings.housekeeping_incremental_repack_period
end
end
end
module Projects
class UpdatePagesService < BaseService
include Gitlab::CurrentSettings
BLOCK_SIZE = 32.kilobytes
MAX_SIZE = 1.terabyte
SITE_PATH = 'public/'.freeze
......@@ -134,7 +132,7 @@ def blocks
end
def max_size
max_pages_size = current_application_settings.max_pages_size.megabytes
max_pages_size = Gitlab::CurrentSettings.max_pages_size.megabytes
return MAX_SIZE if max_pages_size.zero?
......
......@@ -34,7 +34,7 @@ def execute
def run_auto_devops_pipeline?
return false if project.repository.gitlab_ci_yml || !project.auto_devops.previous_changes.include?('enabled')
project.auto_devops.enabled? || (project.auto_devops.enabled.nil? && current_application_settings.auto_devops_enabled?)
project.auto_devops.enabled? || (project.auto_devops.enabled.nil? && Gitlab::CurrentSettings.auto_devops_enabled?)
end
private
......
......@@ -11,10 +11,8 @@ class SubmitUsagePingService
percentage_projects_prometheus_active leader_service_desk_issues instance_service_desk_issues
percentage_service_desk_issues].freeze
include Gitlab::CurrentSettings
def execute
return false unless current_application_settings.usage_ping_enabled?
return false unless Gitlab::CurrentSettings.usage_ping_enabled?
response = HTTParty.post(
URL,
......
class UploadService
include Gitlab::CurrentSettings
def initialize(model, file, uploader_class = FileUploader)
@model, @file, @uploader_class = model, file, uploader_class
end
......@@ -17,6 +15,6 @@ def execute
private
def max_attachment_size
current_application_settings.max_attachment_size.megabytes.to_i
Gitlab::CurrentSettings.max_attachment_size.megabytes.to_i
end
end
module Users
class BuildService < BaseService
include Gitlab::CurrentSettings
def initialize(current_user, params = {})
@current_user = current_user
@params = params.dup
......@@ -34,7 +32,7 @@ def execute(skip_authorization: false)
private
def can_create_user?
(current_user.nil? && current_application_settings.allow_signup?) || current_user&.admin?
(current_user.nil? && Gitlab::CurrentSettings.allow_signup?) || current_user&.admin?
end
# Allowed params for creating a user (admins only)
......@@ -102,7 +100,7 @@ def build_user_params(skip_authorization:)
end
def skip_user_confirmation_email_from_setting
!current_application_settings.send_user_confirmation_email
!Gitlab::CurrentSettings.send_user_confirmation_email
end
end
end
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