]> source.dussan.org Git - redmine.git/commitdiff
Notify previous assignee when assignee changes (#2694).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 23 Jan 2012 17:55:29 +0000 (17:55 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 23 Jan 2012 17:55:29 +0000 (17:55 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8695 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
app/models/user.rb
test/unit/issue_test.rb

index ad91ab4887fefb516a69c12501ba9547325516bc..2b9b12b778fa3b5c6b40cf03d012122860c64d12 100644 (file)
@@ -514,19 +514,27 @@ class Issue < ActiveRecord::Base
     blocked? ? statuses.reject {|s| s.is_closed?} : statuses
   end
 
+  def assigned_to_was
+    if assigned_to_id_changed? && assigned_to_id_was.present?
+      @assigned_to_was ||= User.find_by_id(assigned_to_id_was)
+    end
+  end
+
   # Returns the mail adresses of users that should be notified
   def recipients
-    notified = project.notified_users
+    notified = []
     # Author and assignee are always notified unless they have been
     # locked or don't want to be notified
-    notified << author if author && author.active? && author.notify_about?(self)
+    notified << author if author
     if assigned_to
-      if assigned_to.is_a?(Group)
-        notified += assigned_to.users.select {|u| u.active? && u.notify_about?(self)}
-      else
-        notified << assigned_to if assigned_to.active? && assigned_to.notify_about?(self)
-      end
+      notified += (assigned_to.is_a?(Group) ? assigned_to.users : [assigned_to])
+    end
+    if assigned_to_was
+      notified += (assigned_to_was.is_a?(Group) ? assigned_to_was.users : [assigned_to_was])
     end
+    notified = notified.select {|u| u.active? && u.notify_about?(self)}
+
+    notified += project.notified_users
     notified.uniq!
     # Remove users that can not view the issue
     notified.reject! {|user| !visible?(user)}
index 92e3414117069c0bb7c5449ce52ebadb04971331..9be6143dc304b7337913811ca69866af274e66d8 100644 (file)
@@ -509,7 +509,7 @@ class User < Principal
       true
     when 'selected'
       # user receives notifications for created/assigned issues on unselected projects
-      if object.is_a?(Issue) && (object.author == self || is_or_belongs_to?(object.assigned_to))
+      if object.is_a?(Issue) && (object.author == self || is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.assigned_to_was))
         true
       else
         false
@@ -517,13 +517,13 @@ class User < Principal
     when 'none'
       false
     when 'only_my_events'
-      if object.is_a?(Issue) && (object.author == self || is_or_belongs_to?(object.assigned_to))
+      if object.is_a?(Issue) && (object.author == self || is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.assigned_to_was))
         true
       else
         false
       end
     when 'only_assigned'
-      if object.is_a?(Issue) && is_or_belongs_to?(object.assigned_to)
+      if object.is_a?(Issue) && (is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.assigned_to_was))
         true
       else
         false
index 59dabba486559028b358990414f5ff9d158f07c6..ee56ffe74384e5ba3597c978b7fb01cf478136ff 100644 (file)
@@ -678,6 +678,18 @@ class IssueTest < ActiveSupport::TestCase
     end
   end
 
+  def test_recipients_should_include_previous_assignee
+    user = User.find(3)
+    user.members.update_all ["mail_notification = ?", false]
+    user.update_attribute :mail_notification, 'only_assigned'
+
+    issue = Issue.find(2)
+    issue.assigned_to = nil
+    assert_include user.mail, issue.recipients
+    issue.save!
+    assert !issue.recipients.include?(user.mail)
+  end
+
   def test_recipients_should_not_include_users_that_cannot_view_the_issue
     issue = Issue.find(12)
     assert issue.recipients.include?(issue.author.mail)