##// END OF EJS Templates
Do not notify users that are no longer allowed to view an issue (#3589, #4263)....
Jean-Philippe Lang -
r3007:c870a7b9ef35
parent child
Show More
@@ -250,13 +250,23 class Issue < ActiveRecord::Base
250 blocked? ? statuses.reject {|s| s.is_closed?} : statuses
250 blocked? ? statuses.reject {|s| s.is_closed?} : statuses
251 end
251 end
252
252
253 # Returns the mail adresses of users that should be notified for the issue
253 # Returns the mail adresses of users that should be notified
254 def recipients
254 def recipients
255 recipients = project.recipients
255 notified = project.notified_users
256 # Author and assignee are always notified unless they have been locked
256 # Author and assignee are always notified unless they have been locked
257 recipients << author.mail if author && author.active?
257 notified << author if author && author.active?
258 recipients << assigned_to.mail if assigned_to && assigned_to.active?
258 notified << assigned_to if assigned_to && assigned_to.active?
259 recipients.compact.uniq
259 notified.uniq!
260 # Remove users that can not view the issue
261 notified.reject! {|user| !visible?(user)}
262 notified.collect(&:mail)
263 end
264
265 # Returns the mail adresses of watchers that should be notified
266 def watcher_recipients
267 notified = watcher_users
268 notified.reject! {|user| !user.active? || !visible?(user)}
269 notified.collect(&:mail)
260 end
270 end
261
271
262 # Returns the total number of hours spent on this issue.
272 # Returns the total number of hours spent on this issue.
@@ -352,6 +352,11 class Project < ActiveRecord::Base
352 members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail}
352 members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail}
353 end
353 end
354
354
355 # Returns the users that should be notified on project events
356 def notified_users
357 members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user}
358 end
359
355 # Returns an array of all custom fields enabled for project issues
360 # Returns an array of all custom fields enabled for project issues
356 # (explictly associated custom fields and custom fields enabled for all projects)
361 # (explictly associated custom fields and custom fields enabled for all projects)
357 def all_issue_custom_fields
362 def all_issue_custom_fields
@@ -185,7 +185,7 issues_012:
185 description:
185 description:
186 tracker_id: 1
186 tracker_id: 1
187 assigned_to_id:
187 assigned_to_id:
188 author_id: 2
188 author_id: 3
189 status_id: 5
189 status_id: 5
190 start_date: <%= 1.day.ago.to_date.to_s(:db) %>
190 start_date: <%= 1.day.ago.to_date.to_s(:db) %>
191 due_date:
191 due_date:
@@ -353,6 +353,23 class IssueTest < ActiveSupport::TestCase
353 assert_nil copy.custom_value_for(2)
353 assert_nil copy.custom_value_for(2)
354 end
354 end
355
355
356 def test_recipients_should_not_include_users_that_cannot_view_the_issue
357 issue = Issue.find(12)
358 assert issue.recipients.include?(issue.author.mail)
359 # move the issue to a private project
360 copy = issue.move_to(Project.find(5), Tracker.find(2), :copy => true)
361 # author is not a member of project anymore
362 assert !copy.recipients.include?(copy.author.mail)
363 end
364
365 def test_watcher_recipients_should_not_include_users_that_cannot_view_the_issue
366 user = User.find(3)
367 issue = Issue.find(9)
368 Watcher.create!(:user => user, :watchable => issue)
369 assert issue.watched_by?(user)
370 assert !issue.watcher_recipients.include?(user.mail)
371 end
372
356 def test_issue_destroy
373 def test_issue_destroy
357 Issue.find(1).destroy
374 Issue.find(1).destroy
358 assert_nil Issue.find_by_id(1)
375 assert_nil Issue.find_by_id(1)
General Comments 0
You need to be logged in to leave comments. Login now