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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
only have single rule - direct relation - apply to relates
ulfertsee3282a31226
diff --git a/app/models/work_packages/scopes/relatable.rb b/app/models/work_packages/scopes/relatable.rbindex 2cf44b9d6cc..f8c648b8815 100644--- a/app/models/work_packages/scopes/relatable.rb+++ b/app/models/work_packages/scopes/relatable.rb@@ -75,7 +75,8 @@ module WorkPackages::Scopes## There are a couple of exceptions and additions to the limitations outlined above for the following types:# * Relation::TYPE_RELATES: Since this is essentially undirected and does not carry a lot of semantic, the work packages- # are simply somehow related, such relations do not follow the "non circular" nor the "ancestor/descendant" rule.+ # are simply somehow related, such relations only follow the "single relation" rule (which includes their direct+ # parent/children) and none of the other.# * Relation::TYPE_PARENT: Since creating a new relationship will remove the old parent relationship, current ancestors# (except the direct parent) are relatable to. Descendants however are not since that would create a circle.# In addition to the existing hierarchy, the FOLLOWS relationships are taken into account. Predecessors and successors@@ -185,17 +186,27 @@ module WorkPackages::Scopesenddef not_having_transitive_relation(work_package, relation_type)- sql = <<~SQL.squish- WITH- RECURSIVE- #{non_relatable_paths_sql(work_package, relation_type)}+ if relation_type == Relation::TYPE_RELATES+ # Bypassing the recursive query in this case as only children and parent needs to be excluded.+ # Using this more complicated statement since+ # where.not(parent:id: work_package.id)+ # will lead to+ # "parent_id != 123" which excludes+ # work packages having parent_id NULL.+ where.not(id: where(id: work_package.parent_id).or(where(parent_id: work_package.id)).select(:id))+ else+ sql = <<~SQL.squish+ WITH+ RECURSIVE+ #{non_relatable_paths_sql(work_package, relation_type)}- SELECT id- FROM related- WHERE #{blocklist_condition(relation_type)}- SQL+ SELECT id+ FROM related+ WHERE #{blocklist_condition(relation_type)}+ SQL- where("work_packages.id NOT IN (#{Arel.sql(sql)})")+ where("work_packages.id NOT IN (#{Arel.sql(sql)})")+ endendprivate@@ -288,9 +299,8 @@ module WorkPackages::Scopeswhen Relation::TYPE_PARENTunions << existing_relation_of_type_lateral(Relation::TYPE_FOLLOWS, limit_direction: true)unions << existing_relation_of_type_lateral(Relation::TYPE_PRECEDES, limit_direction: true)- when Relation::TYPE_RELATES- # Nothingelse+ unions << existing_hierarchy_lateralunions << existing_relation_of_type_lateral(relation_type)enddiff --git a/spec/models/work_packages/scopes/relatable_spec.rb b/spec/models/work_packages/scopes/relatable_spec.rbindex a53b280392a..126fe18102a 100644--- a/spec/models/work_packages/scopes/relatable_spec.rb+++ b/spec/models/work_packages/scopes/relatable_spec.rb@@ -390,18 +390,18 @@ describe WorkPackages::Scopes::Relatable, '.relatable scope' docreate(:follows_relation, from: origin_child, to: aunt)end- it 'contains aunt' do+ it 'contains aunt and grandparent' doexpect(relatable)- .to match_array [aunt]+ .to match_array [aunt, grandparent]endendcontext "for a 'relates' relation" dolet(:relation_type) { Relation::TYPE_RELATES }- it 'contains aunt' do+ it 'contains aunt and grandparent' doexpect(relatable)- .to match_array [aunt]+ .to match_array [aunt, grandparent]endendenddiff --git a/spec/requests/api/v3/work_packages/available_relation_candidates_resource_spec.rb b/spec/requests/api/v3/work_packages/available_relation_candidates_resource_spec.rbindex 78395154dbf..9dd6981ebdc 100644--- a/spec/requests/api/v3/work_packages/available_relation_candidates_resource_spec.rb+++ b/spec/requests/api/v3/work_packages/available_relation_candidates_resource_spec.rb@@ -84,8 +84,8 @@ describe ::API::V3::WorkPackages::AvailableRelationCandidatesAPI docontext "without cross project relations",with_settings: { cross_project_work_package_relations: false } dodescribe "relation candidates for wp1 (in hierarchy)" do- it "returns an empty list" do # as relations to ancestors or descendents is not allowed- expect(result["count"]).to eq 0+ it "returns an empty list" do+ expect(subjects).to match_array ["WP 1.2.1"]endend@@ -119,8 +119,8 @@ describe ::API::V3::WorkPackages::AvailableRelationCandidatesAPI dodescribe "relation candidates for wp1 (in hierarchy)" dolet(:href) { "/api/v3/work_packages/#{wp1.id}/available_relation_candidates?query=WP" }- it "returns WP 2 and all WP 2.x" do- expect(subjects).to match_array ["WP 2", "WP 2.1", "WP 2.2"]+ it "returns WP 2 and all WP 2.x as well at the grandchild WP 1.2.1" do+ expect(subjects).to match_array ["WP 2", "WP 2.1", "WP 2.2", "WP 1.2.1"]endend@@ -133,7 +133,7 @@ describe ::API::V3::WorkPackages::AvailableRelationCandidatesAPI doendit "returns WP 2 and all WP 2.x sorted by updated_at DESC" do- expect(subjects).to match ["WP 2.1", "WP 2", "WP 2.2"]+ expect(subjects).to match ["WP 2.1", "WP 1.2.1", "WP 2", "WP 2.2"]endend