##// END OF EJS Templates
Notify previous assignee when assignee changes (#2694)....
Jean-Philippe Lang -
r8575:22317105f99e
parent child
Show More
@@ -514,19 +514,27 class Issue < ActiveRecord::Base
514 blocked? ? statuses.reject {|s| s.is_closed?} : statuses
514 blocked? ? statuses.reject {|s| s.is_closed?} : statuses
515 end
515 end
516
516
517 def assigned_to_was
518 if assigned_to_id_changed? && assigned_to_id_was.present?
519 @assigned_to_was ||= User.find_by_id(assigned_to_id_was)
520 end
521 end
522
517 # Returns the mail adresses of users that should be notified
523 # Returns the mail adresses of users that should be notified
518 def recipients
524 def recipients
519 notified = project.notified_users
525 notified = []
520 # Author and assignee are always notified unless they have been
526 # Author and assignee are always notified unless they have been
521 # locked or don't want to be notified
527 # locked or don't want to be notified
522 notified << author if author && author.active? && author.notify_about?(self)
528 notified << author if author
523 if assigned_to
529 if assigned_to
524 if assigned_to.is_a?(Group)
530 notified += (assigned_to.is_a?(Group) ? assigned_to.users : [assigned_to])
525 notified += assigned_to.users.select {|u| u.active? && u.notify_about?(self)}
531 end
526 else
532 if assigned_to_was
527 notified << assigned_to if assigned_to.active? && assigned_to.notify_about?(self)
533 notified += (assigned_to_was.is_a?(Group) ? assigned_to_was.users : [assigned_to_was])
528 end
529 end
534 end
535 notified = notified.select {|u| u.active? && u.notify_about?(self)}
536
537 notified += project.notified_users
530 notified.uniq!
538 notified.uniq!
531 # Remove users that can not view the issue
539 # Remove users that can not view the issue
532 notified.reject! {|user| !visible?(user)}
540 notified.reject! {|user| !visible?(user)}
@@ -509,7 +509,7 class User < Principal
509 true
509 true
510 when 'selected'
510 when 'selected'
511 # user receives notifications for created/assigned issues on unselected projects
511 # user receives notifications for created/assigned issues on unselected projects
512 if object.is_a?(Issue) && (object.author == self || is_or_belongs_to?(object.assigned_to))
512 if object.is_a?(Issue) && (object.author == self || is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.assigned_to_was))
513 true
513 true
514 else
514 else
515 false
515 false
@@ -517,13 +517,13 class User < Principal
517 when 'none'
517 when 'none'
518 false
518 false
519 when 'only_my_events'
519 when 'only_my_events'
520 if object.is_a?(Issue) && (object.author == self || is_or_belongs_to?(object.assigned_to))
520 if object.is_a?(Issue) && (object.author == self || is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.assigned_to_was))
521 true
521 true
522 else
522 else
523 false
523 false
524 end
524 end
525 when 'only_assigned'
525 when 'only_assigned'
526 if object.is_a?(Issue) && is_or_belongs_to?(object.assigned_to)
526 if object.is_a?(Issue) && (is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.assigned_to_was))
527 true
527 true
528 else
528 else
529 false
529 false
@@ -678,6 +678,18 class IssueTest < ActiveSupport::TestCase
678 end
678 end
679 end
679 end
680
680
681 def test_recipients_should_include_previous_assignee
682 user = User.find(3)
683 user.members.update_all ["mail_notification = ?", false]
684 user.update_attribute :mail_notification, 'only_assigned'
685
686 issue = Issue.find(2)
687 issue.assigned_to = nil
688 assert_include user.mail, issue.recipients
689 issue.save!
690 assert !issue.recipients.include?(user.mail)
691 end
692
681 def test_recipients_should_not_include_users_that_cannot_view_the_issue
693 def test_recipients_should_not_include_users_that_cannot_view_the_issue
682 issue = Issue.find(12)
694 issue = Issue.find(12)
683 assert issue.recipients.include?(issue.author.mail)
695 assert issue.recipients.include?(issue.author.mail)
General Comments 0
You need to be logged in to leave comments. Login now