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

Re-add conditions

Klaus Zandersddd6476972df
diff --git a/app/models/work_packages/relations.rb b/app/models/work_packages/relations.rb
index 082fa01bbd4..55267a8fe56 100644
--- a/app/models/work_packages/relations.rb
+++ b/app/models/work_packages/relations.rb
@@ -42,8 +42,16 @@ module WorkPackages::Relations
# Since the method looks for relations on the current work package, only work packages
# that are on either end of a relation with the current work package need to be considered.
# The number should be quite small compared to the total number of work packages.
- merge(Relation.visible(user,
- work_package_focus_scope: Arel::Nodes::UnionAll.new(select(:from_id).arel, select(:to_id).arel)))
+
+ # merge() method that we will be using below will be overriding all where conditions with the
+ # ones coming in from the other relation. This is not what we want. We want to keep the old constraints
+ # and add the new ones to it.
+ old_constraints = arel.constraints
+
+ work_package_focus_scope = Arel::Nodes::UnionAll.new(select(:from_id).arel, select(:to_id).arel)
+ visible_relations = Relation.visible(user, work_package_focus_scope:)
+
+ merge(visible_relations).where(old_constraints)
end
end
# rubocop:enable Rails/InverseOf
diff --git a/spec/models/relations/scopes/visible_spec.rb b/spec/models/relations/scopes/visible_spec.rb
index d91770cc2f9..55716b984ee 100644
--- a/spec/models/relations/scopes/visible_spec.rb
+++ b/spec/models/relations/scopes/visible_spec.rb
@@ -104,9 +104,9 @@ RSpec.describe Relations::Scopes::Visible do
admin = create(:admin)
User.execute_as(admin) do
- expect(red.relations.visible).to contain_exactly(red.relations)
- expect(green.relations.visible).to contain_exactly(green.relations)
- expect(blue.relations.visible).to contain_exactly(blue.relations)
+ expect(red.relations.visible).to match_array(red.relations)
+ expect(green.relations.visible).to match_array(green.relations)
+ expect(blue.relations.visible).to match_array(blue.relations)
end
end
end