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

exclude deleted work packages from digest rendering

ulferts0761a98b4cb1
diff --git a/app/mailers/digest_mailer.rb b/app/mailers/digest_mailer.rb
index 8213b0aeaf3..326613d3970 100644
--- a/app/mailers/digest_mailer.rb
+++ b/app/mailers/digest_mailer.rb
@@ -58,6 +58,8 @@ class DigestMailer < ApplicationMailer
.group_by(&:project)
.transform_values { |of_project| of_project.group_by(&:resource) }
+ return if @notifications_by_project.empty?
+
mail to: recipient.mail,
subject: I18n.t('mail.digests.work_packages.subject',
date: format_time_as_date(Time.current),
@@ -70,5 +72,6 @@ class DigestMailer < ApplicationMailer
Notification
.where(id: notification_ids)
.includes(:project, :resource, journal: %i[data attachable_journals customizable_journals])
+ .reject { |notification| notification.resource.nil? || notification.project.nil? || notification.journal.nil? }
end
end
diff --git a/spec/mailers/digest_mailer_spec.rb b/spec/mailers/digest_mailer_spec.rb
index 64bc0799f48..d4e8384ca3b 100644
--- a/spec/mailers/digest_mailer_spec.rb
+++ b/spec/mailers/digest_mailer_spec.rb
@@ -75,6 +75,7 @@ describe DigestMailer, type: :mailer do
describe '#work_packages' do
subject(:mail) { described_class.work_packages(recipient.id, notifications.map(&:id)) }
+
let(:mail_body) { mail.body.parts.detect { |part| part['Content-Type'].value == 'text/html' }.body.to_s }
it 'notes the day and the number of notifications in the subject' do
@@ -117,5 +118,17 @@ describe DigestMailer, type: :mailer do
.to have_selector('body section section li',
text: "Subject changed from old subject to new subject")
end
+
+ context 'with only a deleted work package for the digest' do
+ let(:work_package) { nil }
+
+ it `is a NullMail which isn't sent` do
+ expect(mail.body)
+ .to eql ''
+
+ expect(mail.header)
+ .to eql({})
+ end
+ end
end
end