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

Added storages mailer and events

Andreas Pfohl902a71a1c6b8
diff --git a/lib/open_project/events.rb b/lib/open_project/events.rb
index aae889c22e3..9320a7621ea 100644
--- a/lib/open_project/events.rb
+++ b/lib/open_project/events.rb
@@ -66,6 +66,9 @@ module OpenProject
PROJECT_STORAGE_UPDATED = "project_storage_updated".freeze
PROJECT_STORAGE_DESTROYED = "project_storage_destroyed".freeze
+ STORAGE_TURNED_UNHEALTHY = "storage_turned_unhealthy".freeze
+ STORAGE_TURNED_HEALTHY = "storage_turned_unhealthy".freeze
+
ROLE_UPDATED = "role_updated".freeze
ROLE_DESTROYED = "role_destroyed".freeze
diff --git a/modules/storages/app/mailers/storages/storages_mailer.rb b/modules/storages/app/mailers/storages/storages_mailer.rb
new file mode 100644
index 00000000000..01555cb2a48
--- /dev/null
+++ b/modules/storages/app/mailers/storages/storages_mailer.rb
@@ -0,0 +1,64 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module Storages
+ class StoragesMailer < ApplicationMailer
+ include MessagesHelper
+
+ helper_method :message_url
+
+ before_action :find_admins, only: %i[notify_unhealthy notify_healthy]
+
+ def notify_unhealthy(storage)
+ @storage = storage
+ subject = "Storage turned unhealthy!"
+ send_mail_to_admins(storage, subject)
+ end
+
+ def notify_healthy(storage)
+ @storage = storage
+ subject = "Storage is back healthy!"
+ send_mail_to_admins(storage, subject)
+ end
+
+ private
+
+ def find_admins
+ @admins = User.where(admin: true)
+ .where.not(email: [nil, ''])
+ end
+
+ def send_mail_to_admins(storage, subject)
+ @admins.each do |admin|
+ mail(to: admin.mail, subject:)
+ end
+ end
+ end
+end
diff --git a/modules/storages/app/views/storages/storages_mailer/notify_healthy.html.erb b/modules/storages/app/views/storages/storages_mailer/notify_healthy.html.erb
new file mode 100644
index 00000000000..9202109f0a6
--- /dev/null
+++ b/modules/storages/app/views/storages/storages_mailer/notify_healthy.html.erb
@@ -0,0 +1,32 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) 2012-2024 the OpenProject GmbH
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+Copyright (C) 2006-2013 Jean-Philippe Lang
+Copyright (C) 2010-2013 the ChiliProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<p><%= link_to(@storage.name, storage_url(@storage)) %> (<%= @storage.provider_type %>)</p>
+
+<%= format_text @storage.health_reason %>
diff --git a/modules/storages/app/views/storages/storages_mailer/notify_healthy.text.erb b/modules/storages/app/views/storages/storages_mailer/notify_healthy.text.erb
new file mode 100644
index 00000000000..f6351d23acf
--- /dev/null
+++ b/modules/storages/app/views/storages/storages_mailer/notify_healthy.text.erb
@@ -0,0 +1,33 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) 2012-2024 the OpenProject GmbH
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+Copyright (C) 2006-2013 Jean-Philippe Lang
+Copyright (C) 2010-2013 the ChiliProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<%= @storage.name %> (<%= @storage.provider_type %>)
+<%= storage_url(@storage) %>
+
+<%= @storage.health_reason %>
diff --git a/modules/storages/app/views/storages/storages_mailer/notify_unhealthy.html.erb b/modules/storages/app/views/storages/storages_mailer/notify_unhealthy.html.erb
new file mode 100644
index 00000000000..9202109f0a6
--- /dev/null
+++ b/modules/storages/app/views/storages/storages_mailer/notify_unhealthy.html.erb
@@ -0,0 +1,32 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) 2012-2024 the OpenProject GmbH
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+Copyright (C) 2006-2013 Jean-Philippe Lang
+Copyright (C) 2010-2013 the ChiliProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<p><%= link_to(@storage.name, storage_url(@storage)) %> (<%= @storage.provider_type %>)</p>
+
+<%= format_text @storage.health_reason %>
diff --git a/modules/storages/app/views/storages/storages_mailer/notify_unhealthy.text.erb b/modules/storages/app/views/storages/storages_mailer/notify_unhealthy.text.erb
new file mode 100644
index 00000000000..f6351d23acf
--- /dev/null
+++ b/modules/storages/app/views/storages/storages_mailer/notify_unhealthy.text.erb
@@ -0,0 +1,33 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) 2012-2024 the OpenProject GmbH
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+Copyright (C) 2006-2013 Jean-Philippe Lang
+Copyright (C) 2010-2013 the ChiliProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<%= @storage.name %> (<%= @storage.provider_type %>)
+<%= storage_url(@storage) %>
+
+<%= @storage.health_reason %>
diff --git a/modules/storages/app/workers/storages/health_status_mailer_job.rb b/modules/storages/app/workers/storages/health_status_mailer_job.rb
new file mode 100644
index 00000000000..71474ddbe78
--- /dev/null
+++ b/modules/storages/app/workers/storages/health_status_mailer_job.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module Storages
+ class HealthStatusMailerJob < ApplicationJob
+ def perform(storage)
+ if storage.healthy?
+ return
+ end
+
+ Storages::StoragesMailer.notify_unhealthy(storage).deliver_now
+
+ reschedule
+ end
+
+ private
+
+ def reschedule
+ next_run_time = Date.now.tomorrow.beginning_of_the_day + 2.hours
+
+ self.class.set(wait_until: next_run_time).perform_later
+ end
+ end
+end
diff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rb
index de36e6e7b23..d76be966a89 100644
--- a/modules/storages/lib/open_project/storages/engine.rb
+++ b/modules/storages/lib/open_project/storages/engine.rb
@@ -73,6 +73,7 @@ module OpenProject::Storages
::Storages::ManageNextcloudIntegrationEventsJob.debounce
end
end
+
OpenProject::Notifications.subscribe(
OpenProject::Events::ROLE_UPDATED
) do |payload|
@@ -80,6 +81,7 @@ module OpenProject::Storages
::Storages::ManageNextcloudIntegrationEventsJob.debounce
end
end
+
OpenProject::Notifications.subscribe(
OpenProject::Events::ROLE_DESTROYED
) do |payload|
@@ -100,6 +102,18 @@ module OpenProject::Storages
end
end
end
+
+ OpenProject::Notifications.subscribe(
+ ::OpenProject::Events::STORAGE_TURNED_UNHEALTHY
+ ) do |storage|
+ # send mail to admins
+ end
+
+ OpenProject::Notifications.subscribe(
+ ::OpenProject::Events::STORAGE_TURNED_HEALTHY
+ ) do |storage|
+ # send mail to admins
+ end
end
end