2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
class Namespace < ApplicationRecord
|
2016-11-03 12:29:30 +05:30
|
|
|
include CacheMarkdownField
|
2015-04-26 12:48:37 +05:30
|
|
|
include Sortable
|
2017-09-10 17:25:29 +05:30
|
|
|
include Gitlab::VisibilityLevel
|
2017-08-17 22:00:37 +05:30
|
|
|
include Routable
|
2017-09-10 17:25:29 +05:30
|
|
|
include AfterCommitQueue
|
|
|
|
include Storage::LegacyNamespace
|
2018-03-17 18:26:18 +05:30
|
|
|
include Gitlab::SQL::Pattern
|
2018-11-20 20:47:30 +05:30
|
|
|
include FeatureGate
|
2018-12-05 23:21:45 +05:30
|
|
|
include FromUnion
|
2019-07-07 11:18:12 +05:30
|
|
|
include Gitlab::Utils::StrongMemoize
|
2020-04-22 19:07:51 +05:30
|
|
|
include IgnorableColumns
|
2021-03-11 19:13:27 +05:30
|
|
|
include Namespaces::Traversal::Recursive
|
2021-04-29 21:17:54 +05:30
|
|
|
include Namespaces::Traversal::Linear
|
2021-06-08 01:23:25 +05:30
|
|
|
include EachBatch
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
ignore_column :delayed_project_removal, remove_with: '14.1', remove_after: '2021-05-22'
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
# Prevent users from creating unreasonably deep level of nesting.
|
|
|
|
# The number 20 was taken based on maximum nesting level of
|
|
|
|
# Android repo (15) + some extra backup.
|
|
|
|
NUMBER_OF_ANCESTORS_ALLOWED = 20
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
SHARED_RUNNERS_SETTINGS = %w[disabled_and_unoverridable disabled_with_override enabled].freeze
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
cache_markdown_field :description, pipeline: :description
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
has_many :projects, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
2017-08-17 22:00:37 +05:30
|
|
|
has_many :project_statistics
|
2020-07-28 23:09:34 +05:30
|
|
|
has_one :namespace_settings, inverse_of: :namespace, class_name: 'NamespaceSetting', autosave: true
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
has_many :runner_namespaces, inverse_of: :namespace, class_name: 'Ci::RunnerNamespace'
|
2018-10-15 14:42:47 +05:30
|
|
|
has_many :runners, through: :runner_namespaces, source: :runner, class_name: 'Ci::Runner'
|
2021-03-08 18:12:59 +05:30
|
|
|
has_one :onboarding_progress
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
# This should _not_ be `inverse_of: :namespace`, because that would also set
|
|
|
|
# `user.namespace` when this user creates a group with themselves as `owner`.
|
2014-09-02 18:07:02 +05:30
|
|
|
belongs_to :owner, class_name: "User"
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
belongs_to :parent, class_name: "Namespace"
|
|
|
|
has_many :children, class_name: "Namespace", foreign_key: :parent_id
|
2020-07-28 23:09:34 +05:30
|
|
|
has_many :custom_emoji, inverse_of: :namespace
|
2017-09-10 17:25:29 +05:30
|
|
|
has_one :chat_team, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
2019-09-30 21:07:59 +05:30
|
|
|
has_one :root_storage_statistics, class_name: 'Namespace::RootStorageStatistics'
|
|
|
|
has_one :aggregation_schedule, class_name: 'Namespace::AggregationSchedule'
|
2021-03-08 18:12:59 +05:30
|
|
|
has_one :package_setting_relation, inverse_of: :namespace, class_name: 'PackageSetting'
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
has_one :admin_note, inverse_of: :namespace
|
|
|
|
accepts_nested_attributes_for :admin_note, update_only: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
validates :owner, presence: true, unless: ->(n) { n.type == "Group" }
|
2015-04-26 12:48:37 +05:30
|
|
|
validates :name,
|
2015-12-23 02:04:40 +05:30
|
|
|
presence: true,
|
2019-09-30 21:07:59 +05:30
|
|
|
length: { maximum: 255 }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
validates :description, length: { maximum: 255 }
|
2015-04-26 12:48:37 +05:30
|
|
|
validates :path,
|
2015-12-23 02:04:40 +05:30
|
|
|
presence: true,
|
2017-08-17 22:00:37 +05:30
|
|
|
length: { maximum: 255 },
|
2018-03-17 18:26:18 +05:30
|
|
|
namespace_path: true
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
# Introduce minimal path length of 2 characters.
|
|
|
|
# Allow change of other attributes without forcing users to
|
|
|
|
# rename their user or group. At the same time prevent changing
|
|
|
|
# the path without complying with new 2 chars requirement.
|
|
|
|
# Issue https://gitlab.com/gitlab-org/gitlab/-/issues/225214
|
|
|
|
validates :path, length: { minimum: 2 }, if: :path_changed?
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
validates :max_artifacts_size, numericality: { only_integer: true, greater_than: 0, allow_nil: true }
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
validate :validate_parent_type, if: -> { Feature.enabled?(:validate_namespace_parent_type) }
|
2017-08-17 22:00:37 +05:30
|
|
|
validate :nesting_level_allowed
|
2021-01-03 14:25:43 +05:30
|
|
|
validate :changing_shared_runners_enabled_is_allowed
|
|
|
|
validate :changing_allow_descendants_override_disabled_shared_runners_is_allowed
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
delegate :name, to: :owner, allow_nil: true, prefix: true
|
2019-07-31 22:56:46 +05:30
|
|
|
delegate :avatar_url, to: :owner, allow_nil: true
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
after_commit :refresh_access_of_projects_invited_groups, on: :update, if: -> { previous_changes.key?('share_with_group_lock') }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
before_create :sync_share_with_group_lock_with_parent
|
|
|
|
before_update :sync_share_with_group_lock_with_parent, if: :parent_changed?
|
2019-07-31 22:56:46 +05:30
|
|
|
after_update :force_share_with_group_lock_on_descendants, if: -> { saved_change_to_share_with_group_lock? && share_with_group_lock? }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
# Legacy Storage specific hooks
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
after_update :move_dir, if: :saved_change_to_path_or_parent?
|
2017-08-17 22:00:37 +05:30
|
|
|
before_destroy(prepend: true) { prepare_for_destroy }
|
2014-09-02 18:07:02 +05:30
|
|
|
after_destroy :rm_dir
|
2021-06-08 01:23:25 +05:30
|
|
|
after_commit :expire_child_caches, on: :update, if: -> {
|
|
|
|
Feature.enabled?(:cached_route_lookups, self, type: :ops, default_enabled: :yaml) &&
|
|
|
|
saved_change_to_name? || saved_change_to_path? || saved_change_to_parent_id?
|
|
|
|
}
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
scope :for_user, -> { where(type: nil) }
|
2020-04-08 14:13:33 +05:30
|
|
|
scope :sort_by_type, -> { order(Gitlab::Database.nulls_first_order(:type)) }
|
2021-01-03 14:25:43 +05:30
|
|
|
scope :include_route, -> { includes(:route) }
|
2021-04-29 21:17:54 +05:30
|
|
|
scope :by_parent, -> (parent) { where(parent_id: parent) }
|
|
|
|
scope :filter_by_path, -> (query) { where('lower(path) = :query', query: query.downcase) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
scope :with_statistics, -> do
|
|
|
|
joins('LEFT JOIN project_statistics ps ON ps.namespace_id = namespaces.id')
|
|
|
|
.group('namespaces.id')
|
|
|
|
.select(
|
|
|
|
'namespaces.*',
|
|
|
|
'COALESCE(SUM(ps.storage_size), 0) AS storage_size',
|
|
|
|
'COALESCE(SUM(ps.repository_size), 0) AS repository_size',
|
2019-09-04 21:01:54 +05:30
|
|
|
'COALESCE(SUM(ps.wiki_size), 0) AS wiki_size',
|
2020-07-28 23:09:34 +05:30
|
|
|
'COALESCE(SUM(ps.snippets_size), 0) AS snippets_size',
|
2017-08-17 22:00:37 +05:30
|
|
|
'COALESCE(SUM(ps.lfs_objects_size), 0) AS lfs_objects_size',
|
2019-07-31 22:56:46 +05:30
|
|
|
'COALESCE(SUM(ps.build_artifacts_size), 0) AS build_artifacts_size',
|
2021-01-29 00:20:46 +05:30
|
|
|
'COALESCE(SUM(ps.packages_size), 0) AS packages_size',
|
|
|
|
'COALESCE(SUM(ps.uploads_size), 0) AS uploads_size'
|
2017-08-17 22:00:37 +05:30
|
|
|
)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
scope :sorted_by_similarity_and_parent_id_desc, -> (search) do
|
|
|
|
order_expression = Gitlab::Database::SimilarityScore.build_expression(search: search, rules: [
|
|
|
|
{ column: arel_table["path"], multiplier: 1 },
|
|
|
|
{ column: arel_table["name"], multiplier: 0.7 }
|
|
|
|
])
|
|
|
|
reorder(order_expression.desc, Namespace.arel_table['parent_id'].desc.nulls_last, Namespace.arel_table['id'].desc)
|
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
# Make sure that the name is same as strong_memoize name in root_ancestor
|
|
|
|
# method
|
2021-04-29 21:17:54 +05:30
|
|
|
attr_writer :root_ancestor, :emails_disabled_memoized
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
class << self
|
|
|
|
def by_path(path)
|
2015-12-23 02:04:40 +05:30
|
|
|
find_by('lower(path) = :value', value: path.downcase)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
# Case insensitive search for namespace by path or name
|
2015-04-26 12:48:37 +05:30
|
|
|
def find_by_path_or_name(path)
|
|
|
|
find_by("lower(path) = :path OR lower(name) = :path", path: path.downcase)
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
# Searches for namespaces matching the given query.
|
|
|
|
#
|
2020-06-23 00:09:42 +05:30
|
|
|
# This method uses ILIKE on PostgreSQL.
|
2016-06-02 11:05:42 +05:30
|
|
|
#
|
2020-06-23 00:09:42 +05:30
|
|
|
# query - The search query as a String.
|
2016-06-02 11:05:42 +05:30
|
|
|
#
|
2020-06-23 00:09:42 +05:30
|
|
|
# Returns an ActiveRecord::Relation.
|
2021-01-29 00:20:46 +05:30
|
|
|
def search(query, include_parents: false)
|
|
|
|
if include_parents
|
|
|
|
where(id: Route.for_routable_type(Namespace.name).fuzzy_search(query, [Route.arel_table[:path], Route.arel_table[:name]]).select(:source_id))
|
|
|
|
else
|
|
|
|
fuzzy_search(query, [:path, :name])
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def clean_path(path)
|
|
|
|
path = path.dup
|
2015-09-11 14:41:01 +05:30
|
|
|
# Get the email username by removing everything after an `@` sign.
|
2016-11-03 12:29:30 +05:30
|
|
|
path.gsub!(/@.*\z/, "")
|
2015-09-11 14:41:01 +05:30
|
|
|
# Remove everything that's not in the list of allowed characters.
|
2016-11-03 12:29:30 +05:30
|
|
|
path.gsub!(/[^a-zA-Z0-9_\-\.]/, "")
|
|
|
|
# Remove trailing violations ('.atom', '.git', or '.')
|
|
|
|
path.gsub!(/(\.atom|\.git|\.)*\z/, "")
|
|
|
|
# Remove leading violations ('-')
|
|
|
|
path.gsub!(/\A\-+/, "")
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
# 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?
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
uniquify = Uniquify.new
|
|
|
|
uniquify.string(path) { |s| Namespace.find_by_path_or_name(s) }
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
def clean_name(value)
|
|
|
|
value.scan(Gitlab::Regex.group_name_regex_chars).join(' ')
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def find_by_pages_host(host)
|
|
|
|
gitlab_host = "." + Settings.pages.host.downcase
|
2020-01-01 13:55:28 +05:30
|
|
|
host = host.downcase
|
|
|
|
return unless host.ends_with?(gitlab_host)
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
name = host.delete_suffix(gitlab_host)
|
2020-04-22 19:07:51 +05:30
|
|
|
Namespace.where(parent_id: nil).by_path(name)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
def top_most
|
|
|
|
where(parent_id: nil)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
def package_settings
|
|
|
|
package_setting_relation || build_package_setting_relation
|
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
def default_branch_protection
|
|
|
|
super || Gitlab::CurrentSettings.default_branch_protection
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def visibility_level_field
|
|
|
|
:visibility_level
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def to_param
|
2017-08-17 22:00:37 +05:30
|
|
|
full_path
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def human_name
|
|
|
|
owner_name
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def any_project_has_container_registry_tags?
|
2021-06-08 01:23:25 +05:30
|
|
|
all_projects.includes(:container_repositories).any?(&:has_container_registry_tags?)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
def first_project_with_container_registry_tags
|
|
|
|
all_projects.find(&:has_container_registry_tags?)
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def send_update_instructions
|
2015-10-24 18:46:33 +05:30
|
|
|
projects.each do |project|
|
2019-07-31 22:56:46 +05:30
|
|
|
project.send_move_instructions("#{full_path_before_last_save}/#{project.path}")
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def kind
|
|
|
|
type == 'Group' ? 'group' : 'user'
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
def user?
|
|
|
|
kind == 'user'
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def group?
|
|
|
|
type == 'Group'
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def find_fork_of(project)
|
2019-07-07 11:18:12 +05:30
|
|
|
return unless project.fork_network
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
if Gitlab::SafeRequestStore.active?
|
|
|
|
forks_in_namespace = Gitlab::SafeRequestStore.fetch("namespaces:#{id}:forked_projects") do
|
2018-03-17 18:26:18 +05:30
|
|
|
Hash.new do |found_forks, project|
|
|
|
|
found_forks[project] = project.fork_network.find_forks_in(projects).first
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
forks_in_namespace[project]
|
|
|
|
else
|
|
|
|
project.fork_network.find_forks_in(projects).first
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
# any ancestor can disable emails for all descendants
|
|
|
|
def emails_disabled?
|
2021-04-29 21:17:54 +05:30
|
|
|
strong_memoize(:emails_disabled_memoized) do
|
2020-03-13 15:44:24 +05:30
|
|
|
if parent_id
|
|
|
|
self_and_ancestors.where(emails_disabled: true).exists?
|
|
|
|
else
|
|
|
|
!!emails_disabled
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
def lfs_enabled?
|
|
|
|
# User namespace will always default to the global setting
|
|
|
|
Gitlab.config.lfs.enabled
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def any_project_with_shared_runners_enabled?
|
2017-08-17 22:00:37 +05:30
|
|
|
projects.with_shared_runners.any?
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_ids_for_project_authorizations
|
|
|
|
[owner_id]
|
|
|
|
end
|
|
|
|
|
|
|
|
# Includes projects from this namespace and projects from all subgroups
|
|
|
|
# that belongs to this namespace
|
|
|
|
def all_projects
|
2021-07-08 21:50:14 +05:30
|
|
|
if Feature.enabled?(:recursive_approach_for_all_projects, default_enabled: :yaml)
|
2021-09-30 23:02:18 +05:30
|
|
|
namespace = user? ? self : self_and_descendant_ids
|
2021-07-08 21:50:14 +05:30
|
|
|
Project.where(namespace: namespace)
|
|
|
|
else
|
|
|
|
Project.inside_path(full_path)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def has_parent?
|
2020-06-23 00:09:42 +05:30
|
|
|
parent_id.present? || parent.present?
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def subgroup?
|
|
|
|
has_parent?
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
# Overridden on EE module
|
|
|
|
def multiple_issue_boards_available?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
# Deprecated, use #licensed_feature_available? instead. Remove once Namespace#feature_available? isn't used anymore.
|
|
|
|
def feature_available?(feature)
|
|
|
|
licensed_feature_available?(feature)
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
# Overridden in EE::Namespace
|
2021-04-29 21:17:54 +05:30
|
|
|
def licensed_feature_available?(_feature)
|
2019-09-30 21:07:59 +05:30
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
def full_path_before_last_save
|
|
|
|
if parent_id_before_last_save.nil?
|
|
|
|
path_before_last_save
|
2018-03-17 18:26:18 +05:30
|
|
|
else
|
2019-07-31 22:56:46 +05:30
|
|
|
previous_parent = Group.find_by(id: parent_id_before_last_save)
|
|
|
|
previous_parent.full_path + '/' + path_before_last_save
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
def refresh_project_authorizations
|
|
|
|
owner.refresh_authorized_projects
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
def auto_devops_enabled?
|
|
|
|
first_auto_devops_config[:status]
|
|
|
|
end
|
|
|
|
|
|
|
|
def first_auto_devops_config
|
|
|
|
return { scope: :group, status: auto_devops_enabled } unless auto_devops_enabled.nil?
|
|
|
|
|
|
|
|
strong_memoize(:first_auto_devops_config) do
|
|
|
|
if has_parent?
|
|
|
|
parent.first_auto_devops_config
|
|
|
|
else
|
|
|
|
{ scope: :instance, status: Gitlab::CurrentSettings.auto_devops_enabled? }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
def aggregation_scheduled?
|
|
|
|
aggregation_schedule.present?
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def pages_virtual_domain
|
2020-04-08 14:13:33 +05:30
|
|
|
Pages::VirtualDomain.new(
|
2021-01-29 00:20:46 +05:30
|
|
|
all_projects_with_pages.includes(:route, :project_feature, pages_metadatum: :pages_deployment),
|
2020-04-08 14:13:33 +05:30
|
|
|
trim_prefix: full_path
|
|
|
|
)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
def any_project_with_pages_deployed?
|
|
|
|
all_projects.with_pages_deployed.any?
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def closest_setting(name)
|
|
|
|
self_and_ancestors(hierarchy_order: :asc)
|
|
|
|
.find { |n| !n.read_attribute(name).nil? }
|
|
|
|
.try(name)
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def actual_plan
|
|
|
|
Plan.default
|
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
def paid?
|
|
|
|
root? && actual_plan.paid?
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def actual_limits
|
|
|
|
# We default to PlanLimits.new otherwise a lot of specs would fail
|
|
|
|
# On production each plan should already have associated limits record
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab/issues/36037
|
|
|
|
actual_plan.actual_limits
|
|
|
|
end
|
|
|
|
|
|
|
|
def actual_plan_name
|
|
|
|
actual_plan.name
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def changing_shared_runners_enabled_is_allowed
|
|
|
|
return unless new_record? || changes.has_key?(:shared_runners_enabled)
|
|
|
|
|
|
|
|
if shared_runners_enabled && has_parent? && parent.shared_runners_setting == 'disabled_and_unoverridable'
|
|
|
|
errors.add(:shared_runners_enabled, _('cannot be enabled because parent group has shared Runners disabled'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def changing_allow_descendants_override_disabled_shared_runners_is_allowed
|
|
|
|
return unless new_record? || changes.has_key?(:allow_descendants_override_disabled_shared_runners)
|
|
|
|
|
|
|
|
if shared_runners_enabled && !new_record?
|
|
|
|
errors.add(:allow_descendants_override_disabled_shared_runners, _('cannot be changed if shared runners are enabled'))
|
|
|
|
end
|
|
|
|
|
|
|
|
if allow_descendants_override_disabled_shared_runners && has_parent? && parent.shared_runners_setting == 'disabled_and_unoverridable'
|
|
|
|
errors.add(:allow_descendants_override_disabled_shared_runners, _('cannot be enabled because parent group does not allow it'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def shared_runners_setting
|
|
|
|
if shared_runners_enabled
|
|
|
|
'enabled'
|
|
|
|
else
|
|
|
|
if allow_descendants_override_disabled_shared_runners
|
|
|
|
'disabled_with_override'
|
|
|
|
else
|
|
|
|
'disabled_and_unoverridable'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def shared_runners_setting_higher_than?(other_setting)
|
|
|
|
if other_setting == 'enabled'
|
|
|
|
false
|
|
|
|
elsif other_setting == 'disabled_with_override'
|
|
|
|
shared_runners_setting == 'enabled'
|
|
|
|
elsif other_setting == 'disabled_and_unoverridable'
|
|
|
|
shared_runners_setting == 'enabled' || shared_runners_setting == 'disabled_with_override'
|
|
|
|
else
|
|
|
|
raise ArgumentError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
def root?
|
|
|
|
!has_parent?
|
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
def recent?
|
|
|
|
created_at >= 90.days.ago
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def issue_repositioning_disabled?
|
|
|
|
Feature.enabled?(:block_issue_repositioning, self, type: :ops, default_enabled: :yaml)
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
private
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def expire_child_caches
|
|
|
|
Namespace.where(id: descendants).each_batch do |namespaces|
|
|
|
|
namespaces.touch_all
|
|
|
|
end
|
|
|
|
|
|
|
|
all_projects.each_batch do |projects|
|
|
|
|
projects.touch_all
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def all_projects_with_pages
|
|
|
|
all_projects.with_pages_deployed
|
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
def parent_changed?
|
|
|
|
parent_id_changed?
|
|
|
|
end
|
|
|
|
|
|
|
|
def saved_change_to_parent?
|
|
|
|
saved_change_to_parent_id?
|
|
|
|
end
|
|
|
|
|
|
|
|
def saved_change_to_path_or_parent?
|
|
|
|
saved_change_to_path? || saved_change_to_parent_id?
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def refresh_access_of_projects_invited_groups
|
2017-09-10 17:25:29 +05:30
|
|
|
Group
|
|
|
|
.joins(project_group_links: :project)
|
|
|
|
.where(projects: { namespace_id: id })
|
|
|
|
.find_each(&:refresh_members_authorized_projects)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def nesting_level_allowed
|
|
|
|
if ancestors.count > Group::NUMBER_OF_ANCESTORS_ALLOWED
|
2020-04-08 14:13:33 +05:30
|
|
|
errors.add(:parent_id, 'has too deep level of nesting')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
def validate_parent_type
|
|
|
|
return unless has_parent?
|
|
|
|
|
|
|
|
if user?
|
|
|
|
errors.add(:parent_id, 'a user namespace cannot have a parent')
|
|
|
|
elsif group?
|
|
|
|
errors.add(:parent_id, 'a group cannot have a user namespace as its parent') if parent.user?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def sync_share_with_group_lock_with_parent
|
|
|
|
if parent&.share_with_group_lock?
|
|
|
|
self.share_with_group_lock = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def force_share_with_group_lock_on_descendants
|
|
|
|
# We can't use `descendants.update_all` since Rails will throw away the WITH
|
|
|
|
# RECURSIVE statement. We also can't use WHERE EXISTS since we can't use
|
|
|
|
# different table aliases, hence we're just using WHERE IN. Since we have a
|
|
|
|
# maximum of 20 nested groups this should be fine.
|
|
|
|
Namespace.where(id: descendants.select(:id))
|
|
|
|
.update_all(share_with_group_lock: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def write_projects_repository_config
|
|
|
|
all_projects.find_each do |project|
|
|
|
|
project.write_repository_config
|
2019-02-15 15:39:39 +05:30
|
|
|
project.track_project_repository
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Namespace.prepend_mod_with('Namespace')
|