diff options
Diffstat (limited to 'app/models/namespace.rb')
-rw-r--r-- | app/models/namespace.rb | 57 |
1 files changed, 5 insertions, 52 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 6f7b377ee52..3342fb1fce9 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -12,6 +12,7 @@ class Namespace < ApplicationRecord include FromUnion include Gitlab::Utils::StrongMemoize include IgnorableColumns + include Namespaces::Traversal::Recursive # Prevent users from creating unreasonably deep level of nesting. # The number 20 was taken based on maximum nesting level of @@ -103,6 +104,10 @@ class Namespace < ApplicationRecord ) end + # Make sure that the name is same as strong_memoize name in root_ancestor + # method + attr_writer :root_ancestor + class << self def by_path(path) find_by('lower(path) = :value', value: path.downcase) @@ -243,50 +248,6 @@ class Namespace < ApplicationRecord projects.with_shared_runners.any? end - # Returns all ancestors, self, and descendants of the current namespace. - def self_and_hierarchy - Gitlab::ObjectHierarchy - .new(self.class.where(id: id)) - .all_objects - end - - # Returns all the ancestors of the current namespaces. - def ancestors - return self.class.none unless parent_id - - Gitlab::ObjectHierarchy - .new(self.class.where(id: parent_id)) - .base_and_ancestors - end - - # returns all ancestors upto but excluding the given namespace - # when no namespace is given, all ancestors upto the top are returned - def ancestors_upto(top = nil, hierarchy_order: nil) - Gitlab::ObjectHierarchy.new(self.class.where(id: id)) - .ancestors(upto: top, hierarchy_order: hierarchy_order) - end - - def self_and_ancestors(hierarchy_order: nil) - return self.class.where(id: id) unless parent_id - - Gitlab::ObjectHierarchy - .new(self.class.where(id: id)) - .base_and_ancestors(hierarchy_order: hierarchy_order) - end - - # Returns all the descendants of the current namespace. - def descendants - Gitlab::ObjectHierarchy - .new(self.class.where(parent_id: id)) - .base_and_descendants - end - - def self_and_descendants - Gitlab::ObjectHierarchy - .new(self.class.where(id: id)) - .base_and_descendants - end - def user_ids_for_project_authorizations [owner_id] end @@ -312,14 +273,6 @@ class Namespace < ApplicationRecord parent_id.present? || parent.present? end - def root_ancestor - return self if persisted? && parent_id.nil? - - strong_memoize(:root_ancestor) do - self_and_ancestors.reorder(nil).find_by(parent_id: nil) - end - end - def subgroup? has_parent? end |