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
add a project phase definition show endpoint
ulfertsb49977bbb7ce
diff --git a/docs/api/apiv3/components/schemas/project_phase_definition_model.yml b/docs/api/apiv3/components/schemas/project_phase_definition_model.ymlnew file mode 100644index 00000000000..cf185d0b3f7--- /dev/null+++ b/docs/api/apiv3/components/schemas/project_phase_definition_model.yml@@ -0,0 +1,63 @@+# Schema: ProjectPhaseDefinitionModel+---+type: object+required:+ - _type+ - id+ - name+ - startGate+ - finishGate+ - createdAt+ - updatedAt+properties:+ _type:+ type: string+ enum:+ - ProjectPhaseDefinition+ id:+ type: integer+ description: The project phase definition's id+ minimum: 1+ name:+ type: string+ startGate:+ type: boolean+ startGateName:+ type: string+ finishGate:+ type: boolean+ finishGateName:+ type: string+ createdAt:+ type: string+ format: date-time+ description: Time of creation+ updatedAt:+ type: string+ format: date-time+ description: Time of the most recent change to the project phase definition+ _links:+ type: object+ required:+ - self+ properties:+ self:+ allOf:+ - $ref: './link.yml'+ - description: |-+ This project phase definition.++ **Resource**: ProjectPhaseDefinition+example:+ _type: 'ProjectPhaseDefinition'+ id: 1337+ title: 'Initiating'+ startGate: true+ startGateName: "Before Initiating"+ finishGate: true+ finishGateName: null+ createdAt: '2023-01-20T14:30:00.368Z'+ updatedAt: '2023-05-23T11:57:48.618Z'+ _links:+ self:+ href: '/api/v3/project_phase_definitions/23'diff --git a/docs/api/apiv3/components/schemas/project_phase_model.yml b/docs/api/apiv3/components/schemas/project_phase_model.ymlindex dc1174d17c7..5bf396ba9df 100644--- a/docs/api/apiv3/components/schemas/project_phase_model.yml+++ b/docs/api/apiv3/components/schemas/project_phase_model.yml@@ -18,6 +18,8 @@ properties:description: The project phase's idminimum: 1name:+ type: string+ active:type: booleancreatedAt:type: stringdiff --git a/docs/api/apiv3/openapi-spec.yml b/docs/api/apiv3/openapi-spec.ymlindex 81390420184..bda80abbc7f 100644--- a/docs/api/apiv3/openapi-spec.yml+++ b/docs/api/apiv3/openapi-spec.yml@@ -296,6 +296,8 @@ paths:"$ref": "./paths/priority.yml""/api/v3/project_phase":"$ref": "./paths/project_phase.yml"+ "/api/v3/project_phase_definition":+ "$ref": "./paths/project_phase_definition.yml""/api/v3/project_storages":"$ref": "./paths/project_storages.yml""/api/v3/project_storages/{id}":@@ -779,6 +781,8 @@ components:"$ref": "./components/schemas/project_model.yml"ProjectPhaseModel:"$ref": "./components/schemas/project_phase_model.yml"+ ProjectPhaseDefinitionModel:+ "$ref": "./components/schemas/project_phase_definition_model.yml"ProjectStorageCollectionModel:"$ref": "./components/schemas/project_storage_collection_model.yml"ProjectStorageModel:@@ -958,6 +962,8 @@ tags:- "$ref": "./tags/posts.yml"- "$ref": "./tags/principals.yml"- "$ref": "./tags/priorities.yml"+ - "$ref": "./tags/project_phases.yml"+ - "$ref": "./tags/project_phase_definitions.yml"- "$ref": "./tags/projects.yml"- "$ref": "./tags/queries.yml"- "$ref": "./tags/query_columns.yml"diff --git a/docs/api/apiv3/paths/project_phase_definition.yml b/docs/api/apiv3/paths/project_phase_definition.ymlnew file mode 100644index 00000000000..30cad53a75a--- /dev/null+++ b/docs/api/apiv3/paths/project_phase_definition.yml@@ -0,0 +1,38 @@+# /api/v3/project_phase_definitions/{id}+---+get:+ summary: Get a project phase definition+ operationId: get_project_phase_definition+ tags:+ - Project Phase Definition+ description: |-+ Gets a project phase definition resource. This resource is part of the abstract definition of a project life+ cycle shaping the phases of a project.+ parameters:+ - name: id+ description: Project phase definition id+ in: path+ required: true+ schema:+ type: integer+ example: 1337+ responses:+ '200':+ description: OK+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/project_phase_definition_model.yml'+ '404':+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/error_response.yml'+ example:+ _type: Error+ errorIdentifier: urn:openproject-org:api:v3:errors:MissingPermission+ message: You are not authorized to access this resource.+ description: |-+ Returned if the user does not have permission to see project phases.++ **Required permission:** view project phase OR select project phasediff --git a/docs/api/apiv3/tags/project_phase_definitions.yml b/docs/api/apiv3/tags/project_phase_definitions.ymlnew file mode 100644index 00000000000..2755532e129--- /dev/null+++ b/docs/api/apiv3/tags/project_phase_definitions.yml@@ -0,0 +1,32 @@+---+description: |-+ Project phases separate the whole of the project's duration into smaller, distinct parts.+ 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.++ The phases within the projects rely on an abstract definition of the project life cycle valid in a number of projects within the OpenProject instance.+ That definition is a set of ProjectPhaseDefinitions.++ ## Actions++ * None currently++ ## Linked Properties++ | Link | Description | Type | Constraints | Supported operations |Condition |+ | :----------: | ------------- | ---- | ----------- | -------------------- |----------------------------------------- |+ | self | This project phase definition | ProjectPhaseDefinition | not null | READ | |++ ## Local Properties++ | Property | Description | Type | Constraints | Supported operations |+ |--------------- |-------------------------------------------------------------|-----------|-------------|----------------------|+ | id | Project phase definition's id | Integer | x > 0 | READ |+ | name | | String | | READ |+ | startGate | Indicates whether the project phase has a gate at the start | Boolean | | READ |+ | startGateName | The name of the gate at the start of the phase | String | | READ |+ | finishGate | Indicates whether the project phase has a gate at the end | Boolean | | READ |+ | finishGateName | The name of the gate at the end of the phase | String | | READ |+ | createdAt | Time of creation | DateTime | | READ |+ | updatedAt | Time of the most recent change to the project phase | DateTime | | READ |+name: Project Phasesdiff --git a/docs/api/apiv3/tags/project_phases.yml b/docs/api/apiv3/tags/project_phases.ymlindex e4b0992b9a7..0d7a982baa5 100644--- a/docs/api/apiv3/tags/project_phases.yml+++ b/docs/api/apiv3/tags/project_phases.yml@@ -23,11 +23,9 @@ description: |-| 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 |+ | id | Project phase's id | Integer | x > 0 | READ |+ | name | | String | | READ |+ | active | Indicates whether the project phase is currently active within the project | Boolean | | READ || 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 Phasesdiff --git a/lib/api/v3/project_phase_definitions/project_phase_definitions_api.rb b/lib/api/v3/project_phase_definitions/project_phase_definitions_api.rbnew file mode 100644index 00000000000..2193579c84c--- /dev/null+++ b/lib/api/v3/project_phase_definitions/project_phase_definitions_api.rb@@ -0,0 +1,54 @@+# 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 ProjectPhaseDefinitions+ class ProjectPhaseDefinitionsAPI < ::API::OpenProjectAPI+ resources :project_phase_definitions do+ after_validation do+ authorize_in_any_project(%i[view_project_phases select_project_phases])+ end++ route_param :id do+ after_validation do+ @phase_definition = ::Project::PhaseDefinition.find(params[:id])+ end++ get &::API::V3::Utilities::Endpoints::Show+ .new(model: ::Project::PhaseDefinition,+ render_representer: API::V3::ProjectPhaseDefinitions::ProjectPhaseDefinitionRepresenter)+ .mount+ end+ end+ end+ end+ end+enddiff --git a/lib/api/v3/root.rb b/lib/api/v3/root.rbindex c7f353c71a9..f7a31d47c29 100644--- a/lib/api/v3/root.rb+++ b/lib/api/v3/root.rb@@ -66,6 +66,7 @@ module APImount ::API::V3::Principals::PrincipalsAPImount ::API::V3::Priorities::PrioritiesAPImount ::API::V3::Projects::ProjectsAPI+ mount ::API::V3::ProjectPhaseDefinitions::ProjectPhaseDefinitionsAPImount ::API::V3::ProjectPhases::ProjectPhasesAPImount ::API::V3::Projects::Statuses::StatusesAPImount ::API::V3::Queries::QueriesAPIdiff --git a/spec/requests/api/v3/project_phase_definitions/show_resource_spec.rb b/spec/requests/api/v3/project_phase_definitions/show_resource_spec.rbnew file mode 100644index 00000000000..03ec115f0db--- /dev/null+++ b/spec/requests/api/v3/project_phase_definitions/show_resource_spec.rb@@ -0,0 +1,90 @@+# 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::ProjectPhaseDefinitions::ProjectPhaseDefinitionsAPI, "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 select_project_phases)) }+ shared_let(:project) do+ create(:project,+ members: { user => role })+ end+ shared_let(:project_phase_definition) { create(:project_phase_definition) }++ let(:send_request) do+ get api_v3_paths.project_phase_definition(project_phase_definition.id)+ end++ current_user { user }++ context "with an authorized user" do+ before do+ send_request+ end++ it_behaves_like "successful response", 200, "ProjectPhaseDefinition"+ end++ context "with a user only having the view_project_phases permission" do+ before do+ role.permissions = role.permissions - %i[select_project_phases]+ role.save!++ send_request+ end++ it_behaves_like "successful response", 200, "ProjectPhaseDefinition"+ end++ context "with a user only having the select_project_phases permission" do+ before do+ role.permissions = role.permissions - %i[view_project_phases]+ role.save!++ send_request+ end++ it_behaves_like "successful response", 200, "ProjectPhaseDefinition"+ end++ context "with an unauthorized user" do+ before do+ role.permissions = role.permissions - %i[view_project_phases select_project_phases]+ role.save!++ send_request+ end++ it_behaves_like "unauthorized access"+ end+enddiff --git a/spec/requests/api/v3/support/response_examples.rb b/spec/requests/api/v3/support/response_examples.rbindex b762bdc7361..22fc639ee34 100644--- a/spec/requests/api/v3/support/response_examples.rb+++ b/spec/requests/api/v3/support/response_examples.rb@@ -28,7 +28,7 @@require "spec_helper"-RSpec.shared_examples_for "successful response" do |code = 200|+RSpec.shared_examples_for "successful response" do |code = 200, type = nil|it "has the status code #{code}" doexpect(last_response).to have_http_status(code)end@@ -38,6 +38,12 @@ RSpec.shared_examples_for "successful response" do |code = 200|expect(last_response.headers).to include "Content-Type"expect(last_response.headers["Content-Type"].downcase).to eql expected_content_typeend++ if type+ it "returns a resource of _type #{type}" do+ expect(last_response.body).to be_json_eql(type.to_json).at_path("_type")+ end+ endendRSpec.shared_examples_for "successful no content response" do |code = 204|