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

Mailer refactoring #2993

Merged
merged 6 commits into from
Dec 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 13 additions & 13 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def signup_confirm(user, token)
:confirm_string => token.token)

mail :to => user.email,
:subject => I18n.t("user_mailer.signup_confirm.subject")
:subject => t(".subject")
end
end

Expand All @@ -28,7 +28,7 @@ def email_confirm(user, token)
:confirm_string => token.token)

mail :to => user.new_email,
:subject => I18n.t("user_mailer.email_confirm.subject")
:subject => t(".subject")
end
end

Expand All @@ -38,7 +38,7 @@ def lost_password(user, token)
:token => token.token)

mail :to => user.email,
:subject => I18n.t("user_mailer.lost_password.subject")
:subject => t(".subject")
end
end

Expand All @@ -52,7 +52,7 @@ def gpx_success(trace, possible_points)
@possible_points = possible_points

mail :to => trace.user.email,
:subject => I18n.t("user_mailer.gpx_success.subject")
:subject => t(".subject")
end
end

Expand All @@ -65,7 +65,7 @@ def gpx_failure(trace, error)
@error = error

mail :to => trace.user.email,
:subject => I18n.t("user_mailer.gpx_failure.subject")
:subject => t(".subject")
end
end

Expand All @@ -83,7 +83,7 @@ def message_notification(message)

mail :from => from_address(message.sender.display_name, "m", message.id, message.digest),
:to => message.recipient.email,
:subject => I18n.t("user_mailer.message_notification.subject_header", :subject => message.title)
:subject => t(".subject", :message_title => message.title)
end
end

Expand All @@ -104,7 +104,7 @@ def diary_comment_notification(comment, recipient)

mail :from => from_address(comment.user.display_name, "c", comment.id, comment.digest, recipient.id),
:to => recipient.email,
:subject => I18n.t("user_mailer.diary_comment_notification.subject", :user => comment.user.display_name)
:subject => t(".subject", :user => comment.user.display_name)
end
end

Expand All @@ -117,7 +117,7 @@ def friendship_notification(friendship)

attach_user_avatar(@friendship.befriender)
mail :to => friendship.befriendee.email,
:subject => I18n.t("user_mailer.friendship_notification.subject", :user => friendship.befriender.display_name)
:subject => t(".subject", :user => friendship.befriender.display_name)
end
end

Expand All @@ -132,7 +132,7 @@ def note_comment_notification(comment, recipient)
@commenter = if comment.author
comment.author.display_name
else
I18n.t("user_mailer.note_comment_notification.anonymous")
t(".anonymous")
end

@author = @commenter
Expand All @@ -141,9 +141,9 @@ def note_comment_notification(comment, recipient)
set_references("note", comment.note)

subject = if @owner
I18n.t("user_mailer.note_comment_notification.#{@event}.subject_own", :commenter => @commenter)
t(".#{@event}.subject_own", :commenter => @commenter)
else
I18n.t("user_mailer.note_comment_notification.#{@event}.subject_other", :commenter => @commenter)
t(".#{@event}.subject_other", :commenter => @commenter)
end

mail :to => recipient.email, :subject => subject
Expand All @@ -163,9 +163,9 @@ def changeset_comment_notification(comment, recipient)
@author = @commenter

subject = if @owner
I18n.t("user_mailer.changeset_comment_notification.commented.subject_own", :commenter => @commenter)
t(".commented.subject_own", :commenter => @commenter)
else
I18n.t("user_mailer.changeset_comment_notification.commented.subject_other", :commenter => @commenter)
t(".commented.subject_other", :commenter => @commenter)
end

attach_user_avatar(comment.author)
Expand Down
10 changes: 5 additions & 5 deletions app/views/user_mailer/changeset_comment_notification.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
</p>
<p>
<% if @owner %>
<%= raw t ".commented.your_changeset", :commenter => link_to_user(@commenter), :time => @time %>
<%= t ".commented.your_changeset_html", :commenter => link_to_user(@commenter), :time => @time %>
<% else %>
<%= raw t ".commented.commented_changeset", :commenter => link_to_user(@commenter), :time => @time, :changeset_author => @changeset_author %>
<%= t ".commented.commented_changeset_html", :commenter => link_to_user(@commenter), :time => @time, :changeset_author => @changeset_author %>
<% end %>
<% if @changeset_comment %>
<%= raw t ".commented.partial_changeset_with_comment", :changeset_comment => tag.em(@changeset_comment) %>
<%= t ".commented.partial_changeset_with_comment_html", :changeset_comment => tag.em(@changeset_comment) %>
<% else %>
<%= t ".commented.partial_changeset_without_comment" %>
<% end %>
Expand All @@ -19,11 +19,11 @@
<% end %>

<p>
<%= raw t ".details", :url => link_to(@changeset_url, @changeset_url) %>
<%= t ".details_html", :url => link_to(@changeset_url, @changeset_url) %>
</p>

<% content_for :footer do %>
<p>
<%= raw t ".unsubscribe", :url => link_to(@changeset_url, @changeset_url, :style => "color: #222") %>
<%= t ".unsubscribe_html", :url => link_to(@changeset_url, @changeset_url, :style => "color: #222") %>
</p>
<% end %>
10 changes: 5 additions & 5 deletions app/views/user_mailer/diary_comment_notification.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<%= t ".hi", :to_user => @to_user %>
</p>
<p>
<%= raw t ".header", :from_user => link_to_user(@from_user), :subject => tag.em(@title) %>
<%= t ".header_html", :from_user => link_to_user(@from_user), :subject => tag.em(@title) %>
</p>

<%= message_body do %>
<%= @text.to_html %>
<% end %>

<% content_for :footer do %>
<p><%= raw t ".footer",
:readurl => link_to(@readurl, @readurl) + tag(:br),
:commenturl => link_to(@commenturl, @commenturl) + tag(:br),
:replyurl => link_to(@replyurl, @replyurl) %>
<p><%= t ".footer_html",
:readurl => link_to(@readurl, @readurl) + tag(:br),
:commenturl => link_to(@commenturl, @commenturl) + tag(:br),
:replyurl => link_to(@replyurl, @replyurl) %>
</p>
<% end %>
2 changes: 1 addition & 1 deletion app/views/user_mailer/diary_comment_notification.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= t '.header', :from_user => @from_user, :subject => @title %>

==
<%= raw @text.to_text %>
<%= @text.to_text %>
==

<%= t '.footer', :readurl => @readurl, :commenturl => @commenturl, :replyurl => @replyurl %>
6 changes: 3 additions & 3 deletions app/views/user_mailer/email_confirm.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p><%= t "user_mailer.email_confirm_html.greeting" %></p>
<p><%= t ".greeting" %></p>

<p><%= t "user_mailer.email_confirm_html.hopefully_you", :server_url => Settings.server_url, :new_address => @address %></p>
<p><%= t ".hopefully_you", :server_url => Settings.server_url, :new_address => @address %></p>

<p><%= t "user_mailer.email_confirm_html.click_the_link" %></p>
<p><%= t ".click_the_link" %></p>

<p><a href="<%= @url %>"><%= @url %></a></p>
6 changes: 3 additions & 3 deletions app/views/user_mailer/email_confirm.text.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= t 'user_mailer.email_confirm_plain.greeting' %>
<%= t '.greeting' %>

<%= word_wrap(t 'user_mailer.email_confirm_plain.hopefully_you', :server_url => Settings.server_url, :new_address => @address) %>
<%= word_wrap(t '.hopefully_you', :server_url => Settings.server_url, :new_address => @address) %>

<%= t 'user_mailer.email_confirm_plain.click_the_link' %>
<%= t '.click_the_link' %>

<%= @url %>
4 changes: 2 additions & 2 deletions app/views/user_mailer/friendship_notification.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<p><%= t ".had_added_you", :user => @friendship.befriender.display_name %></p>

<%= message_body do %>
<p><%= raw t ".see_their_profile", :userurl => link_to(@viewurl, @viewurl) %></p>
<p><%= t ".see_their_profile_html", :userurl => link_to(@viewurl, @viewurl) %></p>

<% unless @friendship.befriendee.is_friends_with?(@friendship.befriender) -%>
<p><%= raw t ".befriend_them", :befriendurl => link_to(@friendurl, @friendurl) %></p>
<p><%= t ".befriend_them_html", :befriendurl => link_to(@friendurl, @friendurl) %></p>
<% end -%>
<% end %>
6 changes: 3 additions & 3 deletions app/views/user_mailer/lost_password.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p><%= t "user_mailer.lost_password_html.greeting" %></p>
<p><%= t ".greeting" %></p>

<p><%= t "user_mailer.lost_password_html.hopefully_you" %></p>
<p><%= t ".hopefully_you" %></p>

<p><%= t "user_mailer.lost_password_html.click_the_link" %></p>
<p><%= t ".click_the_link" %></p>

<p><a href="<%= @url %>"><%= @url %></a></p>
6 changes: 3 additions & 3 deletions app/views/user_mailer/lost_password.text.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= t 'user_mailer.lost_password_plain.greeting' %>
<%= t '.greeting' %>

<%= word_wrap(t 'user_mailer.lost_password_plain.hopefully_you') %>
<%= word_wrap(t '.hopefully_you') %>

<%= t 'user_mailer.lost_password_plain.click_the_link' %>
<%= t '.click_the_link' %>

<%= @url %>
6 changes: 3 additions & 3 deletions app/views/user_mailer/message_notification.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<%= t ".hi", :to_user => @to_user %>
</p>
<p>
<%= raw t ".header",
:from_user => link_to_user(@from_user),
:subject => tag.em(@title) %>
<%= t ".header",
:from_user => link_to_user(@from_user),
:subject => tag.em(@title) %>
</p>

<%= message_body do %>
Expand Down
8 changes: 4 additions & 4 deletions app/views/user_mailer/message_notification.text.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<%= raw t '.hi', :to_user => @to_user %>
<%= t '.hi', :to_user => @to_user %>

<%= raw t '.header', :from_user => @from_user, :subject => @title %>
<%= t '.header', :from_user => @from_user, :subject => @title %>

==
<%= raw @text.to_text %>
<%= @text.to_text %>
==

<%= word_wrap(t '.footer_html', :readurl => @readurl, :replyurl => @replyurl) %>
<%= word_wrap(t '.footer', :readurl => @readurl, :replyurl => @replyurl) %>
6 changes: 3 additions & 3 deletions app/views/user_mailer/note_comment_notification.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<p><%= t ".greeting" %></p>

<% if @owner %>
<p><%= raw t ".#{@event}.your_note", :commenter => link_to_user(@commenter), :place => @place %></p>
<p><%= t ".#{@event}.your_note_html", :commenter => link_to_user(@commenter), :place => @place %></p>
<% else %>
<p><%= raw t ".#{@event}.commented_note", :commenter => link_to_user(@commenter), :place => @place %></p>
<p><%= t ".#{@event}.commented_note_html", :commenter => link_to_user(@commenter), :place => @place %></p>
<% end %>

<% unless @comment.empty? %>
Expand All @@ -12,4 +12,4 @@
<% end %>
<% end %>

<p><%= raw t ".details", :url => link_to(@noteurl, @noteurl) %></p>
<p><%= t ".details_html", :url => link_to(@noteurl, @noteurl) %></p>
30 changes: 19 additions & 11 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1414,18 +1414,24 @@ en:
subject: "[OpenStreetMap] %{user} commented on a diary entry"
hi: "Hi %{to_user},"
header: "%{from_user} has commented on the OpenStreetMap diary entry with the subject %{subject}:"
header_html: "%{from_user} has commented on the OpenStreetMap diary entry with the subject %{subject}:"
footer: "You can also read the comment at %{readurl} and you can comment at %{commenturl} or send a message to the author at %{replyurl}"
footer_html: "You can also read the comment at %{readurl} and you can comment at %{commenturl} or send a message to the author at %{replyurl}"
message_notification:
subject_header: "[OpenStreetMap] %{subject}"
subject: "[OpenStreetMap] %{message_title}"
hi: "Hi %{to_user},"
header: "%{from_user} has sent you a message through OpenStreetMap with the subject %{subject}:"
header_html: "%{from_user} has sent you a message through OpenStreetMap with the subject %{subject}:"
footer: "You can also read the message at %{readurl} and you can send a message to the author at %{replyurl}"
footer_html: "You can also read the message at %{readurl} and you can send a message to the author at %{replyurl}"
friendship_notification:
hi: "Hi %{to_user},"
subject: "[OpenStreetMap] %{user} added you as a friend"
had_added_you: "%{user} has added you as a friend on OpenStreetMap."
see_their_profile: "You can see their profile at %{userurl}."
see_their_profile_html: "You can see their profile at %{userurl}."
befriend_them: "You can also add them as a friend at %{befriendurl}."
befriend_them_html: "You can also add them as a friend at %{befriendurl}."
gpx_description:
description_with_tags_html: "It looks like your GPX file %{trace_name} with the description %{trace_description} and the following tags: %{tags}"
description_with_no_tags_html: "It looks like your GPX file %{trace_name} with the description %{trace_description} and no tags"
Expand All @@ -1449,21 +1455,11 @@ en:
welcome: "After you confirm your account, we'll provide you with some additional information to get you started."
email_confirm:
subject: "[OpenStreetMap] Confirm your email address"
email_confirm_plain:
greeting: "Hi,"
hopefully_you: "Someone (hopefully you) would like to change their email address over at %{server_url} to %{new_address}."
click_the_link: "If this is you, please click the link below to confirm the change."
email_confirm_html:
greeting: "Hi,"
hopefully_you: "Someone (hopefully you) would like to change their email address over at %{server_url} to %{new_address}."
click_the_link: "If this is you, please click the link below to confirm the change."
lost_password:
subject: "[OpenStreetMap] Password reset request"
lost_password_plain:
greeting: "Hi,"
hopefully_you: "Someone (possibly you) has asked for the password to be reset on this email address's openstreetmap.org account."
click_the_link: "If this is you, please click the link below to reset your password."
lost_password_html:
greeting: "Hi,"
hopefully_you: "Someone (possibly you) has asked for the password to be reset on this email address's openstreetmap.org account."
click_the_link: "If this is you, please click the link below to reset your password."
Expand All @@ -1474,30 +1470,42 @@ en:
subject_own: "[OpenStreetMap] %{commenter} has commented on one of your notes"
subject_other: "[OpenStreetMap] %{commenter} has commented on a note you are interested in"
your_note: "%{commenter} has left a comment on one of your map notes near %{place}."
your_note_html: "%{commenter} has left a comment on one of your map notes near %{place}."
commented_note: "%{commenter} has left a comment on a map note you have commented on. The note is near %{place}."
commented_note_html: "%{commenter} has left a comment on a map note you have commented on. The note is near %{place}."
closed:
subject_own: "[OpenStreetMap] %{commenter} has resolved one of your notes"
subject_other: "[OpenStreetMap] %{commenter} has resolved a note you are interested in"
your_note: "%{commenter} has resolved one of your map notes near %{place}."
your_note_html: "%{commenter} has resolved one of your map notes near %{place}."
commented_note: "%{commenter} has resolved a map note you have commented on. The note is near %{place}."
commented_note_html: "%{commenter} has resolved a map note you have commented on. The note is near %{place}."
reopened:
subject_own: "[OpenStreetMap] %{commenter} has reactivated one of your notes"
subject_other: "[OpenStreetMap] %{commenter} has reactivated a note you are interested in"
your_note: "%{commenter} has reactivated one of your map notes near %{place}."
your_note_html: "%{commenter} has reactivated one of your map notes near %{place}."
commented_note: "%{commenter} has reactivated a map note you have commented on. The note is near %{place}."
commented_note_html: "%{commenter} has reactivated a map note you have commented on. The note is near %{place}."
details: "More details about the note can be found at %{url}."
details_html: "More details about the note can be found at %{url}."
changeset_comment_notification:
hi: "Hi %{to_user},"
greeting: "Hi,"
commented:
subject_own: "[OpenStreetMap] %{commenter} has commented on one of your changesets"
subject_other: "[OpenStreetMap] %{commenter} has commented on a changeset you are interested in"
your_changeset: "%{commenter} left a comment at %{time} on one of your changesets"
your_changeset_html: "%{commenter} left a comment at %{time} on one of your changesets"
commented_changeset: "%{commenter} left a comment at %{time} on a changeset you are watching created by %{changeset_author}"
commented_changeset_html: "%{commenter} left a comment at %{time} on a changeset you are watching created by %{changeset_author}"
partial_changeset_with_comment: "with comment '%{changeset_comment}'"
partial_changeset_with_comment_html: "with comment '%{changeset_comment}'"
partial_changeset_without_comment: "without comment"
details: "More details about the changeset can be found at %{url}."
details_html: "More details about the changeset can be found at %{url}."
unsubscribe: 'To unsubscribe from updates to this changeset, visit %{url} and click "Unsubscribe".'
unsubscribe_html: 'To unsubscribe from updates to this changeset, visit %{url} and click "Unsubscribe".'
messages:
inbox:
title: "Inbox"
Expand Down
9 changes: 9 additions & 0 deletions test/mailers/user_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ def test_gpx_description_tags

assert_match(/one two three/, email.html_part.body.to_s)
end

def test_html_encoding
user = create(:user, :display_name => "Jack & Jill <br>")
message = create(:message, :sender => user)
email = UserMailer.message_notification(message)

assert_match("Jack & Jill <br>", email.text_part.body.to_s)
assert_match("Jack &amp; Jill &lt;br&gt;", email.html_part.body.to_s)
end
end