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
allow copying associated phase definitions on copy base permission
ulfertsff61d77ec3b6
diff --git a/app/contracts/work_packages/copy_contract.rb b/app/contracts/work_packages/copy_contract.rbindex 8b41516579d..6432b42ad8e 100644--- a/app/contracts/work_packages/copy_contract.rb+++ b/app/contracts/work_packages/copy_contract.rb@@ -37,10 +37,24 @@ module WorkPackagesattribute :done_ratio,writable: true+ # Overriding the definition in the CreateContract to allow copying based on the default+ # permission of :add_work_packages.+ attribute :project_phase_definition_id,+ writable: ->(*) {+ OpenProject::FeatureDecisions.stages_and_gates_active?+ },+ permission: :add_work_packages+# Do not validate predecessors or children presence when copying: when# copying, it's possible to create a work package in automatic scheduling# mode even if it has no predecessors or children yet. They will be added# later in the process.def validate_has_predecessors_or_children; end++ # No validation happening on whether the phase is active in the project.+ # When copying a work package, e.g. from a project template, the phase+ # might not be active in the project yet. But when it is activated later,+ # the value should then be present.+ def validate_phase_active_in_project; endendenddiff --git a/spec/services/projects/copy_service_integration_spec.rb b/spec/services/projects/copy_service_integration_spec.rbindex a127a2fd196..24d49fb8062 100644--- a/spec/services/projects/copy_service_integration_spec.rb+++ b/spec/services/projects/copy_service_integration_spec.rb@@ -887,6 +887,25 @@ RSpec.describe(expect(duplicates_relation.to_id).to eq other_wp.idendend++ context "with project phases associated", with_flag: { stages_and_gates: true } do+ before do+ source_wp.update_column(:project_phase_definition_id, source_project_phase.definition_id)+ end++ it "copies the project phase (regardless of the phase not being copied itself)" do+ expect(subject).to be_success+ expect(project_copy.work_packages.count).to eq(2)++ copied_wp = project_copy.work_packages.find_by(subject: source_wp.subject)+ expect(copied_wp.project_phase_definition_id).to eq(source_project_phase.definition_id)++ [source_wp, source_wp_locked].each do |wp|+ copied_wp = project_copy.work_packages.find_by(subject: wp.subject)+ expect(copied_wp.project_phase_definition_id).to eq(wp.project_phase_definition_id)+ end+ end+ endendcontext "with wiki" dodiff --git a/spec/services/work_packages/copy_service_integration_spec.rb b/spec/services/work_packages/copy_service_integration_spec.rbindex 09b0cfed528..8cec5ea620e 100644--- a/spec/services/work_packages/copy_service_integration_spec.rb+++ b/spec/services/work_packages/copy_service_integration_spec.rb@@ -48,8 +48,9 @@ RSpec.describe WorkPackages::CopyService, "integration", type: :model doset_factory_default(:user, user)end+ shared_let(:project_phase_definition) { create(:project_phase_definition) }shared_let(:work_package) do- create(:work_package, author: user, project:, type:)+ create(:work_package, author: user, project:, type:, project_phase_definition:)endlet(:instance) { described_class.new(work_package:, user:) }@@ -105,6 +106,13 @@ RSpec.describe WorkPackages::CopyService, "integration", type: :model do.to contain_exactly(watcher_user)endend++ describe "#project_phase_definition", with_flag: { stages_and_gates: true } do+ it "is the one of the copied work package" do+ expect(copy.project_phase_definition)+ .to eql project_phase_definition+ end+ endenddescribe "to a different project" do@@ -196,6 +204,13 @@ RSpec.describe WorkPackages::CopyService, "integration", type: :model doendend+ describe "#project_phase_definition", with_flag: { stages_and_gates: true } do+ it "is the one of the copied work package" do+ expect(copy.project_phase_definition)+ .to eql project_phase_definition+ end+ end+describe "#attributes" dobefore dotarget_project.types << work_package.type