Skip to content

Commit

Permalink
Merge remote-tracking branch 'openstreetmap/pull/1401' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Jan 28, 2017
2 parents 8a6e8ae + f83b719 commit b44635f
Show file tree
Hide file tree
Showing 18 changed files with 243 additions and 66 deletions.
Binary file added app/assets/images/osm_logo_30.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions app/helpers/notifier_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,24 @@ module NotifierHelper
def fp(text)
format_paragraph(text, 72, 0)
end

def link_to_user(display_name)
link_to(
display_name,
user_url(display_name, :host => SERVER_URL),
:target => "_blank",
:style => "text-decoration: none; color: #222; font-weight: bold"
)
end

def message_body(&block)
render(
:partial => "message_body",
:locals => { :body => capture(&block) }
)
end

def apply_inline_css(html)
html.gsub /<p>/, '<p style="color: black; margin: 0.75em 0">'
end
end
37 changes: 37 additions & 0 deletions app/models/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class Notifier < ActionMailer::Base
:return_path => EMAIL_RETURN_PATH,
:auto_submitted => "auto-generated"
helper :application
before_action :set_shared_template_vars
before_action :attach_project_logo

def signup_confirm(user, token)
with_recipient_locale user do
Expand Down Expand Up @@ -76,6 +78,9 @@ def message_notification(message)
@replyurl = url_for(:host => SERVER_URL,
:controller => "message", :action => "reply",
:message_id => message.id)
@author = @from_user

attach_user_avatar(message.sender)

mail :from => from_address(message.sender.display_name, "m", message.id, message.digest),
:to => message.recipient.email,
Expand Down Expand Up @@ -106,6 +111,9 @@ def diary_comment_notification(comment, recipient)
:action => "new",
:display_name => comment.user.display_name,
:title => "Re: #{comment.diary_entry.title}")
@author = @from_user

attach_user_avatar(comment.user)

mail :from => from_address(comment.user.display_name, "c", comment.id, comment.digest, recipient.id),
:to => recipient.email,
Expand All @@ -122,7 +130,9 @@ def friend_notification(friend)
@friendurl = url_for(:host => SERVER_URL,
:controller => "user", :action => "make_friend",
:display_name => @friend.befriender.display_name)
@author = @friend.befriender.display_name

attach_user_avatar(@friend.befriender)
mail :to => friend.befriendee.email,
:subject => I18n.t("notifier.friend_notification.subject", :user => friend.befriender.display_name)
end
Expand All @@ -142,6 +152,9 @@ def note_comment_notification(comment, recipient)
I18n.t("notifier.note_comment_notification.anonymous")
end

@author = @commenter
attach_user_avatar(comment.author)

subject = if @owner
I18n.t("notifier.note_comment_notification.#{@event}.subject_own", :commenter => @commenter)
else
Expand All @@ -161,19 +174,43 @@ def changeset_comment_notification(comment, recipient)
@changeset_comment = comment.changeset.tags["comment"].presence
@time = comment.created_at
@changeset_author = comment.changeset.user.display_name
@author = @commenter

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

attach_user_avatar(comment.author)

mail :to => recipient.email, :subject => subject
end
end

private

def set_shared_template_vars
@root_url = root_url(:host => SERVER_URL)
end

def attach_project_logo
attachments.inline["logo.png"] = File.read("#{Rails.root}/app/assets/images/osm_logo_30.png")
end

def attach_user_avatar(user)
attachments.inline["avatar.png"] = File.read(user_avatar_file_path(user))
end

def user_avatar_file_path(user)
image = user && user.image
if image && image.file?
return image.path(:small)
else
return "#{Rails.root}/app/assets/images/users/images/small.png"
end
end

def with_recipient_locale(recipient)
I18n.with_locale Locale.available.preferred(recipient.preferred_languages) do
yield
Expand Down
46 changes: 46 additions & 0 deletions app/views/layouts/notifier.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<html>
<head>
<meta charset="UTF-8"></meta>
</head>
<body style="padding: 0; margin: 0; font-size: 14px; font-family: 'Helvetica Neue', Arial, sans-serif; color: #222">
<table style="background-color: #eee; width: 100%">
<tr>
<td style="text-align: center">
<table style="width: 600px; color: #222; margin-left: auto; margin-right: auto">
<tr>
<td style="width: 30px; padding: 10px 10px 10px 0px">
<a href="<%= @root_url %>" target="_blank">
<%= image_tag attachments["logo.png"].url, alt: "OpenStreetMap logo", title: "OpenStreetMap", height: "30", width: "30", border: "0" %>
</a>
</td>
<td style="padding: 10px 0px">
<a href="<%= @root_url %>" target="_blank" style="text-decoration: none; color: #000">
<h1 style="font-size: 18px; font-weight: 600; margin: 0; text-align: left">OpenStreetMap</h1>
</a>
</td>
</tr>
<tr>
<td colspan="2">
<table style="background-color: #fff; color: #222; border: solid 1px #ccc; border-collapse: separate">
<tr>
<td style="text-align: left; padding: 0px 15px 5px 15px">
<%= raw apply_inline_css(yield) %>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="text-align: center; font-size: 11px">
<%= yield :footer %>
<p style="margin-bottom: 10px">
<a href="<%= @root_url %>" target="_blank" style="color: #222">OpenStreetMap</a>
</p>
</td>
</tr>
</table>
</body>
</html>
20 changes: 9 additions & 11 deletions app/views/notifier/_gpx_description.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<%= t'notifier.gpx_notification.greeting' %>
<%= t'notifier.gpx_notification.your_gpx_file' %>
<%= @trace_name %>
<strong><%= @trace_name %></strong>
<%= t'notifier.gpx_notification.with_description' %>
<%= @trace_description %>
<em><%= @trace_description %></em>
<% if @trace_tags.length>0 %>
<%= t'notifier.gpx_notification.and_the_tags' %>
<% @trace_tags.each do |tag| %>
<%= tag.tag.rstrip %><% end %><% else %>
<%= t'notifier.gpx_notification.and_no_tags' %><% end %>
<%= t'notifier.gpx_notification.and_the_tags' %>
<em><% @trace_tags.each do |tag| %>
<%= tag.tag.rstrip %>
<% end %></em>
<% else %>
<%= t'notifier.gpx_notification.and_no_tags' %>
<% end %>
21 changes: 21 additions & 0 deletions app/views/notifier/_message_body.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<table style="font-size: 15px; font-style: italic; margin: 15px 0px; background-color: #eee; width: 520px">
<tr>
<td style="width: 50px; vertical-align: top; padding: 15px">
<%= link_to(
image_tag(
attachments["avatar.png"].url,
alt: @author,
title: @author,
width: 50,
height: 50,
border: 0
),
user_url(@author, :host => SERVER_URL),
:target => "_blank"
) %>
</td>
<td style="text-align: left; vertical-align: top; padding-right: 10px">
<%= body %>
</td>
</tr>
</table>
24 changes: 15 additions & 9 deletions app/views/notifier/changeset_comment_notification.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<p><%= t 'notifier.changeset_comment_notification.greeting' %></p>

<p>
<% if @owner %>
<%= t "notifier.changeset_comment_notification.commented.your_changeset", :commenter => @commenter, :time => @time %>
<%= raw t "notifier.changeset_comment_notification.commented.your_changeset", :commenter => link_to_user(@commenter), :time => @time %>
<% else %>
<%= t "notifier.changeset_comment_notification.commented.commented_changeset", :commenter => @commenter, :time => @time, :changeset_author => @changeset_author %>
<%= raw t "notifier.changeset_comment_notification.commented.commented_changeset", :commenter => link_to_user(@commenter), :time => @time, :changeset_author => @changeset_author %>
<% end %>
<% if @changeset_comment %>
<%= t "notifier.changeset_comment_notification.commented.partial_changeset_with_comment", :changeset_comment => @changeset_comment %>
<%= raw t "notifier.changeset_comment_notification.commented.partial_changeset_with_comment", :changeset_comment => content_tag("em", @changeset_comment) %>
<% else %>
<%= t "notifier.changeset_comment_notification.commented.partial_changeset_without_comment" %>
<% end %>
</p>

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

<p>
<%= raw t 'notifier.changeset_comment_notification.details', :url => link_to(@changeset_url, @changeset_url, :style => "white-space: nowrap") %>
</p>

<p><%= raw t 'notifier.changeset_comment_notification.details', :url => link_to(@changeset_url, @changeset_url) %></p>
<% content_for :footer do %>
<p>
<%= raw t 'notifier.changeset_comment_notification.unsubscribe', :url => link_to(@changeset_url, @changeset_url, :style => "color: #222; white-space: nowrap") %>
</p>
<% end %>
23 changes: 16 additions & 7 deletions app/views/notifier/diary_comment_notification.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<p><%= t'notifier.diary_comment_notification.hi', :to_user => @to_user %></p>
<p>
<%= t'notifier.diary_comment_notification.hi', :to_user => @to_user %>
</p>
<p>
<%= raw t'notifier.diary_comment_notification.header', :from_user => link_to_user(@from_user), :subject => content_tag("em", @title) %>
</p>

<p><%= raw t'notifier.diary_comment_notification.header', :from_user => link_to(@from_user, :host => SERVER_URL, :controller => :user, :action => :view, :display_name => @from_user), :subject => @title %></p>
<%= message_body do %>
<%= @text.to_html %>
<% end %>
==
<%= @text.to_html %>
==

<p><%= raw t'notifier.diary_comment_notification.footer', :readurl => link_to(@readurl, @readurl), :commenturl => link_to(@commenturl, @commenturl), :replyurl => link_to(@replyurl, @replyurl) %></p>
<% content_for :footer do %>
<p><%= raw t'notifier.diary_comment_notification.footer',
: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/notifier/email_confirm.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

<p><%= t 'notifier.email_confirm_html.click_the_link' %></p>

<p><a href="<%= @url %>"><%= @url %></a></p>
<p><a href="<%= @url %>" style="white-space: nowrap"><%= @url %></a></p>
10 changes: 6 additions & 4 deletions app/views/notifier/friend_notification.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<p><%= t 'notifier.friend_notification.had_added_you', :user => @friend.befriender.display_name %></p>

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

<% unless @friend.befriendee.is_friends_with?(@friend.befriender) -%>
<p><%= raw t 'notifier.friend_notification.befriend_them', :befriendurl => link_to(@friendurl, @friendurl) %></p>
<% end -%>
<% unless @friend.befriendee.is_friends_with?(@friend.befriender) -%>
<p><%= raw t 'notifier.friend_notification.befriend_them', :befriendurl => link_to(@friendurl, @friendurl) %></p>
<% end -%>
<% end %>
17 changes: 12 additions & 5 deletions app/views/notifier/gpx_failure.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<%= render :partial => "gpx_description" %>
<%= t'notifier.gpx_notification.failure.failed_to_import' %>
<p><%= t'notifier.gpx_notification.greeting' %></p>

<%= @error %>
<p>
<%= render :partial => "gpx_description" %>
<%= t'notifier.gpx_notification.failure.failed_to_import' %>
</p>

<%= t'notifier.gpx_notification.failure.more_info_1' %>
<%= t'notifier.gpx_notification.failure.more_info_2' %>
<blockquote>
<%= @error %>
</blockquote>

<p>
<%= t'notifier.gpx_notification.failure.more_info_1' %>
<%= t'notifier.gpx_notification.failure.more_info_2' %>
<%= t'notifier.gpx_notification.failure.import_failures_url' %>
</p>
8 changes: 6 additions & 2 deletions app/views/notifier/gpx_success.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
<%= render :partial => "gpx_description" %>
<%= t'notifier.gpx_notification.success.loaded_successfully', :trace_points => @trace_points, :possible_points => @possible_points %>
<p><%= t'notifier.gpx_notification.greeting' %></p>

<p>
<%= render :partial => "gpx_description" %>
<%= t'notifier.gpx_notification.success.loaded_successfully', :trace_points => @trace_points, :possible_points => @possible_points %>
</p>
27 changes: 20 additions & 7 deletions app/views/notifier/message_notification.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
<p><%= t'notifier.message_notification.hi', :to_user => @to_user %></p>
<p>
<%= t'notifier.message_notification.hi', :to_user => @to_user %>
</p>
<p>
<%= raw t'notifier.message_notification.header',
:from_user => link_to_user(@from_user),
:subject => content_tag("em", @title)
%>
</p>

<p><%= raw t'notifier.message_notification.header', :from_user => link_to(@from_user, :host => SERVER_URL, :controller => :user, :action => :view, :display_name => @from_user), :subject => @title %></p>
<%= message_body do %>
<%= @text.to_html %>
<% end %>
==
<%= @text.to_html %>
==

<p><%= t'notifier.message_notification.footer_html', :readurl => link_to(@readurl, @readurl), :replyurl => link_to(@replyurl, @replyurl) %></p>
<% content_for :footer do %>
<p>
<%= t'notifier.message_notification.footer_html',
:readurl => link_to(@readurl, @readurl) + tag(:br),
:replyurl => link_to(@replyurl, @replyurl)
%>
</p>
<% end %>
10 changes: 5 additions & 5 deletions app/views/notifier/note_comment_notification.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<p><%= t 'notifier.note_comment_notification.greeting' %></p>

<% if @owner %>
<p><%= t "notifier.note_comment_notification.#{@event}.your_note", :commenter => @commenter, :place => @place %></p>
<p><%= raw t "notifier.note_comment_notification.#{@event}.your_note", :commenter => link_to_user(@commenter), :place => @place %></p>
<% else %>
<p><%= t "notifier.note_comment_notification.#{@event}.commented_note", :commenter => @commenter, :place => @place %></p>
<p><%= raw t "notifier.note_comment_notification.#{@event}.commented_note", :commenter => link_to_user(@commenter), :place => @place %></p>
<% end %>
==
<%= @comment.to_html %>
==
<%= message_body do %>
<%= @comment.to_html %>
<% end %>

<p><%= raw t 'notifier.note_comment_notification.details', :url => link_to(@noteurl, @noteurl) %></p>
2 changes: 1 addition & 1 deletion app/views/notifier/signup_confirm.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

<p><%= t("notifier.signup_confirm.confirm") %></p>

<p><%= link_to @url, @url %></p>
<p><%= link_to @url, @url, :style => "white-space: nowrap" %></p>

<p><%= t("notifier.signup_confirm.welcome") %></p>
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,7 @@ en:
commented_note: "%{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}."
changeset_comment_notification:
hi: "Hi %{to_user},"
greeting: "Hi,"
commented:
subject_own: "[OpenStreetMap] %{commenter} has commented on one of your changesets"
Expand All @@ -1319,6 +1320,7 @@ en:
partial_changeset_with_comment: "with comment '%{changeset_comment}'"
partial_changeset_without_comment: "without comment"
details: "More details about the changeset can be found at %{url}."
unsubscribe: 'To unsubscribe from updates to this changeset, visit %{url} and click "Unsubscribe".'
message:
inbox:
title: "Inbox"
Expand Down
Loading

0 comments on commit b44635f

Please sign in to comment.