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
have undisclosed placeholder in case the user lacks permission
ulfertsbec1b1c62642
diff --git a/lib/api/v3/projects/project_sql_representer.rb b/lib/api/v3/projects/project_sql_representer.rbindex de99041e8bd..4dea6698885 100644--- a/lib/api/v3/projects/project_sql_representer.rb+++ b/lib/api/v3/projects/project_sql_representer.rb@@ -42,12 +42,6 @@ module APIprotecteddef ancestors_sql(walker_result)- origin_subselect = if walker_result.page_size- walker_result.filter_scope.limit(walker_result.page_size).offset((walker_result.offset - 1) * walker_result.page_size)- else- walker_result.filter_scope- end-<<-SQL.squishSELECT id, CASE WHEN count(link) = 0 THEN '[]' ELSE json_agg(link) END ancestorsFROM@@ -55,19 +49,31 @@ module APISELECTorigin.id,CASE- WHEN ancestors.id IS NOT NULL+ WHEN ancestors.id IS NOT NULL AND visible_ancestors.id IS NOT NULLTHEN 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+ THEN json_build_object('href', '#{API::V3::URN_UNDISCLOSED}', 'title', '#{I18n.t(:'api_v3.undisclosed.ancestor')}')ELSE NULLEND linkFROM projects originLEFT OUTER JOIN projects ancestorsON ancestors.lft < origin.lft AND ancestors.rgt > origin.rgt- WHERE origin.id IN (#{origin_subselect.select(:id).to_sql})+ LEFT OUTER JOIN (#{Project.visible.to_sql}) visible_ancestors+ ON visible_ancestors.id = ancestors.id+ WHERE origin.id IN (#{origin_subselect(walker_result).select(:id).to_sql})ORDER by origin.id, ancestors.lft) ancestorsGROUP BY idSQLend++ def origin_subselect(walker_result)+ if walker_result.page_size+ walker_result.filter_scope.limit(walker_result.page_size).offset((walker_result.offset - 1) * walker_result.page_size)+ else+ walker_result.filter_scope+ end+ endendlink :self,diff --git a/spec/lib/api/v3/projects/project_sql_representer_renderning_spec.rb b/spec/lib/api/v3/projects/project_sql_representer_renderning_spec.rbindex 3375ce2e5db..01fe6d34911 100644--- a/spec/lib/api/v3/projects/project_sql_representer_renderning_spec.rb+++ b/spec/lib/api/v3/projects/project_sql_representer_renderning_spec.rb@@ -33,21 +33,26 @@ describe ::API::V3::Projects::ProjectSqlRepresenter, 'rendering' doProject.where(id: project.id)end+let(:project) docreate(:project)end+ let(:role) { create(:role) }+current_user docreate(:user,member_in_project: project,- member_with_permissions: [])+ member_through_role: role)end- subject(:json) do+ let(:select) { { 'id' => {}, '_type' => {}, 'self' => {}, 'name' => {}, 'ancestors' => {} } }++ subject(:json) do::API::V3::Utilities::SqlRepresenterWalker.new(scope,embed: {},- select: { 'id' => {}, '_type' => {}, 'self' => {}, 'name' => {}, 'ancestors' => {} },+ select: select,current_user: current_user).walk(described_class).to_json@@ -68,20 +73,21 @@ describe ::API::V3::Projects::ProjectSqlRepresenter, 'rendering' dotitle: project.name}}- }.to_json)+ }.to_json+ )endendcontext 'with an ancestor' dolet!(:parent) do- create(:project).tap do |parent|+ create(:project, members: { current_user => role }).tap do |parent|project.parent = parentproject.saveendendlet!(:grandparent) do- create(:project).tap do |grandparent|+ create(:project, members: { current_user => role }).tap do |grandparent|parent.parent = grandparentparent.saveend@@ -110,7 +116,46 @@ describe ::API::V3::Projects::ProjectSqlRepresenter, 'rendering' dotitle: project.name}}- }.to_json)+ }.to_json+ )+ end+ end++ context 'with an ancestor the user does not have permission to see' do+ let!(:parent) do+ create(:project).tap do |parent|+ project.parent = parent+ project.save+ end+ end++ let!(:grandparent) do+ create(:project, members: { current_user => role }).tap do |grandparent|+ parent.parent = grandparent+ parent.save+ end+ end++ let(:select) { { 'ancestors' => {} } }++ it 'renders as expected' do+ expect(json)+ .to be_json_eql(+ {+ _links: {+ ancestors: [+ {+ href: api_v3_paths.project(grandparent.id),+ title: grandparent.name+ },+ {+ href: API::V3::URN_UNDISCLOSED,+ title: I18n.t(:'api_v3.undisclosed.ancestor')+ }+ ]+ }+ }.to_json+ )endendend