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

Handle existing storages with health_notifications_enabled == nil.

Pavel Balashou1fc89ec2d452
diff --git a/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.html.erb b/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.html.erb
index 3fe5419e808..475f69d103e 100644
--- a/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.html.erb
+++ b/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.html.erb
@@ -40,7 +40,7 @@ See COPYRIGHT and LICENSE files for more details.
data: { turbo_stream: true }) do |f|
flex_layout do |notification_status_actions|
notification_status_actions.with_row do
- f.hidden_field :health_notifications_enabled, value: (@storage.health_notifications_enabled? ? "0" : "1")
+ f.hidden_field :health_notifications_enabled, value: (@storage.health_notifications_should_be_sent? ? "0" : "1")
end
notification_status_actions.with_row(test_selector: "storage-health-notifications-button") do
diff --git a/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.rb b/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.rb
index 31134e5d356..38c5f4f8c5f 100644
--- a/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.rb
+++ b/modules/storages/app/components/storages/admin/sidebar/health_notifications_component.rb
@@ -43,7 +43,7 @@ module Storages
end
def notification_status
- if @storage.health_notifications_enabled?
+ if @storage.health_notifications_should_be_sent?
{ icon: :"bell-slash",
label: I18n.t("storages.health_email_notifications.unsubscribe"),
description: I18n.t("storages.health_email_notifications.description_subscribed") }
diff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rb
index d19421c4042..47d2f4c8049 100644
--- a/modules/storages/app/models/storages/storage.rb
+++ b/modules/storages/app/models/storages/storage.rb
@@ -114,6 +114,15 @@ module Storages
end
end
+ def health_notifications_should_be_sent?
+ # it is a fallback for already created storages without health_notifications_enabled configured.
+ if health_notifications_enabled.nil?
+ automatic_management_enabled?
+ else
+ health_notifications_enabled
+ end
+ end
+
def automatically_managed?
ActiveSupport::Deprecation.warn(
"`#automatically_managed?` is deprecated. Use `#automatic_management_enabled?` instead. " \
diff --git a/modules/storages/app/services/storages/health_service.rb b/modules/storages/app/services/storages/health_service.rb
index 403b8ccbbdd..73fb1c3d165 100644
--- a/modules/storages/app/services/storages/health_service.rb
+++ b/modules/storages/app/services/storages/health_service.rb
@@ -75,7 +75,7 @@ module Storages
private
def notify_healthy_admin_users(reason)
- return unless @storage.health_notifications_enabled?
+ return unless @storage.health_notifications_should_be_sent?
admin_users.each do |admin|
::Storages::StoragesMailer.notify_healthy(admin, @storage, reason).deliver_later
@@ -83,7 +83,7 @@ module Storages
end
def notify_unhealthy_admin_users
- return unless @storage.health_notifications_enabled?
+ return unless @storage.health_notifications_should_be_sent?
admin_users.each do |admin|
::Storages::StoragesMailer.notify_unhealthy(admin, @storage).deliver_later
diff --git a/modules/storages/app/workers/storages/health_status_mailer_job.rb b/modules/storages/app/workers/storages/health_status_mailer_job.rb
index 434fc38fe37..2876d914a74 100644
--- a/modules/storages/app/workers/storages/health_status_mailer_job.rb
+++ b/modules/storages/app/workers/storages/health_status_mailer_job.rb
@@ -42,7 +42,7 @@ module Storages
discard_on ActiveJob::DeserializationError
def perform(storage:)
- return unless storage.health_notifications_enabled?
+ return unless storage.health_notifications_should_be_sent?
return if storage.health_healthy?
admin_users.each do |admin|
diff --git a/modules/storages/spec/models/storages/storage_spec.rb b/modules/storages/spec/models/storages/storage_spec.rb
index 358a850879c..6bd2bb9529a 100644
--- a/modules/storages/spec/models/storages/storage_spec.rb
+++ b/modules/storages/spec/models/storages/storage_spec.rb
@@ -32,6 +32,40 @@ require "spec_helper"
require_module_spec_helper
RSpec.describe Storages::Storage do
+ describe "#health_notifications_should_be_sent?" do
+ let(:storage) { build(:storage, provider_fields: {}) }
+
+ context "when health_notifications_enabled is nil" do
+ it "relies on automatic_management_enabled" do
+ storage.automatic_management_enabled = false
+ expect(storage.health_notifications_should_be_sent?).to be(false)
+
+ storage.automatic_management_enabled = true
+ expect(storage.health_notifications_should_be_sent?).to be(true)
+ end
+ end
+
+ context "when health_notifications_enabled is not nil" do
+ it "relies on health_notifications_enabled" do
+ storage.automatic_management_enabled = false
+ storage.health_notifications_enabled = false
+ expect(storage.health_notifications_should_be_sent?).to be(false)
+
+ storage.automatic_management_enabled = true
+ storage.health_notifications_enabled = false
+ expect(storage.health_notifications_should_be_sent?).to be(false)
+
+ storage.automatic_management_enabled = false
+ storage.health_notifications_enabled = true
+ expect(storage.health_notifications_should_be_sent?).to be(true)
+
+ storage.automatic_management_enabled = false
+ storage.health_notifications_enabled = true
+ expect(storage.health_notifications_should_be_sent?).to be(true)
+ end
+ end
+ end
+
describe "provider_fields" do
let(:storage) { build(:storage, provider_fields: {}) }