diff --git a/app/models/person_notifier.rb b/app/models/person_notifier.rb index e6ec250..9cb0d53 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,7 +82,7 @@ class PersonNotifier {:theme => nil} end - def content_summary(person, notifications) + 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.default_hostname @@ -87,13 +92,14 @@ class PersonNotifier @profile = person @recipient = @profile.nickname || @profile.name @notifications = notifications + @tasks = tasks @environment = @profile.environment.name @url = @profile.environment.top_url mail( content_type: "text/html", from: "#{@profile.environment.name} <#{@profile.environment.noreply_email}>", to: @profile.email, - subject: _("[%s] Network Activity") % [@profile.environment.name] + subject: _("[%s] Notifications") % [@profile.environment.name] ) end end 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 d0f8743..59c93b4 100644 --- a/test/unit/person_notifier_test.rb +++ b/test/unit/person_notifier_test.rb @@ -246,6 +246,14 @@ class PersonNotifierTest < ActiveSupport::TestCase assert jobs.select {|j| !j.failed? && j.last_error.nil? }.empty? 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