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
avoid sending journal aggregated event if journal was updated
ulfertsef8fc137e3bb
diff --git a/app/workers/journals/completed_job.rb b/app/workers/journals/completed_job.rbindex f261f67c52e..788a1d2e241 100644--- a/app/workers/journals/completed_job.rb+++ b/app/workers/journals/completed_job.rb@@ -34,7 +34,7 @@ class Journals::CompletedJob < ApplicationJobreturn unless supported?(journal)set(wait_until: delivery_time)- .perform_later(journal.id, send_mails)+ .perform_later(journal.id, journal.updated_at, send_mails)enddef aggregated_event(journal)@@ -61,12 +61,17 @@ class Journals::CompletedJob < ApplicationJobendend- def perform(journal_id, send_mails)- journal = Journal.find_by(id: journal_id)-- # If the WP has been deleted the journal will have been deleted, too.- # Or the journal might have been replaced- return if journal.nil?+ def perform(journal_id, journal_updated_at, send_mails)+ # If the WP has been deleted, the journal will have been deleted, too.+ # The journal might also have been updated in the meantime. This happens if+ # the journable is updated a second time by the same user within the aggregation time.+ # If aggregation happened, then the job scheduled when the journal was updated the second time+ # will take care of notifying later.+ # If another user were to update the journable even within aggregation time,+ # the journal would not be altered. It is thus safe to consider the journal+ # final.+ journal = Journal.find_by(id: journal_id, updated_at: journal_updated_at)+ return unless journalnotify_journal_complete(journal, send_mails)enddiff --git a/spec/models/work_package/openproject_notifications_spec.rb b/spec/models/work_package/openproject_notifications_spec.rbindex b46482c0963..cbd956b4d0d 100644--- a/spec/models/work_package/openproject_notifications_spec.rb+++ b/spec/models/work_package/openproject_notifications_spec.rb@@ -61,23 +61,23 @@ describe WorkPackage, type: :model, with_settings: { journal_aggregation_time_miendit "are triggered" do- expect(journal_ids).to include(work_package.journals.last.id)+ expect(journal_ids).to match [work_package.journals.last.id]endenddescribe 'when after update' dobefore dowork_package-+ perform_enqueued_jobsjournal_ids.clear- work_package.update subject: 'the wind of change'+ work_package.update(subject: 'the wind of change')perform_enqueued_jobsendit "are triggered" do- expect(journal_ids).to include(work_package.journals.last.id)+ expect(journal_ids).to match [work_package.journals.last.id]endendenddiff --git a/spec/workers/journals/completed_job_spec.rb b/spec/workers/journals/completed_job_spec.rbindex 4d99c6d5266..f5c3fb461ec 100644--- a/spec/workers/journals/completed_job_spec.rb+++ b/spec/workers/journals/completed_job_spec.rb@@ -32,20 +32,7 @@ describe Journals::CompletedJob, type: :model dolet(:send_mail) { true }let(:journal) do- build_stubbed(:journal, journable:).tap do |j|- allow(Journal)- .to receive(:find)- .with(j.id.to_s)- .and_return(j)- allow(Journal)- .to receive(:find_by)- .with(id: j.id)- .and_return(j)- allow(Journal)- .to receive(:exists?)- .with(id: j.id)- .and_return(true)- end+ build_stubbed(:journal, journable:)enddescribe '.schedule' do@@ -63,6 +50,7 @@ describe Journals::CompletedJob, type: :model do.to have_enqueued_job(described_class).at(Setting.journal_aggregation_time_minutes.to_i.minutes.from_now).with(journal.id,+ journal.updated_at,send_mail)endend@@ -94,7 +82,16 @@ describe Journals::CompletedJob, type: :model doenddescribe '#perform' do- subject { described_class.new.perform(journal.id, send_mail) }+ subject { described_class.new.perform(journal.id, journal.updated_at, send_mail) }++ let(:find_by_journal) { journal }++ before do+ allow(Journal)+ .to receive(:find_by)+ .with(id: journal.id, updated_at: journal.updated_at)+ .and_return(find_by_journal)+ endshared_examples_for 'sends a notification' do |event|it 'sends a notification' do@@ -132,15 +129,9 @@ describe Journals::CompletedJob, type: :model doOpenProject::Events::AGGREGATED_NEWS_JOURNAL_READYend- context 'with a non non-existant journal' do+ context 'with a non non-existent journal (either because the journable was deleted or the journal updated)' dolet(:journable) { build_stubbed(:work_package) }-- before do- allow(Journal)- .to receive(:find_by)- .with(id: journal.id)- .and_return(nil)- end+ let(:find_by_journal) { nil }it 'sends no notification' doallow(OpenProject::Notifications)