Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#36743] do not include the selected ancestor

Tobias Dillmann30969168698c
diff --git a/app/models/queries/work_packages/filter/ancestor_filter.rb b/app/models/queries/work_packages/filter/ancestor_filter.rb
index fe13bda2062..50e2432d969 100644
--- a/app/models/queries/work_packages/filter/ancestor_filter.rb
+++ b/app/models/queries/work_packages/filter/ancestor_filter.rb
@@ -33,7 +33,11 @@ class Queries::WorkPackages::Filter::AncestorFilter <
include ::Queries::WorkPackages::Filter::FilterForWpMixin
def where
- descendant_ids = WorkPackageHierarchy.where(ancestor_id: no_templated_values).pluck(:descendant_id)
+ descendant_ids = WorkPackageHierarchy
+ .where(ancestor_id: no_templated_values)
+ # exclude the selected ancestors:
+ .where.not(descendant_id: no_templated_values)
+ .pluck(:descendant_id)
operator_strategy.sql_for_field(descendant_ids, self.class.model.table_name, :id)
end
diff --git a/spec/models/queries/work_packages/filter/ancestor_filter_spec.rb b/spec/models/queries/work_packages/filter/ancestor_filter_spec.rb
index f2fa70249fd..fcfc9e22b64 100644
--- a/spec/models/queries/work_packages/filter/ancestor_filter_spec.rb
+++ b/spec/models/queries/work_packages/filter/ancestor_filter_spec.rb
@@ -287,8 +287,8 @@ RSpec.describe Queries::WorkPackages::Filter::AncestorFilter do
.includes(instance.includes)
.where(instance.where)
- # The ancestor filter will include all descendants of the parent work package, as well as the parent itself.
- expect(scope).to contain_exactly(parent, child, grandchild)
+ # The ancestor filter will include all descendants of the parent work package, but not the parent itself.
+ expect(scope).to contain_exactly(child, grandchild)
end
context "with the `!` operator" do
@@ -299,13 +299,13 @@ RSpec.describe Queries::WorkPackages::Filter::AncestorFilter do
instance.operator = "!"
end
- it "excludes the parent and its descendants" do
+ it "excludes the parents descendants, but not the parent itself" do
scope = WorkPackage
.references(instance.includes)
.includes(instance.includes)
.where(instance.where)
- expect(scope).to contain_exactly(another_wp, grandparent)
+ expect(scope).to contain_exactly(another_wp, grandparent, parent)
end
end
end