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
link phase instead of defintion in wp representer
ulfertsa8968665483c
diff --git a/frontend/src/app/shared/components/fields/display/display-field.initializer.ts b/frontend/src/app/shared/components/fields/display/display-field.initializer.tsindex e23f28ca92e..8d590f9bebb 100644--- a/frontend/src/app/shared/components/fields/display/display-field.initializer.ts+++ b/frontend/src/app/shared/components/fields/display/display-field.initializer.ts@@ -101,7 +101,7 @@ export function initializeCoreDisplayFields(displayFieldService:DisplayFieldServ.addFieldType(TypeDisplayField, 'type', ['Type']).addFieldType(ResourceDisplayField, 'resource', ['Project',- 'ProjectPhaseDefinition',+ 'ProjectPhase','TimeEntriesActivity','Version','Category',diff --git a/lib/api/v3/project_phases/project_phase_representer.rb b/lib/api/v3/project_phases/project_phase_representer.rbnew file mode 100644index 00000000000..350a0e04ceb--- /dev/null+++ b/lib/api/v3/project_phases/project_phase_representer.rb@@ -0,0 +1,58 @@+# 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 ProjectPhaseRepresenter < ::API::Decorators::Single+ include API::Decorators::DateProperty++ self_link++ link :definition do+ {+ href: api_v3_paths.project_phase_definition(represented.definition_id),+ title: represented.definition.name+ }+ end++ property :id+ property :name++ date_time_property :created_at+ date_time_property :updated_at++ def _type+ "ProjectPhase"+ end+ end+ end+ end+enddiff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rbindex b5c05421278..7c4356c0415 100644--- a/lib/api/v3/utilities/path_helper.rb+++ b/lib/api/v3/utilities/path_helper.rb@@ -327,6 +327,7 @@ module APIresources :project+ show :project_phaseshow :project_phase_definitionshow :project_statusdiff --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 cec3a807c6a..35143a78742 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@@ -227,11 +227,12 @@ module API}# TODO: Turn into schema_with_allowed_link- schema :project_phase_definition,- type: "ProjectPhaseDefinition",+ schema :project_phase,+ type: "ProjectPhase",location: :link,required: false,- name_source: :project_phase+ show_if: ->(*) { current_user.allowed_in_project?(:view_project_phases, represented.project) },+ writable: -> { represented.writable?(:project_phase_definition_id) }schema_with_allowed_link :parent,type: "WorkPackage",diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rbindex 2be5645ef6a..afd2deeceec 100644--- a/lib/api/v3/work_packages/work_package_representer.rb+++ b/lib/api/v3/work_packages/work_package_representer.rb@@ -487,13 +487,13 @@ module APIassociated_resource :project- resource :project_phase_definition,+ resource :project_phase,link_cache_if: -> { view_project_phase_allowed? },link: ->(*) {if phase_set_and_active?{- href: api_v3_paths.project_phase_definition(represented.project_phase_definition_id),- title: represented.project_phase_definition.name+ href: api_v3_paths.project_phase(project_phase.id),+ title: project_phase.name}else{@@ -504,8 +504,8 @@ module API},getter: ->(*) doif embed_links && phase_set_and_active? && view_project_phase_allowed?- API::V3::ProjectPhaseDefinitions::ProjectPhaseDefinitionRepresenter.create(- represented.project_phase_definition, current_user:+ API::V3::ProjectPhases::ProjectPhaseRepresenter.create(+ project_phase, current_user:)endend,@@ -669,12 +669,16 @@ module APIcurrent_user.allowed_in_project?(:add_work_packages, represented.project)end- def phase_set_and_active?- represented.project&.phases&.any? do- it.definition_id == represented.project_phase_definition_id && it.active?+ def project_phase+ @project_phase ||= represented.project&.phases&.detect do+ it.definition_id == represented.project_phase_definition_idendend+ def phase_set_and_active?+ project_phase&.active?+ end+def relationsself_path = api_v3_paths.work_package_relations(represented.id)visible_relations = representeddiff --git a/spec/features/work_packages/project_phases/linking_spec.rb b/spec/features/work_packages/project_phases/linking_spec.rbindex 52e3dfb5477..ee4885ff58c 100644--- a/spec/features/work_packages/project_phases/linking_spec.rb+++ b/spec/features/work_packages/project_phases/linking_spec.rb@@ -51,9 +51,11 @@ RSpec.describe "Linking Projects phases and work packages settings", :js, with_flet(:work_package_page) { Pages::FullWorkPackage.new(work_package) }- it "allows seeing linked phases" do+ it "allows seeing and editing linked phases" dowork_package_page.visit!work_package_page.expect_attributes(project_phase_definition: executing_phase_definition.name)++ work_package_page.set_attributes({ project_phase_definition: initiating_phase_definition.name })endenddiff --git a/spec/lib/api/v3/project_phases/project_phase_representer_spec.rb b/spec/lib/api/v3/project_phases/project_phase_representer_spec.rbnew file mode 100644index 00000000000..cebf38c2c6f--- /dev/null+++ b/spec/lib/api/v3/project_phases/project_phase_representer_spec.rb@@ -0,0 +1,91 @@+# 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::ProjectPhaseRepresenter, "rendering" do+ include API::V3::Utilities::PathHelper++ let(:current_user) { build_stubbed(:user) }+ let(:definition) { build_stubbed(:project_phase_definition, :with_gates) }+ let(:project) { build_stubbed(:project) }+ let(:phase) { build_stubbed(:project_phase, definition:, project:) }+ let(:representer) do+ described_class.create(phase, current_user:, embed_links: true)+ end++ subject { representer.to_json }++ describe "_links" do+ describe "self" do+ it_behaves_like "has a titled link" do+ let(:link) { "self" }+ let(:href) { api_v3_paths.project_phase phase.id }+ let(:title) { phase.name }+ end+ end++ describe "definition" do+ it_behaves_like "has a titled link" do+ let(:link) { "definition" }+ let(:href) { api_v3_paths.project_phase_definition definition.id }+ let(:title) { definition.name }+ end+ end+ end++ describe "properties" do+ it_behaves_like "property", :_type do+ let(:value) { "ProjectPhase" }+ end++ it_behaves_like "property", :id do+ let(:value) { phase.id }+ end++ it_behaves_like "property", :name do+ let(:value) { phase.name }+ end++ describe "createdAt" do+ it_behaves_like "has UTC ISO 8601 date and time" do+ let(:date) { phase.created_at }+ let(:json_path) { "createdAt" }+ end+ end++ describe "updatedAt" do+ it_behaves_like "has UTC ISO 8601 date and time" do+ let(:date) { phase.updated_at }+ let(:json_path) { "updatedAt" }+ end+ end+ end+enddiff --git a/spec/lib/api/v3/utilities/path_helper_spec.rb b/spec/lib/api/v3/utilities/path_helper_spec.rbindex 70a9772011a..8ded9624f35 100644--- a/spec/lib/api/v3/utilities/path_helper_spec.rb+++ b/spec/lib/api/v3/utilities/path_helper_spec.rb@@ -296,6 +296,10 @@ RSpec.describe API::V3::Utilities::PathHelper doendend+ describe "project phase paths" do+ it_behaves_like "show", :project_phase+ end+describe "project phase definition paths" doit_behaves_like "show", :project_phase_definitionenddiff --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 f30b89f7531..363ec9bbf82 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@@ -831,8 +831,8 @@ RSpec.describe API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter dolet(:permissions) { %i[edit_work_packages view_project_phases] }it_behaves_like "has basic schema properties" do- let(:path) { "projectPhaseDefinition" }- let(:type) { "ProjectPhaseDefinition" }+ let(:path) { "projectPhase" }+ let(:type) { "ProjectPhase" }let(:name) { I18n.t("attributes.project_phase") }let(:required) { false }let(:writable) { false }@@ -844,8 +844,8 @@ RSpec.describe API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter dolet(:permissions) { %i[edit_work_packages view_project_phases edit_project_phases] }it_behaves_like "has basic schema properties" do- let(:path) { "projectPhaseDefinition" }- let(:type) { "ProjectPhaseDefinition" }+ let(:path) { "projectPhase" }+ let(:type) { "ProjectPhase" }let(:name) { I18n.t("attributes.project_phase") }let(:required) { false }let(:writable) { true }@@ -853,9 +853,9 @@ RSpec.describe API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter doendend- context "without the view_project_phases permission view time_entries permission" do- it "has no spentTime attribute" do- expect(subject).not_to have_json_path("projectPhaseDefinitions")+ context "without the view_project_phases permission" do+ it "has no projectPhase attribute" do+ expect(subject).not_to have_json_path("projectPhase")endendenddiff --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 c6188e49b5f..f0ea986733f 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@@ -674,22 +674,22 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doendend- describe "projectPhaseDefinition" do+ describe "projectPhase" do+ context "with a phase being set" do+ it_behaves_like "has a titled link" do+ let(:link) { "projectPhase" }+ let(:href) { api_v3_paths.project_phase(project_phase.id) }+ let(:title) { project_phase.name }+ end+ end+context "without a phase being set" dobefore dowork_package.project_phase_definition = nilendit_behaves_like "has an empty link" do- let(:link) { "projectPhaseDefinition" }- end- end-- context "with a phase being set" do- it_behaves_like "has a titled link" do- let(:link) { "projectPhaseDefinition" }- let(:href) { api_v3_paths.project_phase_definition(project_phase_definition.id) }- let(:title) { project_phase_definition.name }+ let(:link) { "projectPhase" }endend@@ -697,7 +697,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter dolet(:project_phase) { nil }it_behaves_like "has an empty link" do- let(:link) { "projectPhaseDefinition" }+ let(:link) { "projectPhase" }endend@@ -705,7 +705,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter dolet(:project_phase) { build_stubbed(:project_phase, active: false, definition: project_phase_definition) }it_behaves_like "has an empty link" do- let(:link) { "projectPhaseDefinition" }+ let(:link) { "projectPhase" }endend@@ -713,7 +713,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter dolet(:permissions) { all_permissions - [:view_project_phases] }it_behaves_like "has no link" do- let(:link) { "projectPhaseDefinition" }+ let(:link) { "projectPhase" }endendend@@ -1363,9 +1363,13 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doenddescribe "projectPhaseDefinition" do- let(:embedded_path) { "_embedded/projectPhaseDefinition" }+ let(:embedded_path) { "_embedded/projectPhase" }let(:embedded_resource) { project_phase_definition }- let(:embedded_resource_type) { "ProjectPhaseDefinition" }+ let(:embedded_resource_type) { "ProjectPhase" }++ context "with a phase being set" do+ it_behaves_like "has the resource embedded"+ endcontext "without a phase being set" dobefore do@@ -1375,10 +1379,6 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doit_behaves_like "has the resource not embedded"end- context "with a phase being set" do- it_behaves_like "has the resource embedded"- end-context "with the phase not existing in the project" dolet(:project_phase) { nil }