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
make register_journal_formatted_fields formatter_key into named argument
Ivan Kuchin7c710f11d111
diff --git a/app/models/journable/with_historic_attributes.rb b/app/models/journable/with_historic_attributes.rbindex 63a1c7aced3..c9e92ce6e45 100644--- a/app/models/journable/with_historic_attributes.rb+++ b/app/models/journable/with_historic_attributes.rb@@ -242,7 +242,7 @@ class Journable::WithHistoricAttributes < SimpleDelegator# of the association name (`custom_fields` in this instance), to map the association fields. That# will result in a changes hash containing { "custom_fields_1" => ... }. This makes sense in the case# of journal changes, because the formatted fields have the convention for plural lookup for journals- # defined in the `register_journal_formatted_fields(:custom_field, /custom_fields_\d+/)`.+ # defined in the `register_journal_formatted_fields(/custom_fields_\d+/, formatter_key: :custom_field)`.# In this case the diff is part of the WorkPackageAtTimestampRepresenter where the `representable_map`# contains the singular names (`custom_field_1`), hence we need to map the diffs to match that format.# As a food for thought, I think it would be more handy to use the singular naming everywhere.diff --git a/app/models/project.rb b/app/models/project.rbindex e4363ac4a5d..000467a7c35 100644--- a/app/models/project.rb+++ b/app/models/project.rb@@ -107,16 +107,14 @@ class Project < ApplicationRecordauthor: nil,datetime: :created_at- register_journal_formatted_fields(:active_status, "active")- register_journal_formatted_fields(:template, "templated")- register_journal_formatted_fields(:plaintext, "identifier")- register_journal_formatted_fields(:plaintext, "name")- register_journal_formatted_fields(:diff, "status_explanation")- register_journal_formatted_fields(:diff, "description")- register_journal_formatted_fields(:project_status_code, "status_code")- register_journal_formatted_fields(:visibility, "public")- register_journal_formatted_fields(:subproject_named_association, "parent_id")- register_journal_formatted_fields(:custom_field, /custom_fields_\d+/)+ register_journal_formatted_fields "active", formatter_key: :active_status+ register_journal_formatted_fields "templated", formatter_key: :template+ register_journal_formatted_fields "identifier", "name", formatter_key: :plaintext+ register_journal_formatted_fields "status_explanation", "description", formatter_key: :diff+ register_journal_formatted_fields "status_code", formatter_key: :project_status_code+ register_journal_formatted_fields "public", formatter_key: :visibility+ register_journal_formatted_fields "parent_id", formatter_key: :subproject_named_association+ register_journal_formatted_fields /custom_fields_\d+/, formatter_key: :custom_fieldhas_paper_traildiff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rbindex 37810f31de5..15a12204425 100644--- a/app/models/wiki_page.rb+++ b/app/models/wiki_page.rb@@ -54,7 +54,7 @@ class WikiPage < ApplicationRecordacts_as_journalized- register_journal_formatted_fields(:wiki_diff, 'text')+ register_journal_formatted_fields "text", formatter_key: :wiki_diffattr_accessor :redirect_existing_linksdiff --git a/app/models/work_package/journalized.rb b/app/models/work_package/journalized.rbindex 310e70c561c..8d4372a3a7d 100644--- a/app/models/work_package/journalized.rb+++ b/app/models/work_package/journalized.rb@@ -77,28 +77,29 @@ module WorkPackage::Journalizedname: JournalizedProcs.event_name,url: JournalizedProcs.event_url- register_journal_formatted_fields(:id, "parent_id")- register_journal_formatted_fields(:chronic_duration,- "estimated_hours", "derived_estimated_hours",- "remaining_hours", "derived_remaining_hours")- register_journal_formatted_fields(:percentage, "done_ratio", "derived_done_ratio")- register_journal_formatted_fields(:diff, "description")- register_journal_formatted_fields(:schedule_manually, "schedule_manually")- register_journal_formatted_fields(:attachment, /attachments_?\d+/)- register_journal_formatted_fields(:custom_field, /custom_fields_\d+/)- register_journal_formatted_fields(:ignore_non_working_days, "ignore_non_working_days")- register_journal_formatted_fields(:cause, "cause")- register_journal_formatted_fields(:file_link, /file_links_?\d+/)+ register_journal_formatted_fields "parent_id", formatter_key: :id+ register_journal_formatted_fields "estimated_hours", "derived_estimated_hours",+ "remaining_hours", "derived_remaining_hours",+ formatter_key: :chronic_duration+ register_journal_formatted_fields "done_ratio", "derived_done_ratio", formatter_key: :percentage+ register_journal_formatted_fields "description", formatter_key: :diff+ register_journal_formatted_fields "schedule_manually", formatter_key: :schedule_manually+ register_journal_formatted_fields /attachments_?\d+/, formatter_key: :attachment+ register_journal_formatted_fields /custom_fields_\d+/, formatter_key: :custom_field+ register_journal_formatted_fields "ignore_non_working_days", formatter_key: :ignore_non_working_days+ register_journal_formatted_fields "cause", formatter_key: :cause+ register_journal_formatted_fields /file_links_?\d+/, formatter_key: :file_link# Joined- register_journal_formatted_fields :named_association, :parent_id, :project_id,+ register_journal_formatted_fields :parent_id, :project_id,:budget_id,:status_id, :type_id,:assigned_to_id, :priority_id,:category_id, :version_id,- :author_id, :responsible_id- register_journal_formatted_fields :datetime, :start_date, :due_date- register_journal_formatted_fields :plaintext, :subject- register_journal_formatted_fields :day_count, :duration+ :author_id, :responsible_id,+ formatter_key: :named_association+ register_journal_formatted_fields :start_date, :due_date, formatter_key: :datetime+ register_journal_formatted_fields :subject, formatter_key: :plaintext+ register_journal_formatted_fields :duration, formatter_key: :day_countendenddiff --git a/lib_static/plugins/acts_as_journalized/lib/acts/journalized/format_hooks.rb b/lib_static/plugins/acts_as_journalized/lib/acts/journalized/format_hooks.rbindex cd0ce88caf7..348c0befa6a 100644--- a/lib_static/plugins/acts_as_journalized/lib/acts/journalized/format_hooks.rb+++ b/lib_static/plugins/acts_as_journalized/lib/acts/journalized/format_hooks.rb@@ -53,7 +53,7 @@ module Acts::Journalizedmodule ClassMethods# Shortcut to register a formatter for a number of fields- def register_journal_formatted_fields(formatter_key, *field_names)+ def register_journal_formatted_fields(*field_names, formatter_key:)journal_data_type = journal_class.namefield_names.each do |field|JournalFormatter.register_formatted_field(journal_data_type, field, formatter_key)diff --git a/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rbindex 6e0a5d307dd..6f12f90bf9d 100644--- a/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb+++ b/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb@@ -33,8 +33,7 @@ module OpenProject::Backlogs::Patches::WorkPackagePatchprepend InstanceMethodsextend ClassMethods- register_journal_formatted_fields(:decimal, "story_points")- register_journal_formatted_fields(:decimal, "position")+ register_journal_formatted_fields "story_points", "position", formatter_key: :decimalvalidates_numericality_of :story_points, only_integer: true,allow_nil: true,diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rbindex fb1d3ba4e60..40a975c1108 100644--- a/modules/costs/app/models/time_entry.rb+++ b/modules/costs/app/models/time_entry.rb@@ -57,12 +57,10 @@ class TimeEntry < ApplicationRecord# TODO: move into servicebefore_save :update_costs- register_journal_formatted_fields(:time_entry_hours, "hours")- register_journal_formatted_fields(:time_entry_named_association, "user_id")- register_journal_formatted_fields(:named_association, "work_package_id")- register_journal_formatted_fields(:named_association, "activity_id")- register_journal_formatted_fields(:plaintext, "comments")- register_journal_formatted_fields(:plaintext, "spent_on")+ register_journal_formatted_fields "hours", formatter_key: :time_entry_hours+ register_journal_formatted_fields "user_id", formatter_key: :time_entry_named_association+ register_journal_formatted_fields "work_package_id", "activity_id", formatter_key: :named_association+ register_journal_formatted_fields "comments", "spent_on", formatter_key: :plaintextdef self.update_all(updates, conditions = nil, options = {})# instead of a update_all, perform an individual update during work_package#movediff --git a/modules/meeting/app/models/meeting/journalized.rb b/modules/meeting/app/models/meeting/journalized.rbindex 72d54d847ac..feaa00539fe 100644--- a/modules/meeting/app/models/meeting/journalized.rb+++ b/modules/meeting/app/models/meeting/journalized.rb@@ -41,19 +41,18 @@ module Meeting::Journalizedauthor: Proc.new(&:user),description: ""- register_journal_formatted_fields(:plaintext, "title")- register_journal_formatted_fields(:fraction, "duration")- register_journal_formatted_fields(:datetime, "start_date")- register_journal_formatted_fields(:meeting_start_time, "start_time")- register_journal_formatted_fields(:plaintext, "location")- register_journal_formatted_fields(:meeting_state, "state")+ register_journal_formatted_fields "title", "location", formatter_key: :plaintext+ register_journal_formatted_fields "duration", formatter_key: :fraction+ register_journal_formatted_fields "start_date", formatter_key: :datetime+ register_journal_formatted_fields "start_time", formatter_key: :meeting_start_time+ register_journal_formatted_fields "state", formatter_key: :meeting_state- register_journal_formatted_fields(:agenda_item_duration, "duration")- register_journal_formatted_fields(:agenda_item_diff, /agenda_items_\d+_notes/)- register_journal_formatted_fields(:agenda_item_title, /agenda_items_\d+_title/)- register_journal_formatted_fields(:agenda_item_duration, /agenda_items_\d+_duration_in_minutes/)- register_journal_formatted_fields(:agenda_item_position, "position")- register_journal_formatted_fields(:meeting_work_package_id, /agenda_items_\d+_work_package_id/)+ register_journal_formatted_fields "duration", formatter_key: :agenda_item_duration+ register_journal_formatted_fields /agenda_items_\d+_notes/, formatter_key: :agenda_item_diff+ register_journal_formatted_fields /agenda_items_\d+_title/, formatter_key: :agenda_item_title+ register_journal_formatted_fields /agenda_items_\d+_duration_in_minutes/, formatter_key: :agenda_item_duration+ register_journal_formatted_fields "position", formatter_key: :agenda_item_position+ register_journal_formatted_fields /agenda_items_\d+_work_package_id/, formatter_key: :meeting_work_package_iddef touch_and_save_journalsupdate_column(:updated_at, Time.current)