]> source.dussan.org Git - redmine.git/commitdiff
Merged r12419.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 21 Dec 2013 11:26:01 +0000 (11:26 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 21 Dec 2013 11:26:01 +0000 (11:26 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/2.4-stable@12434 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 07d09d69407bf0001d6c4bd09addc865e803495f..0101abf00287c99853f7115c43a3e303ee9069f8 100644 (file)
@@ -93,7 +93,7 @@ class Issue < ActiveRecord::Base
 
   before_create :default_assign
   before_save :close_duplicates, :update_done_ratio_from_issue_status,
-              :force_updated_on_change, :update_closed_on
+              :force_updated_on_change, :update_closed_on, :set_assigned_to_was
   after_save {|issue| issue.send :after_project_change if !issue.id_changed? && issue.project_id_changed?} 
   after_save :reschedule_following_issues, :update_nested_set_attributes,
              :update_parent_attributes, :create_journal
@@ -101,6 +101,8 @@ class Issue < ActiveRecord::Base
   after_save :after_create_from_copy
   after_destroy :update_parent_attributes
   after_create :send_notification
+  # Keep it at the end of after_save callbacks
+  after_save :clear_assigned_to_was
 
   # Returns a SQL conditions string used to find all issues visible by the specified user
   def self.visible_condition(user, options={})
@@ -776,9 +778,12 @@ class Issue < ActiveRecord::Base
     end
   end
 
+  # Returns the previous assignee if changed
   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)
+    # assigned_to_id_was is reset before after_save callbacks
+    user_id = @previous_assigned_to_id || assigned_to_id_was
+    if user_id && user_id != assigned_to_id
+      @assigned_to_was ||= User.find_by_id(user_id)
     end
   end
 
@@ -1515,6 +1520,18 @@ class Issue < ActiveRecord::Base
     end
   end
 
+  # Stores the previous assignee so we can still have access
+  # to it during after_save callbacks (assigned_to_id_was is reset)
+  def set_assigned_to_was
+    @previous_assigned_to_id = assigned_to_id_was
+  end
+
+  # Clears the previous assignee at the end of after_save callbacks
+  def clear_assigned_to_was
+    @assigned_to_was = nil
+    @previous_assigned_to_id = nil
+  end
+
   # Query generator for selecting groups of issue counts for a project
   # based on specific criteria
   #
index 8f9f965cbeb3096b6a9e0f8b791e62fcc922de3f..8b0252e0b0b1d69e9843ea361de2c2095574a169 100644 (file)
@@ -1700,6 +1700,19 @@ class IssueTest < ActiveSupport::TestCase
     assert_equal 1, ActionMailer::Base.deliveries.size
   end
 
+  def test_update_should_notify_previous_assignee
+    ActionMailer::Base.deliveries.clear
+    user = User.find(3)
+    user.members.update_all ["mail_notification = ?", false]
+    user.update_attribute :mail_notification, 'only_assigned'
+
+    issue = Issue.find(2)
+    issue.init_journal User.find(1)
+    issue.assigned_to = nil
+    issue.save!
+    assert_include user.mail, ActionMailer::Base.deliveries.last.bcc
+  end
+
   def test_stale_issue_should_not_send_email_notification
     ActionMailer::Base.deliveries.clear
     issue = Issue.find(1)