From 0087d237f76458f0db7ec552de2972e1d70c3838 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 13 Jul 2013 10:32:48 +0000 Subject: Don't notify users about relations that are not visible (#1005). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12015 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/journal.rb | 13 +++++++++++++ app/models/mailer.rb | 7 ++++--- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/models/journal.rb b/app/models/journal.rb index 70ecc54f5..47ae12380 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -68,6 +68,19 @@ class Journal < ActiveRecord::Base end end + def each_notification(users, &block) + if users.any? + users_by_details_visibility = users.group_by do |user| + visible_details(user) + end + users_by_details_visibility.each do |visible_details, users| + if notes? || visible_details.any? + yield(users) + end + end + end + end + # Returns the new status if the journal contains a status change, otherwise nil def new_status c = details.detect {|detail| detail.prop_key == 'status_id'} diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 6a8aded13..c6822362e 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -81,9 +81,10 @@ class Mailer < ActionMailer::Base issue = journal.journalized.reload to = journal.notified_users cc = journal.notified_watchers - issue.each_notification(to + cc) do |users| - next unless journal.notes? || journal.visible_details(users.first).any? - Mailer.issue_edit(journal, to & users, cc & users).deliver + journal.each_notification(to + cc) do |users| + issue.each_notification(users) do |users2| + Mailer.issue_edit(journal, to & users2, cc & users2).deliver + end end end -- cgit v1.2.3