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
Fix/archived projects via api (#8625)
ulferts50daff50629d
diff --git a/app/models/project.rb b/app/models/project.rbindex 976bec97cc4..13daff9812a 100644--- a/app/models/project.rb+++ b/app/models/project.rb@@ -574,6 +574,6 @@ class Project < ApplicationRecordenddef remove_white_spaces_from_project_name- self.name = name.squish unless self.name.nil?+ self.name = name.squish unless name.nil?endenddiff --git a/lib/api/utilities/endpoints/bodied.rb b/lib/api/utilities/endpoints/bodied.rbindex ef2801d4885..535376ce701 100644--- a/lib/api/utilities/endpoints/bodied.rb+++ b/lib/api/utilities/endpoints/bodied.rb@@ -90,7 +90,7 @@ module APIcontract_class: process_contract }process_service- .new(args.compact)+ .new(**args.compact).call(params)enddiff --git a/lib/api/v3/projects/projects_api.rb b/lib/api/v3/projects/projects_api.rbindex 97fe1a8aa7b..720f428cf19 100644--- a/lib/api/v3/projects/projects_api.rb+++ b/lib/api/v3/projects/projects_api.rb@@ -30,11 +30,20 @@ module APImodule V3module Projectsclass ProjectsAPI < ::API::OpenProjectAPI+ helpers do+ def visible_project_scope+ if current_user.admin?+ Project.all+ else+ Project.visible(current_user)+ end+ end+ end+resources :projects doget &::API::V3::Utilities::Endpoints::Index.new(model: Project,scope: -> {- Project- .visible(User.current)+ visible_project_scope.includes(ProjectRepresenter.to_eager_load)}).mount@@ -52,7 +61,7 @@ module APIendroute_param :id doafter_validation do- @project = Project.visible(current_user).find(params[:id])+ @project = visible_project_scope.find(params[:id])endget &::API::V3::Utilities::Endpoints::Show.new(model: Project).mountdiff --git a/lib/open_project/patches/declarative_option.rb b/lib/open_project/patches/declarative_option.rbindex e38d03654ba..08f3cba0dc8 100644--- a/lib/open_project/patches/declarative_option.rb+++ b/lib/open_project/patches/declarative_option.rb@@ -26,8 +26,6 @@# See docs/COPYRIGHT.rdoc for more details.#++-require 'representable'-module OpenProject::Patches::DeclarativeOptionextend ActiveSupport::Concerndiff --git a/spec/requests/api/v3/project_resource_spec.rb b/spec/requests/api/v3/project_resource_spec.rbindex 2257b1aeaaa..2bacea5f97f 100644--- a/spec/requests/api/v3/project_resource_spec.rb+++ b/spec/requests/api/v3/project_resource_spec.rb@@ -36,11 +36,13 @@ describe 'API v3 Project resource', type: :request, content_type: :json dolet(:current_user) doFactoryBot.create(:user, member_in_project: project, member_through_role: role)end+ let(:admin) { FactoryBot.create(:admin) }let(:project) do- FactoryBot.create(:project, public: false, status: project_status)+ FactoryBot.create(:project, public: false, status: project_status, active: project_active)end+ let(:project_active) { true }let(:project_status) do- FactoryBot.create(:project_status)+ FactoryBot.build(:project_status, project: nil)endlet(:other_project) doFactoryBot.create(:project, public: false)@@ -150,6 +152,29 @@ describe 'API v3 Project resource', type: :request, content_type: :json do.at_path('_links/parent/href')endend++ context 'with the project being archived/inactive' do+ let(:project_active) { false }++ context 'with the user being admin' do+ let(:current_user) { admin }++ it 'responds with 200 OK' do+ expect(subject.status).to eq(200)+ end++ it 'responds with the correct project' do+ expect(subject.body).to include_json('Project'.to_json).at_path('_type')+ expect(subject.body).to be_json_eql(project.identifier.to_json).at_path('identifier')+ end+ end++ context 'with the user being no admin' do+ it 'responds with 404' do+ expect(subject.status).to eq(404)+ end+ end+ endendcontext 'not logged in user' do@@ -175,7 +200,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json doendit 'succeeds' do- expect(last_response.status)+ expect(response.status).to eql(200)end@@ -244,12 +269,35 @@ describe 'API v3 Project resource', type: :request, content_type: :json doendit 'returns the projects not matching the value' do- expect(response.body)+ expect(last_response.body).to be_json_eql(other_project.id.to_json).at_path('_embedded/elements/0/id')endendend++ context 'with the project being archived/inactive' do+ let(:project_active) { false }+ let(:projects) { [project] }++ context 'with the user being admin' do+ let(:current_user) { admin }++ it 'responds with 200 OK' do+ expect(last_response.status).to eq(200)+ end++ it_behaves_like 'API V3 collection response', 1, 1, 'Project'+ end++ context 'with the user being no admin' do+ it_behaves_like 'API V3 collection response', 0, 0, 'Project'++ it 'responds with 200' do+ expect(last_response.status).to eq(200)+ end+ end+ endenddescribe '#post /projects' do@@ -680,7 +728,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json dodescribe '#delete /api/v3/projects/:id' dolet(:path) { api_v3_paths.project(project.id) }- let(:setup) { }+ let(:setup) {}before dologin_as current_user