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

Fix/archived projects via api (#8625)

ulferts50daff50629d
diff --git a/app/models/project.rb b/app/models/project.rb
index 976bec97cc4..13daff9812a 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -574,6 +574,6 @@ class Project < ApplicationRecord
end
def remove_white_spaces_from_project_name
- self.name = name.squish unless self.name.nil?
+ self.name = name.squish unless name.nil?
end
end
diff --git a/lib/api/utilities/endpoints/bodied.rb b/lib/api/utilities/endpoints/bodied.rb
index ef2801d4885..535376ce701 100644
--- a/lib/api/utilities/endpoints/bodied.rb
+++ b/lib/api/utilities/endpoints/bodied.rb
@@ -90,7 +90,7 @@ module API
contract_class: process_contract }
process_service
- .new(args.compact)
+ .new(**args.compact)
.call(params)
end
diff --git a/lib/api/v3/projects/projects_api.rb b/lib/api/v3/projects/projects_api.rb
index 97fe1a8aa7b..720f428cf19 100644
--- a/lib/api/v3/projects/projects_api.rb
+++ b/lib/api/v3/projects/projects_api.rb
@@ -30,11 +30,20 @@ module API
module V3
module Projects
class 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 do
get &::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 API
end
route_param :id do
after_validation do
- @project = Project.visible(current_user).find(params[:id])
+ @project = visible_project_scope.find(params[:id])
end
get &::API::V3::Utilities::Endpoints::Show.new(model: Project).mount
diff --git a/lib/open_project/patches/declarative_option.rb b/lib/open_project/patches/declarative_option.rb
index 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::DeclarativeOption
extend ActiveSupport::Concern
diff --git a/spec/requests/api/v3/project_resource_spec.rb b/spec/requests/api/v3/project_resource_spec.rb
index 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 do
let(:current_user) do
FactoryBot.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)
end
let(:other_project) do
FactoryBot.create(:project, public: false)
@@ -150,6 +152,29 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
.at_path('_links/parent/href')
end
end
+
+ 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
+ end
end
context 'not logged in user' do
@@ -175,7 +200,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
end
it '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 do
end
it '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')
end
end
end
+
+ 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
+ end
end
describe '#post /projects' do
@@ -680,7 +728,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
describe '#delete /api/v3/projects/:id' do
let(:path) { api_v3_paths.project(project.id) }
- let(:setup) { }
+ let(:setup) {}
before do
login_as current_user