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

fix includes_hierarchy condition

ulfertsa28feeea27ee
diff --git a/app/models/work_packages/scopes/relatable.rb b/app/models/work_packages/scopes/relatable.rb
index 6bcfc43ef4b..e0fb7cd75a4 100644
--- a/app/models/work_packages/scopes/relatable.rb
+++ b/app/models/work_packages/scopes/relatable.rb
@@ -380,7 +380,7 @@ module WorkPackages::Scopes
false from_to_id,
related.includes_from_relation,
related.includes_to_relation,
- true includes_hierarchy
+ #{with_descendants ? 'work_package_hierarchies.descendant_id = related.id' : 'work_package_hierarchies.ancestor_id = related.id'} includes_hierarchy
FROM
work_package_hierarchies
WHERE
diff --git a/spec/models/work_packages/scopes/relatable_spec.rb b/spec/models/work_packages/scopes/relatable_spec.rb
index 4f19c40d37d..b754a483eba 100644
--- a/spec/models/work_packages/scopes/relatable_spec.rb
+++ b/spec/models/work_packages/scopes/relatable_spec.rb
@@ -1430,4 +1430,84 @@ describe WorkPackages::Scopes::Relatable, '.relatable scope' do
end
end
end
+
+ context 'with a predecessor chain where the first has parent and child' do
+ let(:direct_predecessor) do
+ create(:work_package).tap do |pre|
+ create(:follows_relation, from: origin, to: pre)
+ end
+ end
+ let(:transitive_predecessor) do
+ create(:work_package, parent: transitive_predecessor_parent).tap do |pre|
+ create(:follows_relation, from: direct_predecessor, to: pre)
+ end
+ end
+ let(:transitive_predecessor_parent) do
+ create(:work_package)
+ end
+ let(:transitive_predecessor_child) do
+ create(:work_package, parent: transitive_predecessor)
+ end
+ let!(:existing_work_packages) do
+ [direct_predecessor, transitive_predecessor, transitive_predecessor_parent, transitive_predecessor_child]
+ end
+
+ context "for a 'parent' relation" do
+ let(:relation_type) { Relation::TYPE_PARENT }
+
+ it "contains the parent at the beginning of the chain" do
+ expect(relatable)
+ .to match_array [transitive_predecessor_parent]
+ end
+ end
+
+ context "for a 'child' relation" do
+ let(:relation_type) { Relation::TYPE_CHILD }
+
+ it "contains the child at the beginning of the chain" do
+ expect(relatable)
+ .to match_array [transitive_predecessor_child]
+ end
+ end
+ end
+
+ context 'with a successor chain where the last has parent and child' do
+ let(:direct_successor) do
+ create(:work_package).tap do |suc|
+ create(:follows_relation, to: origin, from: suc)
+ end
+ end
+ let(:transitive_successor) do
+ create(:work_package, parent: transitive_successor_parent).tap do |suc|
+ create(:follows_relation, to: direct_successor, from: suc)
+ end
+ end
+ let(:transitive_successor_parent) do
+ create(:work_package)
+ end
+ let(:transitive_successor_child) do
+ create(:work_package, parent: transitive_successor)
+ end
+ let!(:existing_work_packages) do
+ [direct_successor, transitive_successor, transitive_successor_parent, transitive_successor_child]
+ end
+
+ context "for a 'parent' relation" do
+ let(:relation_type) { Relation::TYPE_PARENT }
+
+ it "contains the parent at the beginning of the chain" do
+ expect(relatable)
+ .to match_array [transitive_successor_parent]
+ end
+ end
+
+ context "for a 'child' relation" do
+ let(:relation_type) { Relation::TYPE_CHILD }
+
+ it "contains the child at the beginning of the chain" do
+ expect(relatable)
+ .to match_array [transitive_successor_child]
+ end
+ end
+ end
end