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
linting
ulferts47a90a3cef41
diff --git a/lib/api/decorators/sql/hal.rb b/lib/api/decorators/sql/hal.rbindex 74de1447c36..185f1868b42 100644--- a/lib/api/decorators/sql/hal.rb+++ b/lib/api/decorators/sql/hal.rb@@ -266,6 +266,14 @@ module APIlink[:href] ? link[:href].call(walker_result) : "format('#{api_v3_paths.send(path_name, '%s')}', #{column})"end++ def sql_offset(walker_result)+ (walker_result.offset - 1) * walker_result.page_size+ end++ def sql_limit(walker_result)+ walker_result.page_size+ endendendenddiff --git a/lib/api/decorators/sql_collection_representer.rb b/lib/api/decorators/sql_collection_representer.rbindex 41280981dcb..3150324494e 100644--- a/lib/api/decorators/sql_collection_representer.rb+++ b/lib/api/decorators/sql_collection_representer.rb@@ -52,14 +52,6 @@ module APIdef href_query(walker_results, overrides)walker_results.url_query.merge(overrides).to_queryend-- def sql_offset(walker_result)- (walker_result.offset - 1) * walker_result.page_size- end-- def sql_limit(walker_result)- walker_result.page_size- endendproperty :_type,diff --git a/lib/api/v3/projects/project_sql_representer.rb b/lib/api/v3/projects/project_sql_representer.rbindex 4dea6698885..881240978e7 100644--- a/lib/api/v3/projects/project_sql_representer.rb+++ b/lib/api/v3/projects/project_sql_representer.rb@@ -48,18 +48,11 @@ module API(SELECTorigin.id,- CASE- WHEN ancestors.id IS NOT NULL AND visible_ancestors.id IS NOT NULL- 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- THEN json_build_object('href', '#{API::V3::URN_UNDISCLOSED}', 'title', '#{I18n.t(:'api_v3.undisclosed.ancestor')}')- ELSE NULL- END link+ #{ancestor_projection} linkFROM projects originLEFT OUTER JOIN projects ancestorsON ancestors.lft < origin.lft AND ancestors.rgt > origin.rgt- LEFT OUTER JOIN (#{Project.visible.to_sql}) visible_ancestors- ON visible_ancestors.id = ancestors.id+ #{visibility_join}WHERE origin.id IN (#{origin_subselect(walker_result).select(:id).to_sql})ORDER by origin.id, ancestors.lft) ancestors@@ -69,11 +62,44 @@ module APIdef 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)+ walker_result.filter_scope.limit(sql_limit(walker_result)).offset(sql_offset(walker_result))elsewalker_result.filter_scopeendend++ def ancestor_projection+ if User.current.admin?+ <<-SQL.squish+ CASE+ WHEN ancestors.id IS NOT NULL+ THEN json_build_object('href', format('/api/v3/projects/%s', ancestors.id), 'title', ancestors.name)+ ELSE NULL+ END+ SQL+ else+ <<-SQL.squish+ CASE+ WHEN ancestors.id IS NOT NULL AND visible_ancestors.id IS NOT NULL+ 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+ THEN json_build_object('href', '#{API::V3::URN_UNDISCLOSED}', 'title', '#{I18n.t(:'api_v3.undisclosed.ancestor')}')+ ELSE NULL+ END+ SQL+ end+ end++ def visibility_join+ if User.current.admin?+ ''+ else+ <<-SQL.squish+ LEFT OUTER JOIN (#{Project.visible.to_sql}) visible_ancestors+ ON visible_ancestors.id = ancestors.id+ SQL+ end+ endendlink :self,diff --git a/lib/api/v3/utilities/endpoints/sql_index.rb b/lib/api/v3/utilities/endpoints/sql_index.rbindex 8bf1b2f06d1..bfca63ae36c 100644--- a/lib/api/v3/utilities/endpoints/sql_index.rb+++ b/lib/api/v3/utilities/endpoints/sql_index.rb@@ -72,7 +72,7 @@ module APIenddef nested_hash(path)- { path[0] => path.length > 1 ? nested_hash(path[1..-1]) : {} }+ { path[0] => path.length > 1 ? nested_hash(path[1..]) : {} }endendenddiff --git a/spec/lib/api/v3/projects/project_sql_representer_renderning_spec.rb b/spec/lib/api/v3/projects/project_sql_representer_rendering_spec.rbsimilarity index 82%rename from spec/lib/api/v3/projects/project_sql_representer_renderning_spec.rbrename to spec/lib/api/v3/projects/project_sql_representer_rendering_spec.rbindex 01fe6d34911..cae929cc517 100644--- a/spec/lib/api/v3/projects/project_sql_representer_renderning_spec.rb+++ b/spec/lib/api/v3/projects/project_sql_representer_rendering_spec.rb@@ -29,6 +29,16 @@ require 'spec_helper'describe ::API::V3::Projects::ProjectSqlRepresenter, 'rendering' doinclude ::API::V3::Utilities::PathHelper+ subject(:json) do+ ::API::V3::Utilities::SqlRepresenterWalker+ .new(scope,+ embed: {},+ select: select,+ current_user: current_user)+ .walk(described_class)+ .to_json+ end+let(:scope) doProject.where(id: project.id)@@ -40,24 +50,14 @@ describe ::API::V3::Projects::ProjectSqlRepresenter, 'rendering' dolet(:role) { create(:role) }+ let(:select) { { 'id' => {}, '_type' => {}, 'self' => {}, 'name' => {}, 'ancestors' => {} } }+current_user docreate(:user,member_in_project: project,member_through_role: role)end- let(:select) { { 'id' => {}, '_type' => {}, 'self' => {}, 'name' => {}, 'ancestors' => {} } }-- subject(:json) do- ::API::V3::Utilities::SqlRepresenterWalker- .new(scope,- embed: {},- select: select,- current_user: current_user)- .walk(described_class)- .to_json- end-context 'without an ancestor' doit 'renders as expected' doexpect(json)@@ -158,4 +158,46 @@ describe ::API::V3::Projects::ProjectSqlRepresenter, 'rendering' do)endend++ context 'with an archived ancestor but with the user being admin' do+ let!(:parent) do+ create(:project, active: false).tap do |parent|+ project.parent = parent+ project.save+ end+ end++ let!(:grandparent) do+ create(:project).tap do |grandparent|+ parent.parent = grandparent+ parent.save+ end+ end++ let(:select) { { 'ancestors' => {} } }++ current_user do+ create(:admin)+ end++ 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_paths.project(parent.id),+ title: parent.name+ }+ ]+ }+ }.to_json+ )+ end+ endenddiff --git a/spec/requests/api/v3/capability_resource_spec.rb b/spec/requests/api/v3/capability_resource_spec.rbindex be867888a75..798f932520e 100644--- a/spec/requests/api/v3/capability_resource_spec.rb+++ b/spec/requests/api/v3/capability_resource_spec.rb@@ -344,7 +344,7 @@ describe 'API v3 capabilities resource', type: :request, content_type: :json do{id: "memberships/update/p#{project.id}-#{current_user.id}"}- ]+ ]}}