##// 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 514 blocked? ? statuses.reject {|s| s.is_closed?} : statuses
515 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 523 # Returns the mail adresses of users that should be notified
518 524 def recipients
519 notified = project.notified_users
525 notified = []
520 526 # Author and assignee are always notified unless they have been
521 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 529 if assigned_to
524 if assigned_to.is_a?(Group)
525 notified += assigned_to.users.select {|u| u.active? && u.notify_about?(self)}
526 else
527 notified << assigned_to if assigned_to.active? && assigned_to.notify_about?(self)
528 end
530 notified += (assigned_to.is_a?(Group) ? assigned_to.users : [assigned_to])
531 end
532 if assigned_to_was
533 notified += (assigned_to_was.is_a?(Group) ? assigned_to_was.users : [assigned_to_was])
529 534 end
535 notified = notified.select {|u| u.active? && u.notify_about?(self)}
536
537 notified += project.notified_users
530 538 notified.uniq!
531 539 # Remove users that can not view the issue
532 540 notified.reject! {|user| !visible?(user)}
@@ -509,7 +509,7 class User < Principal
509 509 true
510 510 when 'selected'
511 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 513 true
514 514 else
515 515 false
@@ -517,13 +517,13 class User < Principal
517 517 when 'none'
518 518 false
519 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 521 true
522 522 else
523 523 false
524 524 end
525 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 527 true
528 528 else
529 529 false
@@ -678,6 +678,18 class IssueTest < ActiveSupport::TestCase
678 678 end
679 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 693 def test_recipients_should_not_include_users_that_cannot_view_the_issue
682 694 issue = Issue.find(12)
683 695 assert issue.recipients.include?(issue.author.mail)
General Comments 0
You need to be logged in to leave comments. Login now