Commit 5012a8e49bdb5348efc32d8972af636a0211811d

Authored by Victor Costa
1 parent 8b11b55d

Display pending tasks in notification email

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,7 +82,7 @@ class PersonNotifier
77 82 {:theme => nil}
78 83 end
79 84  
80   - def content_summary(person, notifications)
  85 + def content_summary(person, notifications, tasks)
81 86 if person.environment
82 87 ActionMailer::Base.asset_host = person.environment.top_url
83 88 ActionMailer::Base.default_url_options[:host] = person.environment.default_hostname
... ... @@ -87,13 +92,14 @@ class PersonNotifier
87 92 @profile = person
88 93 @recipient = @profile.nickname || @profile.name
89 94 @notifications = notifications
  95 + @tasks = tasks
90 96 @environment = @profile.environment.name
91 97 @url = @profile.environment.top_url
92 98 mail(
93 99 content_type: "text/html",
94 100 from: "#{@profile.environment.name} <#{@profile.environment.noreply_email}>",
95 101 to: @profile.email,
96   - subject: _("[%s] Network Activity") % [@profile.environment.name]
  102 + subject: _("[%s] Notifications") % [@profile.environment.name]
97 103 )
98 104 end
99 105 end
... ...
app/views/person_notifier/mailer/_task.html.erb 0 → 100644
... ... @@ -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 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 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 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 33 </div>
24   - </div>
25 34 </td></tr></tbody></table>
26 35 </div>
... ...
test/unit/person_notifier_test.rb
... ... @@ -246,6 +246,14 @@ class PersonNotifierTest &lt; ActiveSupport::TestCase
246 246 assert jobs.select {|j| !j.failed? && j.last_error.nil? }.empty?
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
... ...