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
support signaling on available parent project endpoint
ulferts03609dd6e0e3
diff --git a/lib/api/v3/projects/available_parents_api.rb b/lib/api/v3/projects/available_parents_api.rbindex fa268b53cba..a55e128ddbf 100644--- a/lib/api/v3/projects/available_parents_api.rb+++ b/lib/api/v3/projects/available_parents_api.rb@@ -37,25 +37,25 @@ module APIauthorize_any(%i[add_project add_subprojects edit_project], global: true)end- get &::API::V3::Utilities::Endpoints::Index.new(model: Project,- scope: -> do- project = if params[:of]- Project.find(params[:of])- else- Project.new- end+ get &::API::V3::Utilities::Endpoints::SqlFallbackedIndex.new(model: Project,+ scope: -> do+ project = if params[:of]+ Project.find(params[:of])+ else+ Project.new+ end- contract_class = if project.new_record?- ::Projects::CreateContract- else- ::Projects::UpdateContract- end+ contract_class = if project.new_record?+ ::Projects::CreateContract+ else+ ::Projects::UpdateContract+ end- contract = contract_class.new(project, current_user)+ contract = contract_class.new(project, current_user)- contract.assignable_parents.includes(:enabled_modules)- end)- .mount+ contract.assignable_parents.includes(:enabled_modules)+ end)+ .mountendendenddiff --git a/spec/requests/api/v3/projects/available_parents_resource_spec.rb b/spec/requests/api/v3/projects/available_parents_resource_spec.rbindex 62d1268fdad..69cb9cbac44 100644--- a/spec/requests/api/v3/projects/available_parents_resource_spec.rb+++ b/spec/requests/api/v3/projects/available_parents_resource_spec.rb@@ -86,47 +86,58 @@ describe 'API v3 Project available parents resource', type: :request, content_tyendcontext 'without a project candidate' do- it 'returns 200 OK' do- expect(subject.status)- .to be 200+ before do+ responseend- it 'returns projects for which the user has the add_subprojects permission' do- expect(subject.body)- .to have_json_size(3)- .at_path('_embedded/elements')-- expect(subject.body)- .to be_json_eql(project.id.to_json)- .at_path('_embedded/elements/0/id')-- expect(subject.body)- .to be_json_eql(project_with_add_subproject_permission.id.to_json)- .at_path('_embedded/elements/1/id')-- expect(subject.body)- .to be_json_eql(child_project_with_add_subproject_permission.id.to_json)- .at_path('_embedded/elements/2/id')+ it_behaves_like 'API V3 collection response', 3, 3, 'Project', 'Collection' do+ let(:elements) { [project, project_with_add_subproject_permission, child_project_with_add_subproject_permission] }endendcontext 'with a project candidate' dolet(:path) { api_v3_paths.projects_available_parents + "?of=#{project.id}" }+ before do+ response+ end+it 'returns 200 OK' doexpect(subject.status).to be 200end- it 'returns projects for which the user has the add_subprojects permission but' +- ' excludes the queried for project and it`s descendants' do- expect(subject.body)- .to have_json_size(1)- .at_path('_embedded/elements')+ # Returns projects for which the user has the add_subprojects permission but+ # excludes the queried for project and its descendants+ it_behaves_like 'API V3 collection response', 1, 1, 'Project', 'Collection' do+ let(:elements) { [project_with_add_subproject_permission] }+ end+ end++ context 'when signaling the properties to include' do+ let(:other_projects) { [] }+ let(:select) { 'elements/id,elements/name,elements/ancestors,total' }+ let(:path) { api_v3_paths.path_for(:projects_available_parents, select:) }+ let(:expected) do+ {+ total: 1,+ _embedded: {+ elements: [+ {+ id: project.id,+ name: project.name,+ _links: {+ ancestors: []+ }+ }+ ]+ }+ }+ end- expect(subject.body)- .to be_json_eql(project_with_add_subproject_permission.id.to_json)- .at_path('_embedded/elements/0/id')+ it 'is the reduced set of properties of the embedded elements' do+ expect(response.body)+ .to be_json_eql(expected.to_json)endend