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
prevent setting dates twice for new work packages
ulferts4a58428459cc
diff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rbindex a8a6ef0eda5..6b575eb8c1d 100644--- a/app/services/work_packages/set_attributes_service.rb+++ b/app/services/work_packages/set_attributes_service.rb@@ -36,18 +36,10 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributesset_static_attributes(attributes)model.change_by_system do- set_default_attributes(attributes)- update_project_dependent_attributes+ set_calculated_attributes(attributes)endset_custom_attributes(attributes)-- model.change_by_system do- update_dates- update_duration- reassign_invalid_status_if_type_changed- set_templated_description- endenddef set_static_attributes(attributes)@@ -58,9 +50,19 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributeswork_package.attributes = assignable_attributesend- def set_default_attributes(attributes)- return unless work_package.new_record?+ def set_calculated_attributes(attributes)+ if work_package.new_record?+ set_default_attributes(attributes)+ else+ update_dates+ end+ update_duration+ update_project_dependent_attributes+ reassign_invalid_status_if_type_changed+ set_templated_description+ end+ def set_default_attributes(attributes)set_default_priorityset_default_authorset_default_statusdiff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rbindex 74785b35a50..50b17ca0b18 100644--- a/spec/services/work_packages/set_attributes_service_spec.rb+++ b/spec/services/work_packages/set_attributes_service_spec.rb@@ -331,6 +331,33 @@ describe WorkPackages::SetAttributesService, type: :model doendend+ context 'with the parent having dates and not providing own dates and with the parent`s' \+ 'soonest_start being before the start_date (e.g. because the parent is manually scheduled)' do+ let(:call_attributes) { { parent: } }++ before do+ allow(parent)+ .to receive(:soonest_start)+ .and_return(parent_start_date + 3.days)+ end++ it_behaves_like 'service call' do+ it "sets the start_date to the parent`s start_date" do+ subject++ expect(work_package.start_date)+ .to eql parent_start_date+ end++ it "sets the due_date to the parent`s due_date" do+ subject++ expect(work_package.due_date)+ .to eql parent_due_date+ end+ end+ end+context 'with the parent having start date (no due) and not providing own dates' dolet(:call_attributes) { { parent: } }let(:parent_due_date) { nil }