Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-10-10 16:45:35 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2017-10-10 17:55:02 +0300
commit9d1348d66838b4c5e25ba133d486239482973fca (patch)
treed7c56904b3f991c462be9c593ef9e130addd1442 /app/models/namespace.rb
parent7611e6a0f745393aa432e4201e8053072a263c2e (diff)
Move the `ancestors_upto` to `Project` and `Namespace`
Diffstat (limited to 'app/models/namespace.rb')
-rw-r--r--app/models/namespace.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index e279d8dd8c5..a6f517ce2ce 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -160,6 +160,13 @@ class Namespace < ActiveRecord::Base
.base_and_ancestors
end
+ # returns all ancestors upto but excluding the the given namespace
+ # when no namespace is given, all ancestors upto the top are returned
+ def ancestors_upto(top = nil)
+ Gitlab::GroupHierarchy.new(self.class.where(id: id))
+ .ancestors(upto: top)
+ end
+
def self_and_ancestors
return self.class.where(id: id) unless parent_id