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
hide projectPhase attribute if there are not active project phases
ulfertsc7556daa89b8
diff --git a/docs/api/apiv3/components/schemas/work_package_model.yml b/docs/api/apiv3/components/schemas/work_package_model.ymlindex 6b61caf2245..7082ac62b4c 100644--- a/docs/api/apiv3/components/schemas/work_package_model.yml+++ b/docs/api/apiv3/components/schemas/work_package_model.yml@@ -423,6 +423,13 @@ properties:The project to which the work package belongs**Resource**: Project+ projectPhase:+ allOf:+ - $ref: "./link.yml"+ - description: |-+ The project phase to which the work package belongs++ **Resource**: ProjectPhaseresponsible:allOf:- $ref: "./link.yml"diff --git a/docs/api/apiv3/components/schemas/work_package_schema_model.yml b/docs/api/apiv3/components/schemas/work_package_schema_model.ymlindex c900a77b087..302cf923d33 100644--- a/docs/api/apiv3/components/schemas/work_package_schema_model.yml+++ b/docs/api/apiv3/components/schemas/work_package_schema_model.yml@@ -64,6 +64,8 @@ properties:$ref: './schema_property_model.yml'project:$ref: './schema_property_model.yml'+ projectPhase:+ $ref: './schema_property_model.yml'parent:$ref: './schema_property_model.yml'assignee:diff --git a/docs/api/apiv3/paths/project_phase.yml b/docs/api/apiv3/paths/project_phase.ymlindex 8930e3c870a..8a3fe14053a 100644--- a/docs/api/apiv3/paths/project_phase.yml+++ b/docs/api/apiv3/paths/project_phase.yml@@ -4,7 +4,7 @@ get:summary: Get a project phaseoperationId: get_project_phasetags:- - Project Phase+ - Project Phasesdescription: |-Gets a project phase resource. This resource contains an instance of a ProjectPhaseDefinition within a project which canthen have project specific dates.diff --git a/docs/api/apiv3/paths/project_phase_definition.yml b/docs/api/apiv3/paths/project_phase_definition.ymlindex 30cad53a75a..e54b3cd3480 100644--- a/docs/api/apiv3/paths/project_phase_definition.yml+++ b/docs/api/apiv3/paths/project_phase_definition.yml@@ -4,7 +4,7 @@ get:summary: Get a project phase definitionoperationId: get_project_phase_definitiontags:- - Project Phase Definition+ - Project Phase Definitionsdescription: |-Gets a project phase definition resource. This resource is part of the abstract definition of a project lifecycle shaping the phases of a project.diff --git a/docs/api/apiv3/tags/project_phase_definitions.yml b/docs/api/apiv3/tags/project_phase_definitions.ymlindex 2755532e129..2feaee73198 100644--- a/docs/api/apiv3/tags/project_phase_definitions.yml+++ b/docs/api/apiv3/tags/project_phase_definitions.yml@@ -29,4 +29,4 @@ description: |-| 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 Phases+name: Project Phase Definitionsdiff --git a/docs/api/apiv3/tags/work_packages.yml b/docs/api/apiv3/tags/work_packages.ymlindex fd0907dc0ef..98c2c311c2e 100644--- a/docs/api/apiv3/tags/work_packages.yml+++ b/docs/api/apiv3/tags/work_packages.yml@@ -20,29 +20,30 @@ description: |-## Linked Properties- | Link | Description | Type | Constraints | Supported operations | Condition |- | :----------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ------------ | --------------------- | ----------------------------------------- |- | self | This work package | WorkPackage | not null | READ | |- | schema | The schema of this work package | Schema | not null | READ | |- | ancestors | Array of all visible ancestors of the work package, with the root node being the first element | Collection | not null | READ | **Permission** view work packages |- | attachments | The files attached to this work package | Collection | not null | READ / WRITE | |- | author | The person that created the work package | User | not null | READ | |- | assignee | The person that is intended to work on the work package | User | | READ / WRITE | |- | availableWatchers | All users that can be added to the work package as watchers. | User | | READ | **Permission** add work package watchers |- | budget | The budget this work package is associated to | Budget | | READ / WRITE | **Permission** view cost objects |- | category | The category of the work package | Category | | READ / WRITE | |- | children | Array of all visible children of the work package | Collection | not null | READ | **Permission** view work packages |- | parent | Parent work package | WorkPackage | Needs to be visible (to the current user) | READ / WRITE | |- | priority | The priority of the work package | Priority | not null | READ / WRITE | |- | project | The project to which the work package belongs | Project | not null | READ / WRITE | |- | responsible | The person that is responsible for the overall outcome | User | | READ / WRITE | |- | relations | Relations this work package is involved in | Relation | | READ | **Permission** view work packages |- | revisions | Revisions that are referencing the work package | Revision | | READ | **Permission** view changesets |- | status | The current status of the work package | Status | not null | READ / WRITE | |- | timeEntries | All time entries logged on the work package. Please note that this is a link to an HTML resource for now and as such, the link is subject to change. | N/A | | READ | **Permission** view time entries |- | type | The type of the work package | Type | not null | READ / WRITE | |- | version | The version associated to the work package | Version | | READ / WRITE | |- | watchers | All users that are currently watching this work package | Collection | | READ | **Permission** view work package watchers |+ | Link | Description | Type | Constraints | Supported operations | Condition |+ | :----------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ------------ | --------------------- | ----------------------------------------- |+ | self | This work package | WorkPackage | not null | READ | |+ | schema | The schema of this work package | Schema | not null | READ | |+ | ancestors | Array of all visible ancestors of the work package, with the root node being the first element | Collection | not null | READ | **Permission** view work packages |+ | attachments | The files attached to this work package | Collection | not null | READ / WRITE | |+ | author | The person that created the work package | User | not null | READ | |+ | assignee | The person that is intended to work on the work package | User | | READ / WRITE | |+ | availableWatchers | All users that can be added to the work package as watchers. | User | | READ | **Permission** add work package watchers |+ | budget | The budget this work package is associated to | Budget | | READ / WRITE | **Permission** view cost objects |+ | category | The category of the work package | Category | | READ / WRITE | |+ | children | Array of all visible children of the work package | Collection | not null | READ | **Permission** view work packages |+ | parent | Parent work package | WorkPackage | Needs to be visible (to the current user) | READ / WRITE | |+ | priority | The priority of the work package | Priority | not null | READ / WRITE | |+ | project | The project to which the work package belongs | Project | not null | READ / WRITE | |+ | projectPhase | The project phase this work package is assigned to | ProjectPhase | | READ / WRITE | **Permission** view project phases. There has to be a project phase active in the project. |+ | responsible | The person that is responsible for the overall outcome | User | | READ / WRITE | |+ | relations | Relations this work package is involved in | Relation | | READ | **Permission** view work packages |+ | revisions | Revisions that are referencing the work package | Revision | | READ | **Permission** view changesets |+ | status | The current status of the work package | Status | not null | READ / WRITE | |+ | timeEntries | All time entries logged on the work package. Please note that this is a link to an HTML resource for now and as such, the link is subject to change. | N/A | | READ | **Permission** view time entries |+ | type | The type of the work package | Type | not null | READ / WRITE | |+ | version | The version associated to the work package | Version | | READ / WRITE | |+ | watchers | All users that are currently watching this work package | Collection | | READ | **Permission** view work package watchers |## Local Propertiesdiff --git a/lib/api/v3/work_packages/schema/base_work_package_schema.rb b/lib/api/v3/work_packages/schema/base_work_package_schema.rbindex fa181776205..a42ec221d0b 100644--- a/lib/api/v3/work_packages/schema/base_work_package_schema.rb+++ b/lib/api/v3/work_packages/schema/base_work_package_schema.rb@@ -51,6 +51,9 @@ module API[]end+ delegate :assignable_project_phases,+ to: :contract+def writable?(property)property = property.to_sreturn false if property == "subject" && type&.replacement_pattern_defined_for?(:subject)diff --git a/lib/api/v3/work_packages/schema/work_package_schema_representer.rb b/lib/api/v3/work_packages/schema/work_package_schema_representer.rbindex bafa5de2398..d7cd2ddeade 100644--- a/lib/api/v3/work_packages/schema/work_package_schema_representer.rb+++ b/lib/api/v3/work_packages/schema/work_package_schema_representer.rb@@ -237,6 +237,7 @@ module APIrequired: false,show_if: ->(*) {current_user.allowed_in_project?(:view_project_phases, represented.project) &&+ represented.assignable_project_phases.any? &&OpenProject::FeatureDecisions.stages_and_gates_active?},writable: -> { represented.writable?(:project_phase_definition_id) }diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rbindex 5024d0d59ca..5bd14163429 100644--- a/lib/api/v3/work_packages/work_package_representer.rb+++ b/lib/api/v3/work_packages/work_package_representer.rb@@ -488,7 +488,7 @@ module APIassociated_resource :projectresource :project_phase,- link_cache_if: -> { view_project_phase_allowed? },+ link_cache_if: -> { any_phase_active_in_project? && view_project_phase_allowed? },link: ->(*) {if phase_set_and_active?{@@ -691,6 +691,10 @@ module APIproject_phase&.active?end+ def any_phase_active_in_project?+ represented.project.phases.any?(&:active?)+ end+def relationsself_path = api_v3_paths.work_package_relations(represented.id)visible_relations = representeddiff --git a/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb b/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rbindex d78c9ae14e5..837138d1cdf 100644--- a/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb+++ b/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb@@ -58,6 +58,9 @@ RSpec.describe API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do.to receive(:assignable_values).with(:version, current_user).and_return([])+ allow(schema)+ .to receive(:assignable_project_phases)+ .and_return(assignable_project_phases)endendlet(:self_link) { "/a/self/link" }@@ -72,6 +75,7 @@ RSpec.describe API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter docurrent_user:)endlet(:available_custom_fields) { [] }+ let(:assignable_project_phases) { [build_stubbed(:project_phase, project:)] }let(:wp_type) { project.types.first }let(:custom_field) { build_stubbed(:custom_field) }let(:work_package) do@@ -846,6 +850,15 @@ RSpec.describe API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter doendend+ context "without any phases active in the project" do+ let(:permissions) { %i[edit_work_packages view_project_phases] }+ let(:assignable_project_phases) { [] }++ it "has no projectPhase attribute" do+ expect(subject).not_to have_json_path("projectPhase")+ end+ end+context "without the view_project_phases permission" doit "has no projectPhase attribute" doexpect(subject).not_to have_json_path("projectPhase")diff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rbindex 6e47b44be04..3c1c1d95261 100644--- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb+++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb@@ -101,8 +101,10 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter do]endlet(:permissions) { all_permissions }- let(:project) { build_stubbed(:project_with_types, phases: project_phase.present? ? [project_phase] : []) }+ let(:project) { build_stubbed(:project_with_types, phases: project_phases) }let(:project_phase) { build_stubbed(:project_phase, definition: project_phase_definition) }+ let(:other_project_phase) { build_stubbed(:project_phase) }+ let(:project_phases) { [project_phase, other_project_phase].compact }let(:project_phase_definition) { build_stubbed(:project_phase_definition) }let(:type) dotype = project.types.first@@ -717,6 +719,24 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter dolet(:link) { "projectPhase" }endend++ context "without any phase existing in the project" do+ let(:project_phases) { [] }++ it_behaves_like "has no link" do+ let(:link) { "projectPhase" }+ end+ end++ context "without any phase active in the project" do+ before do+ project_phases.each { |phase| phase.active = false }+ end++ it_behaves_like "has no link" do+ let(:link) { "projectPhase" }+ end+ endendcontext "without the feature flag being active" do@@ -1370,7 +1390,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doendend- describe "projectPhaseDefinition" do+ describe "projectPhase" dolet(:embedded_path) { "_embedded/projectPhase" }let(:embedded_resource) { project_phase_definition }let(:embedded_resource_type) { "ProjectPhase" }@@ -1389,7 +1409,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doendcontext "with the phase not existing in the project" do- let(:project_phase) { nil }+ let(:project_phases) { [other_project_phase] }it_behaves_like "has the resource not embedded"end