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
extract methods
ulfertsd37bdb71f049
diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rbindex 1ca2f58b3c3..d43083b2027 100644--- a/app/controllers/journals_controller.rb+++ b/app/controllers/journals_controller.rb@@ -64,7 +64,7 @@ class JournalsController < ApplicationControllerenddef diff- journal = Journal::AggregatedJournal.for_journal(@journal)+ journal = Journal::AggregatedJournal.containing_journal(@journal)field = params[:field].parameterize.underscore.to_symunless valid_diff?diff --git a/app/models/journal/aggregated_journal.rb b/app/models/journal/aggregated_journal.rbindex 16aa4691d74..95367d36c5f 100644--- a/app/models/journal/aggregated_journal.rb+++ b/app/models/journal/aggregated_journal.rb@@ -41,8 +41,13 @@# be droppedclass Journal::AggregatedJournalclass << self+ def with_version(pure_journal)+ wp_journals = Journal::AggregatedJournal.aggregated_journals(journable: pure_journal.journable)+ wp_journals.detect { |journal| journal.version == pure_journal.version }+ end+# Returns the aggregated journal that contains the specified (vanilla/pure) journal.- def for_journal(pure_journal)+ def containing_journal(pure_journal)raw = Journal::AggregatedJournal.query_aggregated_journals(journable: pure_journal.journable).where("#{version_projection} >= ?", pure_journal.version).firstdiff --git a/app/services/notifications/journal_notification_service.rb b/app/services/notifications/journal_notification_service.rbindex 94c829e3d95..a1eab12b3fd 100644--- a/app/services/notifications/journal_notification_service.rb+++ b/app/services/notifications/journal_notification_service.rb@@ -44,14 +44,21 @@ class Notifications::JournalNotificationServicereturn nil unless send_notification?(journal) && send_mailsreturn nil unless ::UserMailer.perform_deliveries+ notify_for_predecessor(journal)+ enqueue_work_package_notification(journal)+ end++ # Send the notification on behalf of the predecessor in case it could not send it on its own+ def notify_for_predecessor(journal)aggregated = find_aggregated_journal_for(journal)- # Send the notification on behalf of the predecessor in case it could not send it on its ownif Journal::AggregatedJournal.hides_notifications?(aggregated, aggregated.predecessor)work_package = aggregated.predecessor.journablenotify_journal_complete(work_package, aggregated.predecessor)end+ end+ def enqueue_work_package_notification(journal)job = EnqueueWorkPackageNotificationJob.new(journal.id, User.current.id)Delayed::Job.enqueue job,run_at: delivery_time,diff --git a/app/services/notifications/journal_notifier.rb b/app/services/notifications/journal_notifier.rbindex 775743d92fb..f280614162d 100644--- a/app/services/notifications/journal_notifier.rb+++ b/app/services/notifications/journal_notifier.rb@@ -32,18 +32,25 @@ module Notifications::JournalNotifierprivatedef find_aggregated_journal_for(raw_journal)- wp_journals = Journal::AggregatedJournal.aggregated_journals(journable: raw_journal.journable)- wp_journals.detect { |journal| journal.version == raw_journal.version }+ Journal::AggregatedJournal.with_version(raw_journal)enddef notify_journal_complete(work_package, journal)+ journal_complete_mail(work_package, journal)++ journal_complete_notification(journal)+ end++ def journal_complete_mail(work_package, journal)notification_receivers(work_package, journal).each do |recipient|job = DeliverWorkPackageNotificationJob.new(journal.id,recipient.id,User.current.id)Delayed::Job.enqueue job, priority: ::ApplicationJob.priority_number(:notification)end+ end+ def journal_complete_notification(journal)OpenProject::Notifications.send(OpenProject::Events::AGGREGATED_WORK_PACKAGE_JOURNAL_READY,journal_id: journal.id,@@ -83,8 +90,8 @@ module Notifications::JournalNotifier.each(&:compact!)base_scope = User- .includes(:groups)- .references(:groups_users)+ .includes(:groups)+ .references(:groups_users)by_id = base_scope.where(id: user_ids || [])by_login = base_scope.where(login: user_login_names || [])diff --git a/app/workers/deliver_work_package_notification_job.rb b/app/workers/deliver_work_package_notification_job.rbindex 8f0258d396a..a72cdc91517 100644--- a/app/workers/deliver_work_package_notification_job.rb+++ b/app/workers/deliver_work_package_notification_job.rb@@ -36,7 +36,7 @@ class DeliverWorkPackageNotificationJob < DeliverNotificationJobdef render_mail(recipient:, sender:)return nil unless raw_journal # abort, assuming that the underlying WP was deleted- journal = find_aggregated_journal+ journal = Journal::AggregatedJournal.with_version(raw_journal)# The caller should have ensured that the journal can't outdate anymore# before queuing a notification@@ -55,11 +55,6 @@ class DeliverWorkPackageNotificationJob < DeliverNotificationJob@raw_journal ||= Journal.find_by(id: @journal_id)end- def find_aggregated_journal- wp_journals = Journal::AggregatedJournal.aggregated_journals(journable: work_package)- wp_journals.detect { |journal| journal.version == raw_journal.version }- end-def work_package@work_package ||= raw_journal.journableenddiff --git a/spec/models/journal/aggregated_journal_spec.rb b/spec/models/journal/aggregated_journal_spec.rbindex 5608138519f..314c733a6c0 100644--- a/spec/models/journal/aggregated_journal_spec.rb+++ b/spec/models/journal/aggregated_journal_spec.rb@@ -128,10 +128,10 @@ describe Journal::AggregatedJournal, type: :model doendit 'returns the single journal for both original journals' do- expect(described_class.for_journal work_package.journals.first)+ expect(described_class.containing_journal work_package.journals.first).to be_equivalent_to_journal subject.first- expect(described_class.for_journal work_package.journals.second)+ expect(described_class.containing_journal work_package.journals.second).to be_equivalent_to_journal subject.firstend@@ -171,15 +171,15 @@ describe Journal::AggregatedJournal, type: :model doendit 'returns the same aggregated journal for the first two originals' do- expect(described_class.for_journal work_package.journals.first)+ expect(described_class.containing_journal work_package.journals.first).to be_equivalent_to_journal subject.first- expect(described_class.for_journal work_package.journals.second)+ expect(described_class.containing_journal work_package.journals.second).to be_equivalent_to_journal subject.firstendit 'returns a different aggregated journal for the last original' do- expect(described_class.for_journal work_package.journals.last)+ expect(described_class.containing_journal work_package.journals.last).to be_equivalent_to_journal subject.secondendend