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

[57251] Fix mail_alert_sent not being set correctly on update

Christophe Bliard1ad3b4ed4dac
diff --git a/app/services/notifications/create_from_model_service.rb b/app/services/notifications/create_from_model_service.rb
index e1f0eb09201..089ad5ed5d8 100644
--- a/app/services/notifications/create_from_model_service.rb
+++ b/app/services/notifications/create_from_model_service.rb
@@ -129,6 +129,7 @@ class Notifications::CreateFromModelService
Notifications::UpdateService
.new(model: existing_notification, user:, contract_class: EmptyContract)
.call(read_ian: strategy.supports_ian?(reason) ? false : nil,
+ mail_alert_sent: existing_notification.mail_alert_sent || (strategy.supports_mail?(reason) ? false : nil),
reason:)
end
diff --git a/spec/services/notifications/create_from_model_service_work_package_spec.rb b/spec/services/notifications/create_from_model_service_work_package_spec.rb
index 886f4d912c2..3a57b24a1dc 100644
--- a/spec/services/notifications/create_from_model_service_work_package_spec.rb
+++ b/spec/services/notifications/create_from_model_service_work_package_spec.rb
@@ -997,7 +997,7 @@ RSpec.describe Notifications::CreateFromModelService,
context "when there is already a notification for the journal (because it was aggregated)" do
let(:note) { "Hello user:\"#{recipient_login}\"" }
let!(:existing_notification) do
- create(:notification, resource:, journal:, recipient:, reason: :mentioned, read_ian: true)
+ create(:notification, resource:, journal:, recipient:, reason: :mentioned, read_ian: true, mail_alert_sent: nil)
end
it_behaves_like "creates no notification"
@@ -1006,7 +1006,27 @@ RSpec.describe Notifications::CreateFromModelService,
call
expect(existing_notification.reload.read_ian)
- .to be_falsey
+ .to be(false)
+ end
+
+ it "changes the mail_alert_sent of the existing notification from nil to false" do
+ call
+
+ expect(existing_notification.reload.mail_alert_sent)
+ .to be(false)
+ end
+
+ context "and the mail alert has already been sent" do
+ before do
+ existing_notification.update(mail_alert_sent: true)
+ end
+
+ it "keeps the mail_alert_sent of the existing notification to true" do
+ call
+
+ expect(existing_notification.reload.mail_alert_sent)
+ .to be(true)
+ end
end
end