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

add a project phase show endpoint

ulferts3bf846be9ff5
diff --git a/docs/api/apiv3/tags/project_phases.yml b/docs/api/apiv3/tags/project_phases.yml
new file mode 100644
index 00000000000..e4b0992b9a7
--- /dev/null
+++ b/docs/api/apiv3/tags/project_phases.yml
@@ -0,0 +1,33 @@
+---
+description: |-
+ Project phases separate the whole of the project's duration into smaller, distinct parts where each phase has its own start and end date.
+ Such a phase will then have different focus on certain aspects of project management. E.g. while the first phase might be about gathering requirements, the second phase might be about implementing the requirements
+ and the third phase might be about testing the implementation.
+
+ Phases within a project are concrete instances of a phase definition. That way, one or a number of project life cycles can be defined throughout the OpenProject instance and then be reused in different projects.
+ Projects can enable or disable the use of a phase definition in a project and assign dates to the phase instances.
+
+ ## Actions
+
+ * None currently
+
+ ## Linked Properties
+
+ | Link | Description | Type | Constraints | Supported operations |Condition |
+ | :----------: | ------------- | ---- | ----------- | -------------------- |----------------------------------------- |
+ | self | This project phase | ProjectPhase | not null | READ | |
+ | definition | This definition this phase relies on | ProjectPhaseDefinition | not null | READ | |
+ | project | This project this phase is instantiated in | Project | not null | READ | |
+
+ ## Local Properties
+
+ | Property | Description | Type | Constraints | Supported operations |
+ | :---------------------:| ------------- | ---- | ----------- | -------------------- |
+ | id | Project phase's id | Integer | x > 0 | READ/WRITE |
+ | name | | String | | READ/WRITE |
+ | active | Indicates whether the project phase is currently active within the project | Boolean | | READ/WRITE |
+ | createdAt | Time of creation | DateTime | | READ |
+ | updatedAt | Time of the most recent change to the project phase | DateTime | | READ |
+
+ Depending on custom fields defined for projects, additional properties might exist.
+name: Project Phases
diff --git a/lib/api/v3/project_phases/project_phase_representer.rb b/lib/api/v3/project_phases/project_phase_representer.rb
index 350a0e04ceb..9afa84905bd 100644
--- a/lib/api/v3/project_phases/project_phase_representer.rb
+++ b/lib/api/v3/project_phases/project_phase_representer.rb
@@ -43,8 +43,16 @@ module API
}
end
+ link :project do
+ {
+ href: api_v3_paths.project(represented.project_id),
+ title: represented.project.name
+ }
+ end
+
property :id
property :name
+ property :active
date_time_property :created_at
date_time_property :updated_at
diff --git a/lib/api/v3/project_phases/project_phases_api.rb b/lib/api/v3/project_phases/project_phases_api.rb
new file mode 100644
index 00000000000..4e26824a867
--- /dev/null
+++ b/lib/api/v3/project_phases/project_phases_api.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+# ++
+
+module API
+ module V3
+ module ProjectPhases
+ class ProjectPhasesAPI < ::API::OpenProjectAPI
+ resources :project_phases do
+ route_param :id do
+ after_validation do
+ @phase = ::Project::Phase.visible(current_user).find(params[:id])
+ end
+
+ get &::API::V3::Utilities::Endpoints::Show
+ .new(model: ::Project::Phase,
+ render_representer: API::V3::ProjectPhases::ProjectPhaseRepresenter)
+ .mount
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/api/v3/root.rb b/lib/api/v3/root.rb
index a30041f486f..c7f353c71a9 100644
--- a/lib/api/v3/root.rb
+++ b/lib/api/v3/root.rb
@@ -66,6 +66,7 @@ module API
mount ::API::V3::Principals::PrincipalsAPI
mount ::API::V3::Priorities::PrioritiesAPI
mount ::API::V3::Projects::ProjectsAPI
+ mount ::API::V3::ProjectPhases::ProjectPhasesAPI
mount ::API::V3::Projects::Statuses::StatusesAPI
mount ::API::V3::Queries::QueriesAPI
mount ::API::V3::Render::RenderAPI
diff --git a/spec/lib/api/v3/project_phases/project_phase_representer_spec.rb b/spec/lib/api/v3/project_phases/project_phase_representer_spec.rb
index cebf38c2c6f..65ad20316a8 100644
--- a/spec/lib/api/v3/project_phases/project_phase_representer_spec.rb
+++ b/spec/lib/api/v3/project_phases/project_phase_representer_spec.rb
@@ -59,6 +59,14 @@ RSpec.describe API::V3::ProjectPhases::ProjectPhaseRepresenter, "rendering" do
let(:title) { definition.name }
end
end
+
+ describe "project" do
+ it_behaves_like "has a titled link" do
+ let(:link) { "project" }
+ let(:href) { api_v3_paths.project project.id }
+ let(:title) { project.name }
+ end
+ end
end
describe "properties" do
@@ -74,6 +82,10 @@ RSpec.describe API::V3::ProjectPhases::ProjectPhaseRepresenter, "rendering" do
let(:value) { phase.name }
end
+ it_behaves_like "property", :active do
+ let(:value) { phase.active }
+ end
+
describe "createdAt" do
it_behaves_like "has UTC ISO 8601 date and time" do
let(:date) { phase.created_at }
diff --git a/spec/requests/api/v3/project_phases/show_resource_spec.rb b/spec/requests/api/v3/project_phases/show_resource_spec.rb
new file mode 100644
index 00000000000..21fecddce7c
--- /dev/null
+++ b/spec/requests/api/v3/project_phases/show_resource_spec.rb
@@ -0,0 +1,68 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+# ++
+
+require "spec_helper"
+
+RSpec.describe API::V3::ProjectPhases::ProjectPhasesAPI, "show", content_type: :json do # rubocop:disable RSpec/SpecFilePathFormat
+ include API::V3::Utilities::PathHelper
+
+ shared_let(:user) { create(:user) }
+ shared_let(:role) { create(:project_role, permissions: %i(view_project_phases)) }
+ shared_let(:project) do
+ create(:project,
+ members: { user => role })
+ end
+ shared_let(:project_phase) { create(:project_phase, project:) }
+
+ let(:send_request) do
+ get api_v3_paths.project_phase(project_phase.id)
+ end
+
+ current_user { user }
+
+ context "with an authorized user" do
+ before do
+ send_request
+ end
+
+ it_behaves_like "successful response"
+ end
+
+ context "with an unauthorized user" do
+ before do
+ role.permissions = role.permissions - [:view_project_phases]
+ role.save!
+
+ send_request
+ end
+
+ it_behaves_like "not found"
+ end
+end