Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementation/60342 Update reminder email subject to include the note #17504

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading