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
Define reminder notification mailer template
Kabiru Mwenja2e5a638db943
diff --git a/app/mailers/reminders/notification_mailer.rb b/app/mailers/reminders/notification_mailer.rbnew file mode 100644index 00000000000..079d71e1559--- /dev/null+++ b/app/mailers/reminders/notification_mailer.rb@@ -0,0 +1,65 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++class Reminders::NotificationMailer < ApplicationMailer+ include MailNotificationHelper+ include Redmine::I18n++ helper :mail_notification+ helper_method :reminder_summary_text,+ :reminder_timestamp_text,+ :reminder_note_text++ def reminder_notification(notification)+ @notification = notification+ @user = notification.recipient++ open_project_headers User: notification.recipient.name+ message_id "reminder", notification.recipient++ send_localized_mail(notification.recipient) do+ "#{Setting.app_title} - #{reminder_summary_text}"+ end+ end++ private++ def reminder_summary_text+ I18n.t(:"mail.reminder_notifications.subject")+ end++ def reminder_timestamp_text+ "#{format_time(@notification.created_at)}."+ end++ def reminder_note_text+ return if @notification.reminder.note.blank?++ I18n.t(:"mail.reminder_notifications.note", note: @notification.reminder.note)+ end+enddiff --git a/app/views/reminders/notification_mailer/reminder_notification.html.erb b/app/views/reminders/notification_mailer/reminder_notification.html.erbnew file mode 100644index 00000000000..aea025f165e--- /dev/null+++ b/app/views/reminders/notification_mailer/reminder_notification.html.erb@@ -0,0 +1,54 @@+<table <%= placeholder_table_styles %>>+ <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>+ <%= render partial: 'mailer/mailer_header',+ locals: {+ summary: reminder_summary_text,+ button_href: notifications_url,+ button_text: I18n.t(:'mail.notification.center'),+ user: @user,+ } %>++ <%= render layout: 'mailer/notification_row',+ locals: {+ work_package: @notification.resource,+ unique_reasons: [@notification.reason],+ show_count: true,+ count: 1,+ user: @user+ } do %>+ <table <%= placeholder_table_styles %>>+ <tr>+ <td style="line-height: 24px; font-size: 14px; white-space: normal;">+ <span style="color: #878787;">+ <%= reminder_timestamp_text %>+ </span>+ <%= reminder_note_text %>+ </td>+ </tr>+ </table>+ <% end %>++ <%= render layout: 'mailer/notification_settings_table',+ locals: {+ button_url: my_reminders_url,+ button_text: I18n.t(:'mail.notification.settings')+ } do %>+ <% end %>++ <table>+ <tr>+ <%= placeholder_cell('40px', vertical: false) %>+ </tr>+ </table>+ </td>+ <%= placeholder_cell('12px', vertical: true) %>+ </tr>+</table>diff --git a/app/views/reminders/notification_mailer/reminder_notification.text.erb b/app/views/reminders/notification_mailer/reminder_notification.text.erbnew file mode 100644index 00000000000..b48361bb643--- /dev/null+++ b/app/views/reminders/notification_mailer/reminder_notification.text.erb@@ -0,0 +1,14 @@+<%= I18n.t(:'mail.salutation', user: @user.firstname) %>+<%= reminder_summary_text %>+<%= "-" * 100 %>++<% work_package = @notification.resource %>++<%= "=" * (('# ' + work_package.id.to_s + work_package.subject).length + 4) %>+= #<%= work_package.id %> <%= work_package.subject %> =+<%= "=" * (('# ' + work_package.id.to_s + work_package.subject).length + 4) %>++<%= reminder_timestamp_text %>+<%= reminder_note_text %>++<%= "-" * 100 %>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex e42776da9bd..6a1ec549639 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2938,8 +2938,12 @@ en:prefix: "Received because of the notification setting: %{reason}"date_alert_start_date: "Date alert"date_alert_due_date: "Date alert"+ reminder: "Reminder"see_all: "See all"updated_at: "Updated at %{timestamp} by %{user}"+ reminder_notifications:+ subject: "You have a new reminder"+ note: "Note: “%{note}”"sharing:work_packages:allowed_actions: "You may %{allowed_actions} this work package. This can change depending on your project role and permissions."diff --git a/spec/mailers/previews/reminders/notification_mailer_preview.rb b/spec/mailers/previews/reminders/notification_mailer_preview.rbnew file mode 100644index 00000000000..f14b979f07c--- /dev/null+++ b/spec/mailers/previews/reminders/notification_mailer_preview.rb@@ -0,0 +1,36 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++# Preview all emails at http://localhost:3000/rails/mailers/reminders/notification_mailer+class Reminders::NotificationMailerPreview < ActionMailer::Preview+ # Preview this email at http://localhost:3000/rails/mailers/reminders/notification_mailer/reminder_notification+ def reminder_notification+ notification = Notification.where(reason: :reminder).first+ Reminders::NotificationMailer.reminder_notification(notification)+ end+enddiff --git a/spec/mailers/reminders/notification_mailer_spec.rb b/spec/mailers/reminders/notification_mailer_spec.rbnew file mode 100644index 00000000000..a7ac45875fe--- /dev/null+++ b/spec/mailers/reminders/notification_mailer_spec.rb@@ -0,0 +1,69 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++require "spec_helper"++RSpec.describe Reminders::NotificationMailer do+ let(:work_package) { build_stubbed(:work_package) }+ let(:user) { build_stubbed(:user) }+ let(:recipient) { user }++ let(:notification) do+ reminder = build_stubbed(:reminder, remindable: work_package, creator: user, note: "This is an important reminder")+ build_stubbed(:notification, reason: :reminder, recipient:, resource: work_package, reminder:)+ end++ describe "#reminder_notification" do+ subject(:mail) { described_class.reminder_notification(notification) }++ let(:mail_body) { mail.body.parts.detect { |part| part["Content-Type"].value == "text/html" }.body.to_s }++ it "notes reminder in subject" do+ expect(mail.subject).to eql("OpenProject - You have a new reminder")+ end++ it "sends to the recipient" do+ expect(mail.to)+ .to contain_exactly(recipient.mail)+ end++ it "sets the expected message_id header" do+ expect(mail.message_id)+ .to eql "op.reminder.#{Time.current.strftime('%Y%m%d%H%M%S')}.#{recipient.id}@example.net"+ end++ it "sets the expected openproject headers" do+ expect(mail["X-OpenProject-User"]&.value)+ .to eql(recipient.name)+ end++ it "mail body includes the reminder note" do+ expect(mail_body).to include("Note: “This is an important reminder”")+ end+ end+end