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
[62190] Fix errors when setting type of a parent to milestone
Christophe Bliard9719dc3b5dc5
diff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rbindex 4eb0b0dec57..33687b6d6b3 100644--- a/app/services/work_packages/set_attributes_service.rb+++ b/app/services/work_packages/set_attributes_service.rb@@ -286,6 +286,12 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributesdef update_dates_from_rescheduled_childrenreturn if work_package.schedule_manually?+ # A milestone can't have children. An error will be reported for it.+ # Updating dates from children's dates would add more errors like "due date+ # is different from start date" and confuse the user.+ # Better return and keep dates unified to have only one meaningful error.+ return if work_package_now_milestone?+# do a reschedule call to get the work package dates from the rescheduled childrenservice = WorkPackages::SetScheduleService.new(user: User.current, work_package:, switching_to_automatic_mode: [work_package])service.call(work_package.changes.keys.map(&:to_sym)).resultdiff --git a/spec/services/work_packages/update_service_integration_spec.rb b/spec/services/work_packages/update_service_integration_spec.rbindex 19aef6d69c0..a3f54355662 100644--- a/spec/services/work_packages/update_service_integration_spec.rb+++ b/spec/services/work_packages/update_service_integration_spec.rb@@ -32,7 +32,8 @@ require "spec_helper"RSpec.describe WorkPackages::UpdateService, "integration", type: :model doshared_let(:type) { create(:type_standard) }- shared_let(:project_types) { [type] }+ shared_let(:milestone_type) { create(:type_milestone) }+ shared_let(:project_types) { [type, milestone_type] }shared_let(:project) docreate(:project, types: project_types)end@@ -1300,6 +1301,21 @@ RSpec.describe WorkPackages::UpdateService, "integration", type: :model doendend+ context "when changing the type of a work package with children into a milestone" do+ let_work_packages(<<~TABLE)+ | hierarchy | MTWTFSS | scheduling mode+ | work_package | XXX | automatic+ | child | XXX | manual+ TABLE+ let(:attributes) { { type: milestone_type } }++ it "returns only one error: work package has children and cannot be changed into a milestone (Bug #62190)" do+ expect(subject).to be_failure+ expect(subject.errors.attribute_names).to contain_exactly(:type)+ expect(subject.errors.details).to include(type: [{ error: :cannot_be_milestone_due_to_children }])+ end+ end+describe "removing the parent on a work package which precedes its sibling" dolet_work_packages(<<~TABLE)hierarchy | MTWTFSS | scheduling mode | predecessors