diff options
Diffstat (limited to 'app/models/work_item.rb')
-rw-r--r-- | app/models/work_item.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/models/work_item.rb b/app/models/work_item.rb index ed6f9d161a6..0810c520f7e 100644 --- a/app/models/work_item.rb +++ b/app/models/work_item.rb @@ -38,6 +38,18 @@ class WorkItem < Issue end end + def ancestors + hierarchy.ancestors(hierarchy_order: :asc) + end + + def same_type_base_and_ancestors + hierarchy(same_type: true).base_and_ancestors(hierarchy_order: :asc) + end + + def same_type_descendants_depth + hierarchy(same_type: true).max_descendants_depth.to_i + end + private override :parent_link_confidentiality @@ -56,6 +68,13 @@ class WorkItem < Issue Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter.track_work_item_created_action(author: author) end + + def hierarchy(options = {}) + base = self.class.where(id: id) + base = base.where(work_item_type_id: work_item_type_id) if options[:same_type] + + ::Gitlab::WorkItems::WorkItemHierarchy.new(base, options: options) + end end WorkItem.prepend_mod |