Skip to content

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

ensure project status is saved (#9325)

ulferts20a9f91a22a6
diff --git a/app/services/projects/update_service.rb b/app/services/projects/update_service.rb
index b86c2b8031e..ec8fd85615e 100644
--- a/app/services/projects/update_service.rb
+++ b/app/services/projects/update_service.rb
@@ -44,12 +44,18 @@ module Projects
ret
end
+ def persist(service_result)
+ # Needs to take place before awesome_nested_set reloads the model (in case the parent changes)
+ persist_status
+
+ super
+ end
+
def after_perform(service_call)
touch_on_custom_values_update
notify_on_identifier_renamed
send_update_notification
update_wp_versions_on_parent_change
- persist_status
handle_archiving
service_call
diff --git a/spec/services/projects/update_service_integration_spec.rb b/spec/services/projects/update_service_integration_spec.rb
index 2eb588c0891..15b4257ed60 100644
--- a/spec/services/projects/update_service_integration_spec.rb
+++ b/spec/services/projects/update_service_integration_spec.rb
@@ -42,9 +42,15 @@ describe Projects::UpdateService, 'integration', type: :model do
%i(edit_project)
end
- let!(:project) { FactoryBot.create(:project, "custom_field_#{custom_field.id}" => 1) }
+ let!(:project) do
+ FactoryBot.create(:project,
+ "custom_field_#{custom_field.id}" => 1,
+ status: project_status)
+ end
let(:instance) { described_class.new(user: user, model: project) }
let(:custom_field) { FactoryBot.create(:int_project_custom_field) }
+ let(:project_status) { nil }
+
let(:attributes) { {} }
let(:service_result) do
instance
@@ -87,5 +93,33 @@ describe Projects::UpdateService, 'integration', type: :model do
.not_to eql later_updated_at
end
end
+
+ context 'when saving the status as well as the parent' do
+ let(:parent_project) { FactoryBot.create(:project, members: { user => parent_role }) }
+ let(:parent_role) { FactoryBot.create :role, permissions: %i(add_subprojects) }
+ let(:project_status) { FactoryBot.create(:project_status, code: 'on_track') }
+ let(:attributes) do
+ {
+ parent_id: parent_project.id,
+ status: {
+ code: 'off_track'
+ }
+ }
+ end
+
+ it 'updates both the status as well as the parent' do
+ # This is made difficult by awesome_nested_set reloading the project after saving.
+ # Because of the reloading, unpersisted changes to status get lost.
+ service_result
+
+ project.reload
+
+ expect(project.parent)
+ .to eql parent_project
+
+ expect(project.status)
+ .to be_off_track
+ end
+ end
end
end