##// END OF EJS Templates
Don't notify users about relations that are not visible (#1005)....
Jean-Philippe Lang -
r11785:0087d237f764
parent child
Show More
@@ -68,6 +68,19 class Journal < ActiveRecord::Base
68 end
68 end
69 end
69 end
70
70
71 def each_notification(users, &block)
72 if users.any?
73 users_by_details_visibility = users.group_by do |user|
74 visible_details(user)
75 end
76 users_by_details_visibility.each do |visible_details, users|
77 if notes? || visible_details.any?
78 yield(users)
79 end
80 end
81 end
82 end
83
71 # Returns the new status if the journal contains a status change, otherwise nil
84 # Returns the new status if the journal contains a status change, otherwise nil
72 def new_status
85 def new_status
73 c = details.detect {|detail| detail.prop_key == 'status_id'}
86 c = details.detect {|detail| detail.prop_key == 'status_id'}
@@ -81,9 +81,10 class Mailer < ActionMailer::Base
81 issue = journal.journalized.reload
81 issue = journal.journalized.reload
82 to = journal.notified_users
82 to = journal.notified_users
83 cc = journal.notified_watchers
83 cc = journal.notified_watchers
84 issue.each_notification(to + cc) do |users|
84 journal.each_notification(to + cc) do |users|
85 next unless journal.notes? || journal.visible_details(users.first).any?
85 issue.each_notification(users) do |users2|
86 Mailer.issue_edit(journal, to & users, cc & users).deliver
86 Mailer.issue_edit(journal, to & users2, cc & users2).deliver
87 end
87 end
88 end
88 end
89 end
89
90
@@ -374,6 +374,22 class MailerTest < ActiveSupport::TestCase
374 assert_mail_body_match '(Private notes)', last_email
374 assert_mail_body_match '(Private notes)', last_email
375 end
375 end
376
376
377 def test_issue_edit_with_relation_should_notify_users_who_can_see_the_related_issue
378 issue = Issue.generate!
379 private_issue = Issue.generate!(:is_private => true)
380 IssueRelation.create!(:issue_from => issue, :issue_to => private_issue, :relation_type => 'relates')
381 issue.reload
382 assert_equal 1, issue.journals.size
383 journal = issue.journals.first
384 ActionMailer::Base.deliveries.clear
385
386 Mailer.deliver_issue_edit(journal)
387 last_email.bcc.each do |email|
388 user = User.find_by_mail(email)
389 assert private_issue.visible?(user), "Issue was not visible to #{user}"
390 end
391 end
392
377 def test_document_added
393 def test_document_added
378 document = Document.find(1)
394 document = Document.find(1)
379 valid_languages.each do |lang|
395 valid_languages.each do |lang|
General Comments 0
You need to be logged in to leave comments. Login now