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

avoid left joining visiblity check as it leads to duplicate entries

ulfertse7ce6a755e9c
diff --git a/lib/api/v3/projects/project_sql_representer.rb b/lib/api/v3/projects/project_sql_representer.rb
index fc0ffc7f088..a334256a39b 100644
--- a/lib/api/v3/projects/project_sql_representer.rb
+++ b/lib/api/v3/projects/project_sql_representer.rb
@@ -35,12 +35,17 @@ module API
class << self
def ctes(walker_result)
{
+ visible_projects: visible_projects_sql,
ancestors: ancestors_sql(walker_result)
}
end
protected
+ def visible_projects_sql
+ Project.visible.to_sql
+ end
+
def ancestors_sql(walker_result)
<<-SQL.squish
SELECT id, CASE WHEN count(link) = 0 THEN '[]' ELSE json_agg(link) END ancestors
@@ -52,7 +57,6 @@ module API
FROM projects origin
LEFT OUTER JOIN projects ancestors
ON ancestors.lft < origin.lft AND ancestors.rgt > origin.rgt
- #{visibility_join}
WHERE origin.id IN (#{origin_subselect(walker_result).select(:id).to_sql})
ORDER by origin.id, ancestors.lft
) ancestors
@@ -80,9 +84,9 @@ module API
else
<<-SQL.squish
CASE
- WHEN ancestors.id IS NOT NULL AND visible_ancestors.id IS NOT NULL
+ WHEN ancestors.id IS NOT NULL AND ancestors.id IN (SELECT id FROM visible_projects)
THEN json_build_object('href', format('/api/v3/projects/%s', ancestors.id), 'title', ancestors.name)
- WHEN ancestors.id IS NOT NULL AND visible_ancestors.id IS NULL
+ WHEN ancestors.id IS NOT NULL AND ancestors.id NOT IN (SELECT id FROM visible_projects)
THEN json_build_object('href', '#{API::V3::URN_UNDISCLOSED}', 'title', '#{I18n.t(:'api_v3.undisclosed.ancestor')}')
ELSE NULL
END