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

fix[Op#52449]: Do not schedule daily notification job if unsubscribed

Kabiru Mwenja2f4f06f33e28
diff --git a/modules/storages/app/services/storages/health_service.rb b/modules/storages/app/services/storages/health_service.rb
index 403b8ccbbdd..b25d798937f 100644
--- a/modules/storages/app/services/storages/health_service.rb
+++ b/modules/storages/app/services/storages/health_service.rb
@@ -96,6 +96,8 @@ module Storages
end
def schedule_mail_job(storage)
+ return unless storage.health_notifications_enabled?
+
::Storages::HealthStatusMailerJob.schedule(storage:)
end
diff --git a/modules/storages/spec/services/storages/health_service_spec.rb b/modules/storages/spec/services/storages/health_service_spec.rb
index e1a0bdd35c3..331d626d723 100644
--- a/modules/storages/spec/services/storages/health_service_spec.rb
+++ b/modules/storages/spec/services/storages/health_service_spec.rb
@@ -131,32 +131,43 @@ RSpec.describe Storages::HealthService do
it "notifies admin users when the storage becomes healthy" do
expect do
health_service.healthy
- end.to have_enqueued_mail(Storages::StoragesMailer, :notify_healthy)
- .with(admin_user, storage, storage.health_reason).at_most(:once)
+ end.to(have_enqueued_mail(
+ Storages::StoragesMailer, :notify_healthy
+ ).with(admin_user, storage, storage.health_reason).at_most(:once)
+ .and(have_enqueued_job(Storages::HealthStatusMailerJob).with(storage:).at_most(:once)))
end
it "notifies admin users when the storage becomes unhealthy" do
expect do
health_service.unhealthy(reason: "thou_shall_not_pass_error")
- end.to have_enqueued_mail(Storages::StoragesMailer, :notify_unhealthy).with(admin_user, storage).at_most(:once)
+ end.to(have_enqueued_mail(
+ Storages::StoragesMailer, :notify_unhealthy
+ ).with(admin_user, storage).at_most(:once)
+ .and(have_enqueued_job(Storages::HealthStatusMailerJob).with(storage:).at_most(:once)))
end
end
context "when the storage has notifications disabled" do
before do
storage.update(health_notifications_enabled: false)
+
+ allow(Storages::HealthStatusMailerJob).to receive(:schedule).and_call_original
end
it "does not notify admin users when the storage becomes healthy" do
expect do
health_service.healthy
end.not_to have_enqueued_mail(Storages::StoragesMailer, :notify_healthy)
+
+ expect(Storages::HealthStatusMailerJob).not_to have_received(:schedule)
end
it "does not notify admin users when the storage becomes unhealthy" do
expect do
health_service.unhealthy(reason: "thou_shall_not_pass_error")
end.not_to have_enqueued_mail(Storages::StoragesMailer, :notify_unhealthy)
+
+ expect(Storages::HealthStatusMailerJob).not_to have_received(:schedule)
end
end
end