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

Assign `journal_cause` to each WorkPackage in Scheduling

Klaus Zanders7fa0a4d3d8f1
diff --git a/app/models/journal.rb b/app/models/journal.rb
index cc4aa27a4b5..d9a8a5dbd30 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -53,7 +53,11 @@ class Journal < ApplicationRecord
# attributes without a heavy database migration. Fields will be prefixed with `cause_` but are stored in the JSONB
# hash without that prefix
store_accessor :cause, %i[type work_package_id], prefix: true
- VALID_CAUSE_TYPES = %w[work_package_predecessor_changed_times work_package_successor_changed_times].freeze
+ VALID_CAUSE_TYPES = %w[
+ work_package_predecessor_changed_times
+ work_package_successor_changed_times
+ work_package_parent_changed_times
+ ].freeze
# Make sure each journaled model instance only has unique version ids
validates :version, uniqueness: { scope: %i[journable_id journable_type] }
diff --git a/app/services/work_packages/set_schedule_service.rb b/app/services/work_packages/set_schedule_service.rb
index e5517690481..29ddb8bc153 100644
--- a/app/services/work_packages/set_schedule_service.rb
+++ b/app/services/work_packages/set_schedule_service.rb
@@ -70,6 +70,7 @@ class WorkPackages::SetScheduleService
days.due_date(wp.start_date, wp.duration),
wp.due_date
].compact.max
+ assign_cause_for_journaling(wp, :parent)
end
end
end
@@ -123,6 +124,7 @@ class WorkPackages::SetScheduleService
# descendants
def reschedule_by_descendants(scheduled, dependency)
set_dates(scheduled, dependency.start_date, dependency.due_date)
+ assign_cause_for_journaling(scheduled, :predecessor)
end
# Calculates the dates of a work package based on its follows relations.
@@ -148,6 +150,7 @@ class WorkPackages::SetScheduleService
new_start_date = [scheduled.start_date, dependency.soonest_start_date].compact.max
new_due_date = determine_due_date(scheduled, new_start_date)
set_dates(scheduled, new_start_date, new_due_date)
+ assign_cause_for_journaling(scheduled, :successor)
end
def determine_due_date(work_package, start_date)
@@ -175,4 +178,19 @@ class WorkPackages::SetScheduleService
def days(work_package)
WorkPackages::Shared::Days.for(work_package)
end
+
+ def assign_cause_for_journaling(work_package, relation)
+ return if initiating_work_package.nil?
+
+ type_mapping = {
+ parent: 'work_package_parent_changed_times',
+ successor: 'work_package_successor_changed_times',
+ predecessor: 'work_package_predecessor_changed_times'
+ }
+
+ work_package.journal_cause = {
+ type: type_mapping[relation],
+ work_package_id: initiating_work_package.id
+ }
+ end
end