Commit a3d969ae41e028b972a7099c1bb0aa13e4b920b5

Authored by Victor Costa
1 parent de40b2b7

Display pending tasks in notification email

app/models/person_notifier.rb
@@ -22,12 +22,17 @@ class PersonNotifier @@ -22,12 +22,17 @@ class PersonNotifier
22 schedule_next_notification_mail 22 schedule_next_notification_mail
23 end 23 end
24 24
  25 + def notify_from
  26 + @person.last_notification || DateTime.now - @person.notification_time.hours
  27 + end
  28 +
25 def notify 29 def notify
26 if @person.notification_time && @person.notification_time > 0 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 Noosfero.with_locale @person.environment.default_language do 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 end 36 end
32 @person.settings[:last_notification] = DateTime.now 37 @person.settings[:last_notification] = DateTime.now
33 @person.save! 38 @person.save!
@@ -77,13 +82,17 @@ class PersonNotifier @@ -77,13 +82,17 @@ class PersonNotifier
77 {:theme => nil} 82 {:theme => nil}
78 end 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 @current_theme = 'default' 91 @current_theme = 'default'
84 @profile = person 92 @profile = person
85 @recipient = @profile.nickname || @profile.name 93 @recipient = @profile.nickname || @profile.name
86 @notifications = notifications 94 @notifications = notifications
  95 + @tasks = tasks
87 @environment = @profile.environment.name 96 @environment = @profile.environment.name
88 @url = @profile.environment.top_url 97 @url = @profile.environment.top_url
89 mail( 98 mail(
app/views/person_notifier/mailer/_task.html.erb 0 → 100644
@@ -0,0 +1,20 @@ @@ -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: #444444; 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/content_summary.html.erb
@@ -5,22 +5,31 @@ @@ -5,22 +5,31 @@
5 <%= link_to @url, :style => "text-decoration: none;" do %> 5 <%= link_to @url, :style => "text-decoration: none;" do %>
6 <span style="font-weight:bold;font-size: 28px;margin: 0;color: white;background-color: #AAAAAA;padding: 5px;"><%= @environment %></span> 6 <span style="font-weight:bold;font-size: 28px;margin: 0;color: white;background-color: #AAAAAA;padding: 5px;"><%= @environment %></span>
7 <% end %> 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 </div> 9 </div>
10 <div style="margin: 0 20px 20px 20px;border-top:2px solid #e2e2e2;"> 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> 11 + <% if @tasks.present? %>
  12 + <div style="border-bottom: 1px solid #CBCBCB;padding-top: 15px;font-weight: bold;text-align: right;color: #7c7c7c;float: right;min-width: 140px;"><%= _('Tasks') %></div>
  13 + <%= render :partial => 'task', :collection => @tasks %>
  14 + <% end %>
  15 +
  16 + <% if @notifications.present? %>
  17 + <div style="border-bottom: 1px solid #CBCBCB;padding-top: 15px;font-weight: bold;text-align: right;color: #7c7c7c;float: right;min-width: 140px;"><%= _('Network Activity') %></div>
  18 + <% @notifications.each do |activity| %>
  19 + <div style="border-bottom:1px solid #e2e2e2;padding:15px 0;width:600px">
  20 + <table style="width:100%;">
  21 + <%= render :partial => activity.verb, :locals => { :activity => activity } rescue "cannot render notification for #{activity.verb}" %>
  22 + </table>
  23 + </div>
  24 + <% end %>
  25 + </div>
  26 + <% end %>
  27 +
  28 + <div style="color:#444444;font-size:11px;margin-bottom: 20px;">
  29 + <p style="margin:0"><%= _("Greetings,") %></p>
  30 + <p style="margin:0"><%= _('%s team.') % @environment %></p>
  31 + <p style="margin:0"><%= link_to @url, url_for(@url) %></p>
16 </div> 32 </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 </div> 33 </div>
24 - </div>  
25 </td></tr></tbody></table> 34 </td></tr></tbody></table>
26 </div> 35 </div>
test/unit/person_notifier_test.rb
@@ -246,6 +246,14 @@ class PersonNotifierTest &lt; ActiveSupport::TestCase @@ -246,6 +246,14 @@ class PersonNotifierTest &lt; ActiveSupport::TestCase
246 assert_match /src="http:\/\/colivre.net\/images\/icons-app\/community-icon.png.*"/, sent.body.to_s 246 assert_match /src="http:\/\/colivre.net\/images\/icons-app\/community-icon.png.*"/, sent.body.to_s
247 end 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 private 257 private
250 258
251 def notify 259 def notify