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

Merge branch 'dev' into feature/40749-consistent-calculation-of-percent-complete

Christophe Bliard010f264f1c7d
diff --cc lib_static/plugins/acts_as_journalized/lib/journal_changes.rb
index 6ffb3f15ef2,06a7c7a65cc..12f482f452e
--- a/lib_static/plugins/acts_as_journalized/lib/journal_changes.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/journal_changes.rb
@@@ -31,73 -31,71 +31,89 @@@ module JournalChange
return @changes if @changes
return {} if data.nil?
- @changes = ::Acts::Journalized::JournableDiffer.changes(predecessor&.data, data)
-
- @changes[:cause] = [nil, cause] if cause.present?
-
- if journable&.attachable?
- @changes.merge!(
- ::Acts::Journalized::JournableDiffer.association_changes(
- predecessor,
- self,
- 'attachable_journals',
- 'attachments',
- :attachment_id,
- :filename
- )
- )
- end
+ changes = [
+ get_cause_changes,
+ get_data_changes,
+ get_attachments_changes,
+ get_custom_fields_changes,
+ get_file_links_changes,
+ get_agenda_items_changes
+ ].compact
- if journable&.customizable?
- customizable_changes = ::Acts::Journalized::JournableDiffer.association_changes(
- predecessor,
- self,
- 'customizable_journals',
- 'custom_fields',
- :custom_field_id,
- :value
- )
-
- if journable.class.name == "Project"
- remove_disabled_project_custom_fields!(customizable_changes)
- end
-
- @changes.merge!(customizable_changes)
- end
+ @changes = changes.reduce({}.with_indifferent_access, :merge!)
+ end
- if has_file_links?
- @changes.merge!(
- ::Acts::Journalized::FileLinkJournalDiffer.get_changes_to_file_links(
- predecessor,
- storable_journals
- )
- )
- end
+ def get_cause_changes
+ return if cause.blank?
+
+ { cause: [nil, cause] }
+ end
+
+ def get_data_changes
+ ::Acts::Journalized::JournableDiffer.changes(predecessor&.data, data)
+ end
+
+ def get_attachments_changes
+ return unless journable&.attachable?
+
+ ::Acts::Journalized::JournableDiffer.association_changes(
+ predecessor,
+ self,
+ "attachable_journals",
+ "attachments",
+ :attachment_id,
+ :filename
+ )
+ end
+
+ def get_custom_fields_changes
+ return unless journable&.customizable?
+
- ::Acts::Journalized::JournableDiffer.association_changes(
++ customizable_changes = ::Acts::Journalized::JournableDiffer.association_changes(
+ predecessor,
+ self,
+ "customizable_journals",
+ "custom_fields",
+ :custom_field_id,
+ :value
+ )
+
- if journable.respond_to?(:agenda_items)
- @changes.merge!(
- ::Acts::Journalized::JournableDiffer.association_changes_multiple_attributes(
- predecessor,
- self,
- 'agenda_item_journals',
- 'agenda_items',
- :agenda_item_id,
- [:title, :duration_in_minutes, :notes, :position, :work_package_id]
- )
- )
++ if journable.class.name == "Project"
++ remove_disabled_project_custom_fields!(customizable_changes)
+ end
- @changes
++
++ customizable_changes
+ end
+
+ def get_file_links_changes
+ return unless has_file_links?
+
+ ::Acts::Journalized::FileLinkJournalDiffer.get_changes_to_file_links(
+ predecessor,
+ storable_journals
+ )
+ end
+
+ def get_agenda_items_changes
+ return unless journable.respond_to?(:agenda_items)
+
+ ::Acts::Journalized::JournableDiffer.association_changes_multiple_attributes(
+ predecessor,
+ self,
+ "agenda_item_journals",
+ "agenda_items",
+ :agenda_item_id,
+ %i[title duration_in_minutes notes position work_package_id]
+ )
end
+
+ private
+
+ def remove_disabled_project_custom_fields!(customizable_changes)
+ allowed_custom_field_keys = journable
+ .project_custom_field_project_mappings
- .map{ |c| "custom_fields_#{c.custom_field_id}" }
++ .map { |c| "custom_fields_#{c.custom_field_id}" }
+
+ customizable_changes.delete_if { |key| !key.in?(allowed_custom_field_keys) }
+ end
end