Skip to content

Commit

Permalink
implementation/60342 Update reminder email subject to include the note (
Browse files Browse the repository at this point in the history
#17504)

https://community.openproject.org/work_packages/60342

Reminder email template will be redesigned to differentiate from notifications. In the meantime,
we add the note or work package subject in the email subject as a tiny enhancements.
  • Loading branch information
akabiru authored Dec 19, 2024
1 parent a489f17 commit 0d7ebce
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
27 changes: 22 additions & 5 deletions app/mailers/reminders/notification_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,50 @@ class Reminders::NotificationMailer < ApplicationMailer
helper :mail_notification
helper_method :reminder_summary_text,
:reminder_timestamp_text,
:reminder_note_text
:reminder_note_text,
:work_package_subject_text_wrapper,
:text_email_wrapper

def reminder_notification(notification)
@notification = notification
@user = notification.recipient
@work_package = notification.resource
@reminder = notification.reminder

open_project_headers User: notification.recipient.name
message_id "reminder", notification.recipient

send_localized_mail(notification.recipient) do
"#{Setting.app_title} - #{reminder_summary_text}"
"#{Setting.app_title} - #{email_subject_suffix}"
end
end

private

def email_subject_suffix
note = @reminder.note.presence || @work_package.subject
I18n.t(:"mail.reminder_notifications.subject", note:)
end

def reminder_summary_text
I18n.t(:"mail.reminder_notifications.subject")
I18n.t(:"mail.reminder_notifications.heading")
end

def reminder_timestamp_text
"#{format_time(@notification.created_at)}."
end

def reminder_note_text
return if @notification.reminder.note.blank?
return if @reminder.note.blank?

I18n.t(:"mail.reminder_notifications.note", note: @reminder.note)
end

def work_package_subject_text_wrapper
"=" * ("# #{@work_package.id}#{@work_package.subject}".length + 4)
end

I18n.t(:"mail.reminder_notifications.note", note: @notification.reminder.note)
def text_email_wrapper
"-" * 100
end
end
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<%= I18n.t(:'mail.salutation', user: @user.firstname) %>
<%= reminder_summary_text %>
<%= "-" * 100 %>
<%= text_email_wrapper %>

<% 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) %>
<%= work_package_subject_text_wrapper %>
= #<%= @work_package.id %> <%= @work_package.subject %> =
<%= work_package_subject_text_wrapper %>

<%= reminder_timestamp_text %>
<%= reminder_note_text %>

<%= "-" * 100 %>
<%= text_email_wrapper %>
3 changes: 2 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2990,7 +2990,8 @@ en:
see_all: "See all"
updated_at: "Updated at %{timestamp} by %{user}"
reminder_notifications:
subject: "You have a new reminder"
subject: "Reminder: %{note}"
heading: "You have a new reminder"
note: "Note: “%{note}”"
sharing:
work_packages:
Expand Down
18 changes: 16 additions & 2 deletions spec/mailers/reminders/notification_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,22 @@

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")
describe "Email subject" do
context "when the reminder has a note" do
it "includes the note" do
expect(mail.subject).to eql("OpenProject - Reminder: This is an important reminder")
end
end

context "when the reminder does not have a note" do
before do
notification.reminder.note = ""
end

it "includes the work package subject" do
expect(mail.subject).to eql("OpenProject - Reminder: #{work_package.subject}")
end
end
end

it "sends to the recipient" do
Expand Down

0 comments on commit 0d7ebce

Please sign in to comment.