Commit 570ebb2aa16cf18f7987838f857a3da574a1af19
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'fix_person_notifier' into stable
Showing
8 changed files
with
76 additions
and
23 deletions
Show diff stats
app/models/person_notifier.rb
... | ... | @@ -22,12 +22,17 @@ class PersonNotifier |
22 | 22 | schedule_next_notification_mail |
23 | 23 | end |
24 | 24 | |
25 | + def notify_from | |
26 | + @person.last_notification || DateTime.now - @person.notification_time.hours | |
27 | + end | |
28 | + | |
25 | 29 | def notify |
26 | 30 | if @person.notification_time && @person.notification_time > 0 |
27 | - from = @person.last_notification || DateTime.now - @person.notification_time.hours | |
28 | - notifications = @person.tracked_notifications.find(:all, :conditions => ["created_at > ?", from]) | |
31 | + notifications = @person.tracked_notifications.find(:all, :conditions => ["created_at > ?", notify_from]) | |
32 | + tasks = Task.to(@person).without_spam.pending.where("created_at > ?", notify_from).order_by('created_at', 'asc') | |
33 | + | |
29 | 34 | Noosfero.with_locale @person.environment.default_language do |
30 | - Mailer::content_summary(@person, notifications).deliver unless notifications.empty? | |
35 | + Mailer::content_summary(@person, notifications, tasks).deliver unless notifications.empty? && tasks.empty? | |
31 | 36 | end |
32 | 37 | @person.settings[:last_notification] = DateTime.now |
33 | 38 | @person.save! |
... | ... | @@ -77,13 +82,17 @@ class PersonNotifier |
77 | 82 | {:theme => nil} |
78 | 83 | end |
79 | 84 | |
80 | - def content_summary(person, notifications) | |
81 | - ActionMailer::Base.asset_host = person.environment.top_url if person.environment | |
85 | + def content_summary(person, notifications, tasks) | |
86 | + if person.environment | |
87 | + ActionMailer::Base.asset_host = person.environment.top_url | |
88 | + ActionMailer::Base.default_url_options[:host] = person.environment.top_url.gsub(/^(https?:)?/, '') | |
89 | + end | |
82 | 90 | |
83 | 91 | @current_theme = 'default' |
84 | 92 | @profile = person |
85 | 93 | @recipient = @profile.nickname || @profile.name |
86 | 94 | @notifications = notifications |
95 | + @tasks = tasks | |
87 | 96 | @environment = @profile.environment.name |
88 | 97 | @url = @profile.environment.top_url |
89 | 98 | mail( | ... | ... |
app/views/person_notifier/mailer/_comment.html.erb
... | ... | @@ -19,7 +19,7 @@ |
19 | 19 | <span style="font-size: 12px;"><%= comment.title %></span><br/> |
20 | 20 | <% end %> |
21 | 21 | <span style="font-size: 10px;"><%= txt2html comment.body %></span><br/> |
22 | - <span style="font-size: 8px; color: #444444"><%= time_ago_as_sentence(comment.created_at) %></span> | |
22 | + <span style="font-size: 8px; color: #929292"><%= time_ago_as_sentence(comment.created_at) %></span> | |
23 | 23 | <br style="clear: both;" /> |
24 | 24 | |
25 | 25 | <% unless comment.replies.blank? %> | ... | ... |
app/views/person_notifier/mailer/_create_article.html.erb
... | ... | @@ -6,7 +6,7 @@ |
6 | 6 | <p> |
7 | 7 | <span style="font-size: 14px;"><%= link_to activity.user.short_name(20), activity.user.url %></span> |
8 | 8 | <span style="font-size: 14px;"><%= _("has published on community %s") % link_to(activity.target.profile.short_name(20), activity.target.profile.url, :style => "color: #333; font-weight: bold; text-decoration: none;") if activity.target.profile.is_a?(Community) %></span> |
9 | - <span style="font-size: 10px; color: #444444; float:right;"><%= time_ago_as_sentence(activity.created_at) %></span> | |
9 | + <span style="font-size: 10px; color: #929292; float:right;"><%= time_ago_as_sentence(activity.created_at) %></span> | |
10 | 10 | </p> |
11 | 11 | <p> |
12 | 12 | <span style="font-size: 14px;"><%= link_to(activity.params['name'], activity.params['url'], :style => "color: #333; font-weight: bold; text-decoration: none;") %></span> | ... | ... |
app/views/person_notifier/mailer/_default_activity.html.erb
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | <td> |
6 | 6 | <p> |
7 | 7 | <span style="font-size: 14px;"><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></span> |
8 | - <span style="font-size: 10px; color: #444444; float: right;"><%= time_ago_as_sentence(activity.created_at) %></span> | |
8 | + <span style="font-size: 10px; color: #929292; float: right;"><%= time_ago_as_sentence(activity.created_at) %></span> | |
9 | 9 | </p> |
10 | 10 | </td> |
11 | 11 | </tr> | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +<div style="border-bottom:1px solid #e2e2e2;padding:15px 0;width:600px"> | |
2 | + <table style="width:100%;"> | |
3 | + <tr> | |
4 | + <td style="width: 11%"> | |
5 | + <%= profile_image(task.requestor, :minor) %> | |
6 | + </td> | |
7 | + <td> | |
8 | + <div> | |
9 | + <strong><%= link_to task.title, url_for(:controller => 'tasks', :profile => @profile.identifier, :action => 'index', :only_path => false) %></strong> | |
10 | + </div> | |
11 | + <div style="font-size: 14px"> | |
12 | + <span style="font-size: 14px"> | |
13 | + <%= task_information(task) %> | |
14 | + </span> | |
15 | + <span style="font-size: 10px; color: #929292; float: right;"><%= time_ago_as_sentence(task.created_at) %></span> | |
16 | + </div> | |
17 | + </td> | |
18 | + </tr> | |
19 | + </table> | |
20 | +</div> | ... | ... |
app/views/person_notifier/mailer/_upload_image.html.erb
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | <td> |
6 | 6 | <p> |
7 | 7 | <span style="font-size: 14px;"><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></span> |
8 | - <span style="font-size: 10px; color: #444444; float:right;"><%= time_ago_as_sentence(activity.created_at) %></span> | |
8 | + <span style="font-size: 10px; color: #929292; float:right;"><%= time_ago_as_sentence(activity.created_at) %></span> | |
9 | 9 | </p> |
10 | 10 | </td> |
11 | 11 | </tr> | ... | ... |
app/views/person_notifier/mailer/content_summary.html.erb
... | ... | @@ -5,22 +5,38 @@ |
5 | 5 | <%= link_to @url, :style => "text-decoration: none;" do %> |
6 | 6 | <span style="font-weight:bold;font-size: 28px;margin: 0;color: white;background-color: #AAAAAA;padding: 5px;"><%= @environment %></span> |
7 | 7 | <% end %> |
8 | - <span style="font-weight:bold;color: #333;font-size:19px;margin-left: 8px;"><%= _("%s's network activity") % @profile.name %></h3> | |
8 | + <span style="font-weight:bold;color: #333;font-size:19px;margin-left: 8px;"><%= _("%s's Notifications") % @profile.name %></h3> | |
9 | 9 | </div> |
10 | - <div style="margin: 0 20px 20px 20px;border-top:2px solid #e2e2e2;"> | |
11 | - <% @notifications.each do |activity| %> | |
12 | - <div style="border-bottom:1px solid #e2e2e2;padding:15px 0;width:600px"> | |
13 | - <table style="width:100%;"> | |
14 | - <%= render :partial => activity.verb, :locals => { :activity => activity } rescue "cannot render notification for #{activity.verb}" %> | |
15 | - </table> | |
10 | + <div style="margin: 0 20px 20px 20px;border-top:1px solid #e2e2e2;"> | |
11 | + <% if @tasks.present? %> | |
12 | + <div style="border-top: 1px solid #e2e2e2;"> | |
13 | + <div style="border-bottom: 1px solid #CBCBCB;padding-top: 15px;font-weight: bold;text-align: right;color: #7c7c7c;float: right;min-width: 140px;"> | |
14 | + <%= _('Tasks') %> | |
15 | + </div> | |
16 | + <%= render :partial => 'task', :collection => @tasks %> | |
17 | + </div> | |
18 | + <% end %> | |
19 | + | |
20 | + <% if @notifications.present? %> | |
21 | + <div style="border-top: 1px solid #e2e2e2;"> | |
22 | + <div style="border-bottom: 1px solid #CBCBCB;padding-top: 15px;font-weight: bold;text-align: right;color: #7c7c7c;float: right;min-width: 140px;"> | |
23 | + <%= _('Network Activity') %> | |
24 | + </div> | |
25 | + <% @notifications.each do |activity| %> | |
26 | + <div style="border-bottom:1px solid #e2e2e2;padding:15px 0;width:600px"> | |
27 | + <table style="width:100%;"> | |
28 | + <%= render :partial => activity.verb, :locals => { :activity => activity } rescue "cannot render notification for #{activity.verb}" %> | |
29 | + </table> | |
30 | + </div> | |
31 | + <% end %> | |
32 | + </div> | |
33 | + <% end %> | |
34 | + | |
35 | + <div style="color:#444444;font-size:11px;margin-bottom: 20px;"> | |
36 | + <p style="margin:0"><%= _("Greetings,") %></p> | |
37 | + <p style="margin:0"><%= _('%s team.') % @environment %></p> | |
38 | + <p style="margin:0"><%= link_to @url, url_for(@url) %></p> | |
16 | 39 | </div> |
17 | - <% end %> | |
18 | - </div> | |
19 | - <div style="color:#444444;font-size:11px;margin-bottom: 20px;"> | |
20 | - <p style="margin:0"><%= _("Greetings,") %></p> | |
21 | - <p style="margin:0"><%= _('%s team.') % @environment %></p> | |
22 | - <p style="margin:0"><%= link_to @url, url_for(@url) %></p> | |
23 | 40 | </div> |
24 | - </div> | |
25 | 41 | </td></tr></tbody></table> |
26 | 42 | </div> | ... | ... |
test/unit/person_notifier_test.rb
... | ... | @@ -246,6 +246,14 @@ class PersonNotifierTest < ActiveSupport::TestCase |
246 | 246 | assert_match /src="http:\/\/colivre.net\/images\/icons-app\/community-icon.png.*"/, sent.body.to_s |
247 | 247 | end |
248 | 248 | |
249 | + should 'list tasks in notification mail' do | |
250 | + task = @member.tasks.create! | |
251 | + process_delayed_job_queue | |
252 | + notify | |
253 | + sent = ActionMailer::Base.deliveries.last | |
254 | + assert_match /href=".*\/myprofile\/member\/tasks"/, sent.body.to_s | |
255 | + end | |
256 | + | |
249 | 257 | private |
250 | 258 | |
251 | 259 | def notify | ... | ... |