diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-10 15:45:35 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-10 16:55:02 +0200 |
commit | 9d1348d66838b4c5e25ba133d486239482973fca (patch) | |
tree | d7c56904b3f991c462be9c593ef9e130addd1442 /app/models/namespace.rb | |
parent | 7611e6a0f745393aa432e4201e8053072a263c2e (diff) | |
download | gitlab-ce-9d1348d66838b4c5e25ba133d486239482973fca.tar.gz |
Move the `ancestors_upto` to `Project` and `Namespace`
Diffstat (limited to 'app/models/namespace.rb')
-rw-r--r-- | app/models/namespace.rb | 7 |
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 |