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
Refactor how the meeting journals are saved
Dombi Attila24d907bb0bed
diff --git a/app/models/work_package.rb b/app/models/work_package.rbindex e806e3395ac..0f928254618 100644--- a/app/models/work_package.rb+++ b/app/models/work_package.rb@@ -70,7 +70,7 @@ class WorkPackage < ApplicationRecordhas_many :members, as: :entity, dependent: :destroyhas_many :member_principals, through: :members, class_name: 'Principal', source: :principal- has_many :meeting_agenda_items, dependent: nil # Cleanup handled in dissociate_agenda_items method+ has_many :meeting_agenda_items, dependent: :nullifyhas_many :meetings, through: :meeting_agenda_items, source: :meetingscope :recently_updated, -> {@@ -142,7 +142,9 @@ class WorkPackage < ApplicationRecordif: lambda { |work_package| work_package.errors.messages.has_key? :attachments }before_save :close_duplicates, :update_done_ratio_from_statusbefore_create :default_assign- before_destroy :dissociate_agenda_items, if: -> { meeting_agenda_items.any? }+ # By using prepend: true, the callback will be executed before the meeting_agenda_items are nullified,+ # thus the items will be available for the callback method.+ around_destroy :save_agenda_item_journals, prepend: true, if: -> { meeting_agenda_items.any? }acts_as_customizable@@ -639,11 +641,17 @@ class WorkPackage < ApplicationRecordendend- def dissociate_agenda_items+ def save_agenda_item_journals+ ### Unscoping the order is required, because the MeetingAgendaItems have a default order# and it throws an error, because the ordered field is not part of the select.+ #+ # Furthermore, meetings are stored before they become dissociated from the work package,+ # but the meeting journals are saved only after the agenda items are dissociated (nullified).+ # By saving the meeting journals, the agenda item journals are also saved.+uniq_meetings = meetings.unscope(:order).uniq- meeting_agenda_items.update_all(work_package_id: nil)- uniq_meetings.each(&:save_journals)+ yield+ uniq_meetings.each(&:touch_and_save_journals)endenddiff --git a/modules/meeting/app/models/meeting.rb b/modules/meeting/app/models/meeting.rbindex 059dfe14919..e9060b1e904 100644--- a/modules/meeting/app/models/meeting.rb+++ b/modules/meeting/app/models/meeting.rb@@ -61,20 +61,7 @@ class Meeting < ApplicationRecordreferences: :meeting_contents,date_column: "#{table_name}.created_at"- acts_as_journalized- acts_as_event title: Proc.new { |o|- "#{I18n.t(:label_meeting)}: #{o.title} \- #{format_date o.start_time} \- #{format_time o.start_time, false}-#{format_time o.end_time, false})"- },- url: Proc.new { |o| { controller: '/meetings', action: 'show', id: o } },- author: Proc.new(&:user),- description: ''-- register_journal_formatted_fields(:plaintext, 'title')- register_journal_formatted_fields(:fraction, 'duration')- register_journal_formatted_fields(:datetime, 'start_time')- register_journal_formatted_fields(:plaintext, 'location')+ include Meeting::Journalizedaccepts_nested_attributes_for :participants, allow_destroy: truediff --git a/modules/meeting/app/services/meeting_agenda_items/touch_meeting.rb b/modules/meeting/app/models/meeting/journalized.rbsimilarity index 58%rename from modules/meeting/app/services/meeting_agenda_items/touch_meeting.rbrename to modules/meeting/app/models/meeting/journalized.rbindex e8a3da9ac60..7d514cc6ce1 100644--- a/modules/meeting/app/services/meeting_agenda_items/touch_meeting.rb+++ b/modules/meeting/app/models/meeting/journalized.rb@@ -26,24 +26,29 @@# See COPYRIGHT and LICENSE files for more details.#++-module MeetingAgendaItems- module TouchMeeting- extend ActiveSupport::Concern+module Meeting::Journalized+ extend ActiveSupport::Concern- included do- private+ included do+ acts_as_journalized- def touch(meeting)- # We allow invalid meetings to be saved as- # adding the attachments does not change the validity of the meeting- # but without that leeway, the user needs to fix the meeting before- # the agenda_item can be added.- # However we want the meeting to be updated when updating an agenda_item. This is important,- # e.g. for invalidating caches and also for journalizing+ acts_as_event title: Proc.new { |o|+ "#{I18n.t(:label_meeting)}: #{o.title} \+ #{format_date o.start_time} \+ #{format_time o.start_time, false}-#{format_time o.end_time, false})"+ },+ url: Proc.new { |o| { controller: '/meetings', action: 'show', id: o } },+ author: Proc.new(&:user),+ description: ''- meeting.update_column(:updated_at, Time.current)- meeting.save_journals if meeting.respond_to?(:save_journals)- end+ register_journal_formatted_fields(:plaintext, 'title')+ register_journal_formatted_fields(:fraction, 'duration')+ register_journal_formatted_fields(:datetime, 'start_time')+ register_journal_formatted_fields(:plaintext, 'location')++ def touch_and_save_journals+ update_column(:updated_at, Time.current)+ save_journalsendendenddiff --git a/modules/meeting/app/services/meeting_agenda_items/after_perform_hook.rb b/modules/meeting/app/services/meeting_agenda_items/after_perform_hook.rbindex bd41ad8c2fc..539448df29d 100644--- a/modules/meeting/app/services/meeting_agenda_items/after_perform_hook.rb+++ b/modules/meeting/app/services/meeting_agenda_items/after_perform_hook.rb@@ -29,14 +29,13 @@module MeetingAgendaItemsmodule AfterPerformHookextend ActiveSupport::Concern- include TouchMeetingincluded dodef after_perform(call)meeting_agenda_item = call.resultmeeting = meeting_agenda_item.meeting- touch(meeting) unless meeting.nil?+ meeting&.touch_and_save_journalscallend