]> source.dussan.org Git - redmine.git/commitdiff
Don't notify users about relations that are not visible (#1005).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 13 Jul 2013 10:32:48 +0000 (10:32 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 13 Jul 2013 10:32:48 +0000 (10:32 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12015 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/journal.rb
app/models/mailer.rb
test/unit/mailer_test.rb

index 70ecc54f518f1ebfceb9e361f6d205b3b6b91284..47ae123805823f429c7901e01d8ac1043a9ee6e1 100644 (file)
@@ -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'}
index 6a8aded13d9df624a864d90fa3a1a2036195d784..c6822362e06f4171730f4025e3a9b8eb57613ad7 100644 (file)
@@ -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
 
index 93f4567d3614aa573d67d7c4f103ff6308db717c..3cacf4f8716c169441b81cf1b4db89f07e33e28f 100644 (file)
@@ -374,6 +374,22 @@ class MailerTest < ActiveSupport::TestCase
     assert_mail_body_match '(Private notes)', last_email
   end
 
+  def test_issue_edit_with_relation_should_notify_users_who_can_see_the_related_issue
+    issue = Issue.generate!
+    private_issue = Issue.generate!(:is_private => true)
+    IssueRelation.create!(:issue_from => issue, :issue_to => private_issue, :relation_type => 'relates')
+    issue.reload
+    assert_equal 1, issue.journals.size
+    journal = issue.journals.first
+    ActionMailer::Base.deliveries.clear
+
+    Mailer.deliver_issue_edit(journal)
+    last_email.bcc.each do |email|
+      user = User.find_by_mail(email)
+      assert private_issue.visible?(user), "Issue was not visible to #{user}"
+    end
+  end
+
   def test_document_added
     document = Document.find(1)
     valid_languages.each do |lang|