From a3d969ae41e028b972a7099c1bb0aa13e4b920b5 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 12 Jan 2015 12:29:01 -0300 Subject: [PATCH] Display pending tasks in notification email --- app/models/person_notifier.rb | 19 ++++++++++++++----- app/views/person_notifier/mailer/_task.html.erb | 20 ++++++++++++++++++++ app/views/person_notifier/mailer/content_summary.html.erb | 35 ++++++++++++++++++++++------------- test/unit/person_notifier_test.rb | 8 ++++++++ 4 files changed, 64 insertions(+), 18 deletions(-) create mode 100644 app/views/person_notifier/mailer/_task.html.erb diff --git a/app/models/person_notifier.rb b/app/models/person_notifier.rb index 63a9476..62761a4 100644 --- a/app/models/person_notifier.rb +++ b/app/models/person_notifier.rb @@ -22,12 +22,17 @@ class PersonNotifier schedule_next_notification_mail end + def notify_from + @person.last_notification || DateTime.now - @person.notification_time.hours + end + def notify if @person.notification_time && @person.notification_time > 0 - from = @person.last_notification || DateTime.now - @person.notification_time.hours - notifications = @person.tracked_notifications.find(:all, :conditions => ["created_at > ?", from]) + notifications = @person.tracked_notifications.find(:all, :conditions => ["created_at > ?", notify_from]) + tasks = Task.to(@person).without_spam.pending.where("created_at > ?", notify_from).order_by('created_at', 'asc') + Noosfero.with_locale @person.environment.default_language do - Mailer::content_summary(@person, notifications).deliver unless notifications.empty? + Mailer::content_summary(@person, notifications, tasks).deliver unless notifications.empty? && tasks.empty? end @person.settings[:last_notification] = DateTime.now @person.save! @@ -77,13 +82,17 @@ class PersonNotifier {:theme => nil} end - def content_summary(person, notifications) - ActionMailer::Base.asset_host = person.environment.top_url if person.environment + def content_summary(person, notifications, tasks) + if person.environment + ActionMailer::Base.asset_host = person.environment.top_url + ActionMailer::Base.default_url_options[:host] = person.environment.top_url.gsub(/^(https?:)?/, '') + end @current_theme = 'default' @profile = person @recipient = @profile.nickname || @profile.name @notifications = notifications + @tasks = tasks @environment = @profile.environment.name @url = @profile.environment.top_url mail( diff --git a/app/views/person_notifier/mailer/_task.html.erb b/app/views/person_notifier/mailer/_task.html.erb new file mode 100644 index 0000000..b00d8e9 --- /dev/null +++ b/app/views/person_notifier/mailer/_task.html.erb @@ -0,0 +1,20 @@ +
+ + + + + +
+ <%= profile_image(task.requestor, :minor) %> + +
+ <%= link_to task.title, url_for(:controller => 'tasks', :profile => @profile.identifier, :action => 'index', :only_path => false) %> +
+
+ + <%= task_information(task) %> + + <%= time_ago_as_sentence(task.created_at) %> +
+
+
diff --git a/app/views/person_notifier/mailer/content_summary.html.erb b/app/views/person_notifier/mailer/content_summary.html.erb index 6e587dc..44130f6 100644 --- a/app/views/person_notifier/mailer/content_summary.html.erb +++ b/app/views/person_notifier/mailer/content_summary.html.erb @@ -5,22 +5,31 @@ <%= link_to @url, :style => "text-decoration: none;" do %> <%= @environment %> <% end %> - <%= _("%s's network activity") % @profile.name %> + <%= _("%s's Notifications") % @profile.name %>
- <% @notifications.each do |activity| %> -
- - <%= render :partial => activity.verb, :locals => { :activity => activity } rescue "cannot render notification for #{activity.verb}" %> -
+ <% if @tasks.present? %> +
<%= _('Tasks') %>
+ <%= render :partial => 'task', :collection => @tasks %> + <% end %> + + <% if @notifications.present? %> +
<%= _('Network Activity') %>
+ <% @notifications.each do |activity| %> +
+ + <%= render :partial => activity.verb, :locals => { :activity => activity } rescue "cannot render notification for #{activity.verb}" %> +
+
+ <% end %> +
+ <% end %> + +
+

<%= _("Greetings,") %>

+

<%= _('%s team.') % @environment %>

+

<%= link_to @url, url_for(@url) %>

- <% end %> -
-
-

<%= _("Greetings,") %>

-

<%= _('%s team.') % @environment %>

-

<%= link_to @url, url_for(@url) %>

- diff --git a/test/unit/person_notifier_test.rb b/test/unit/person_notifier_test.rb index ba593be..dac964e 100644 --- a/test/unit/person_notifier_test.rb +++ b/test/unit/person_notifier_test.rb @@ -246,6 +246,14 @@ class PersonNotifierTest < ActiveSupport::TestCase assert_match /src="http:\/\/colivre.net\/images\/icons-app\/community-icon.png.*"/, sent.body.to_s end + should 'list tasks in notification mail' do + task = @member.tasks.create! + process_delayed_job_queue + notify + sent = ActionMailer::Base.deliveries.last + assert_match /href=".*\/myprofile\/member\/tasks"/, sent.body.to_s + end + private def notify -- libgit2 0.21.2