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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fixed StorageHealthMailJob and mail sending
Andreas Pfohldfbca96b6891
diff --git a/Gemfile b/Gemfileindex 6b539ba331c..7f13655ad7c 100644--- a/Gemfile+++ b/Gemfile@@ -294,6 +294,7 @@ group :development dogem 'listen', '~> 3.8.0' # Use for event-based reloadersgem 'letter_opener'+ gem 'letter_opener_web'gem 'spring'gem 'spring-commands-rspec'diff --git a/Gemfile.lock b/Gemfile.lockindex cebb636da6e..ab64576ec54 100644--- a/Gemfile.lock+++ b/Gemfile.lock@@ -665,6 +665,11 @@ GEMlefthook (1.6.4)letter_opener (1.9.0)launchy (>= 2.2, < 3)+ letter_opener_web (2.0.0)+ actionmailer (>= 5.2)+ letter_opener (~> 1.7)+ railties (>= 5.2)+ rexmllisten (3.8.0)rb-fsevent (~> 0.10, >= 0.10.3)rb-inotify (~> 0.9, >= 0.9.10)@@ -1198,6 +1203,7 @@ DEPENDENCIESlaunchy (~> 2.5.0)lefthookletter_opener+ letter_opener_weblisten (~> 3.8.0)lograge (~> 0.14.0)lookbook (~> 2.2.1)diff --git a/config/environments/development.rb b/config/environments/development.rbindex 01d16087bcf..0bcb2c86e68 100644--- a/config/environments/development.rb+++ b/config/environments/development.rb@@ -109,6 +109,7 @@ Rails.application.configure do# Send mails to browser windowconfig.action_mailer.delivery_method = :letter_opener+ config.action_mailer.delivery_method = File.exist?('/.dockerenv') ? :letter_opener_web : :letter_opener# Set email preview locations to rspecconfig.action_mailer.preview_paths << Rails.root.join('spec/mailers/previews')diff --git a/config/locales/en.yml b/config/locales/en.ymlindex e9818481f81..34969e8e50a 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2421,6 +2421,11 @@ en:summary:user: "%{user} shared a work package with you with %{role_rights} rights"group: "%{user} shared a work package with the group %{group} you are a member of"+ storages:+ health:+ see_storage_settings: "See storage settings"+ unhealthy:+ summary: "There is a problem with your %{storage_name} storage integration"mail_body_account_activation_request: "A new user (%{value}) has registered. The account is pending your approval:"mail_body_account_information: "Your account information"diff --git a/config/routes.rb b/config/routes.rbindex 6e7dbf0313e..ce5c932ad67 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -650,4 +650,8 @@ Rails.application.routes.draw doif OpenProject::Configuration.lookbook_enabled?mount Lookbook::Engine, at: "/lookbook"end++ if Rails.env.development?+ mount LetterOpenerWeb::Engine, at: "/letter_opener"+ endenddiff --git a/modules/storages/app/mailers/storages/storages_mailer.rb b/modules/storages/app/mailers/storages/storages_mailer.rbindex 0e23f5954c6..e7f0fc00b55 100644--- a/modules/storages/app/mailers/storages/storages_mailer.rb+++ b/modules/storages/app/mailers/storages/storages_mailer.rb@@ -34,32 +34,21 @@ module Storageshelper_method :message_url- before_action :find_admins, only: %i[notify_unhealthy notify_healthy]-- def notify_unhealthy(storage, reason)+ def notify_unhealthy(admin, storage)+ @admin = admin@storage = storage- @reason = reason+ @reason = storage.health_reason+ @url = edit_admin_settings_storage_url(storage)subject = "Storage turned unhealthy!"- send_mail_to_admins(storage, subject)+ mail(to: admin.mail, subject:)end- def notify_healthy(storage)+ def notify_healthy(admin, storage)+ @admin = admin@storage = storage+ @url = edit_admin_settings_storage_url(storage)subject = "Storage is back healthy!"- send_mail_to_admins(storage, subject)- end-- private-- def find_admins- @admins = User.where(admin: true)- .where.not(mail: [nil, ''])- end-- def send_mail_to_admins(storage, subject)- @admins.each do |admin|- mail(to: admin.mail, subject:)- end+ mail(to: admin.mail, subject:)endendenddiff --git a/modules/storages/app/services/storages/health/health_service.rb b/modules/storages/app/services/storages/health/health_service.rbindex bb1dd1a5e03..ccd75dc9cbb 100644--- a/modules/storages/app/services/storages/health/health_service.rb+++ b/modules/storages/app/services/storages/health/health_service.rb@@ -10,21 +10,30 @@ module Storages@storage.mark_as_healthy- ::Storages::StoragesMailer.notify_healthy(@storage).deliver_now if was_unhealthy+ admin_users.each do |admin|+ ::Storages::StoragesMailer.notify_healthy(admin, @storage).deliver_now if was_unhealthy+ endenddef unhealthy(reason:)@storage.mark_as_unhealthy(reason:)- ::Storages::StoragesMailer.notify_unhealthy(@storage, reason).deliver_now+ admin_users.each do |admin|+ ::Storages::StoragesMailer.notify_unhealthy(admin, @storage).deliver_now+ end- schedule_mail_job unless mail_job_exists?+ schedule_mail_job(@storage) unless mail_job_exists?endprivate- def schedule_mail_job- ::Storages::HealthStatusMailerJob.schedule+ def admin_users+ User.where(admin: true)+ .where.not(mail: [nil, ''])+ end++ def schedule_mail_job(storage)+ ::Storages::HealthStatusMailerJob.schedule(admins: admin_users, storage:)enddef mail_job_exists?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.erbindex 9202109f0a6..db7c94d72cc 100644--- a/modules/storages/app/views/storages/storages_mailer/notify_healthy.html.erb+++ b/modules/storages/app/views/storages/storages_mailer/notify_healthy.html.erb@@ -27,6 +27,6 @@ See COPYRIGHT and LICENSE files for more details.++#%>-<p><%= link_to(@storage.name, storage_url(@storage)) %> (<%= @storage.provider_type %>)</p>+<!--<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.erbindex f6351d23acf..41d983b1ab5 100644--- a/modules/storages/app/views/storages/storages_mailer/notify_healthy.text.erb+++ b/modules/storages/app/views/storages/storages_mailer/notify_healthy.text.erb@@ -28,6 +28,6 @@ See COPYRIGHT and LICENSE files for more details.++#%><%= @storage.name %> (<%= @storage.provider_type %>)-<%= storage_url(@storage) %>+<%#= 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.erbindex 9202109f0a6..672ac0ec6cf 100644--- a/modules/storages/app/views/storages/storages_mailer/notify_unhealthy.html.erb+++ b/modules/storages/app/views/storages/storages_mailer/notify_unhealthy.html.erb@@ -27,6 +27,34 @@ 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 %>+<table>+ <tr>+ <%= placeholder_cell('20px', vertical: false) %>+ </tr>+</table>++<table <%= placeholder_table_styles(width: '100%', style: 'width:100%;max-width:700px') %>>+ <tr>+ <%= placeholder_cell('12px', vertical: true) %>+ <td>+ <%+ summary = I18n.t("mail.storages.health.unhealthy.summary", storage_name: @storage.name)+ %>++ <%= render partial: 'mailer/mailer_header',+ locals: {+ user: @admin,+ summary:,+ button_href: @url,+ button_text: I18n.t(:'mail.storages.health.see_storage_settings'),+ } %>++ <table>+ <tr>+ <%= placeholder_cell('40px', vertical: false) %>+ </tr>+ </table>+ </td>+ <%= placeholder_cell('12px', vertical: true) %>+ </tr>+</table>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.erbindex f6351d23acf..26387caf337 100644--- a/modules/storages/app/views/storages/storages_mailer/notify_unhealthy.text.erb+++ b/modules/storages/app/views/storages/storages_mailer/notify_unhealthy.text.erb@@ -26,8 +26,3 @@ 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.rbindex d2c249544d0..e6decbc750f 100644--- a/modules/storages/app/workers/storages/health_status_mailer_job.rb+++ b/modules/storages/app/workers/storages/health_status_mailer_job.rb@@ -30,21 +30,23 @@module Storagesclass HealthStatusMailerJob < ApplicationJob- def perform(storage)+ def perform(admins:, storage:)if storage.health_healthy?returnend- Storages::StoragesMailer.notify_unhealthy(storage).deliver_now+ admins.each do |admin|+ Storages::StoragesMailer.notify_unhealthy(admin, storage).deliver_now+ end- schedule+ HealthStatusMailerJob.schedule(admins:, storage:)endclass << self- def schedule+ def schedule(admins:, storage:)next_run_time = Date.tomorrow.beginning_of_day + 2.hours- HealthStatusMailerJob.set(wait_until: next_run_time).perform_later+ HealthStatusMailerJob.set(wait_until: next_run_time).perform_later(admins: admins.records, storage:)endendend