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

Refactor how the meeting journals are saved

Dombi Attila24d907bb0bed
diff --git a/app/models/work_package.rb b/app/models/work_package.rb
index e806e3395ac..0f928254618 100644
--- a/app/models/work_package.rb
+++ b/app/models/work_package.rb
@@ -70,7 +70,7 @@ class WorkPackage < ApplicationRecord
has_many :members, as: :entity, dependent: :destroy
has_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: :nullify
has_many :meetings, through: :meeting_agenda_items, source: :meeting
scope :recently_updated, -> {
@@ -142,7 +142,9 @@ class WorkPackage < ApplicationRecord
if: lambda { |work_package| work_package.errors.messages.has_key? :attachments }
before_save :close_duplicates, :update_done_ratio_from_status
before_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 < ApplicationRecord
end
end
- 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)
end
end
diff --git a/modules/meeting/app/models/meeting.rb b/modules/meeting/app/models/meeting.rb
index 059dfe14919..e9060b1e904 100644
--- a/modules/meeting/app/models/meeting.rb
+++ b/modules/meeting/app/models/meeting.rb
@@ -61,20 +61,7 @@ class Meeting < ApplicationRecord
references: :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::Journalized
accepts_nested_attributes_for :participants, allow_destroy: true
diff --git a/modules/meeting/app/services/meeting_agenda_items/touch_meeting.rb b/modules/meeting/app/models/meeting/journalized.rb
similarity index 58%
rename from modules/meeting/app/services/meeting_agenda_items/touch_meeting.rb
rename to modules/meeting/app/models/meeting/journalized.rb
index 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_journals
end
end
end
diff --git a/modules/meeting/app/services/meeting_agenda_items/after_perform_hook.rb b/modules/meeting/app/services/meeting_agenda_items/after_perform_hook.rb
index 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 MeetingAgendaItems
module AfterPerformHook
extend ActiveSupport::Concern
- include TouchMeeting
included do
def after_perform(call)
meeting_agenda_item = call.result
meeting = meeting_agenda_item.meeting
- touch(meeting) unless meeting.nil?
+ meeting&.touch_and_save_journals
call
end