diff options
Diffstat (limited to 'app/models/namespace.rb')
-rw-r--r-- | app/models/namespace.rb | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb index cf638f9b16c..9d9b09e3562 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -35,8 +35,6 @@ class Namespace < ApplicationRecord SHARED_RUNNERS_SETTINGS = [SR_DISABLED_AND_UNOVERRIDABLE, SR_DISABLED_WITH_OVERRIDE, SR_DISABLED_AND_OVERRIDABLE, SR_ENABLED].freeze URL_MAX_LENGTH = 255 - PATH_TRAILING_VIOLATIONS = %w[.git .atom .].freeze - # This date is just a placeholder until namespace storage enforcement timeline is confirmed at which point # this should be replaced, see https://about.gitlab.com/pricing/faq-efficient-free-tier/#user-limits-on-gitlab-saas-free-tier MIN_STORAGE_ENFORCEMENT_DATE = 3.months.from_now.to_date @@ -85,6 +83,8 @@ class Namespace < ApplicationRecord has_many :timelog_categories, class_name: 'TimeTracking::TimelogCategory' has_many :achievements, class_name: 'Achievements::Achievement' has_many :namespace_commit_emails, class_name: 'Users::NamespaceCommitEmail' + has_many :cycle_analytics_stages, class_name: 'Analytics::CycleAnalytics::Stage', foreign_key: :group_id, inverse_of: :namespace + has_many :value_streams, class_name: 'Analytics::CycleAnalytics::ValueStream', foreign_key: :group_id, inverse_of: :namespace validates :owner, presence: true, if: ->(n) { n.owner_required? } validates :name, @@ -141,12 +141,14 @@ class Namespace < ApplicationRecord :npm_package_requests_forwarding, to: :package_settings + before_save :update_new_emails_created_column, if: -> { emails_disabled_changed? } before_create :sync_share_with_group_lock_with_parent before_update :sync_share_with_group_lock_with_parent, if: :parent_changed? after_update :force_share_with_group_lock_on_descendants, if: -> { saved_change_to_share_with_group_lock? && share_with_group_lock? } after_update :expire_first_auto_devops_config_cache, if: -> { saved_change_to_auto_devops_enabled? } after_update :move_dir, if: :saved_change_to_path_or_parent?, unless: -> { is_a?(Namespaces::ProjectNamespace) } after_destroy :rm_dir + after_save :reload_namespace_details after_commit :refresh_access_of_projects_invited_groups, on: :update, if: -> { previous_changes.key?('share_with_group_lock') } @@ -240,27 +242,9 @@ class Namespace < ApplicationRecord end def clean_path(path, limited_to: Namespace.all) - path = path.dup - # Get the email username by removing everything after an `@` sign. - path.gsub!(/@.*\z/, "") - # Remove everything that's not in the list of allowed characters. - path.gsub!(/[^a-zA-Z0-9_\-\.]/, "") - # Remove trailing violations ('.atom', '.git', or '.') - loop do - orig = path - PATH_TRAILING_VIOLATIONS.each { |ext| path = path.chomp(ext) } - break if orig == path - end - - # Remove leading violations ('-') - path.gsub!(/\A\-+/, "") - - # Users with the great usernames of "." or ".." would end up with a blank username. - # Work around that by setting their username to "blank", followed by a counter. - path = "blank" if path.blank? - - uniquify = Uniquify.new - uniquify.string(path) { |s| limited_to.find_by_path_or_name(s) } + slug = Gitlab::Slug::Path.new(path).generate + path = Namespaces::RandomizedSuffixPath.new(slug) + Uniquify.new.string(path) { |s| limited_to.find_by_path_or_name(s) } end def clean_name(value) @@ -617,6 +601,17 @@ class Namespace < ApplicationRecord private + def update_new_emails_created_column + return if namespace_settings.nil? + return if namespace_settings.emails_enabled == !emails_disabled + + if namespace_settings.persisted? + namespace_settings.update!(emails_enabled: !emails_disabled) + elsif namespace_settings + namespace_settings.emails_enabled = !emails_disabled + end + end + def cluster_enabled_granted? (Gitlab.com? || Gitlab.dev_or_test_env?) && root_ancestor.cluster_enabled_grant.present? end @@ -678,7 +673,6 @@ class Namespace < ApplicationRecord groups_requiring_authorizations_refresh.find_each do |group| group.refresh_members_authorized_projects( - blocking: false, priority: priority ) end |