From 36c35080b2104afad5dad29506e81d40dc08b1de Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 21 Dec 2013 11:26:01 +0000 Subject: [PATCH] Merged r12419. git-svn-id: http://svn.redmine.org/redmine/branches/2.4-stable@12434 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 23 ++++++++++++++++++++--- test/unit/issue_test.rb | 13 +++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 07d09d694..0101abf00 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -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 # diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 8f9f965cb..8b0252e0b 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -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) -- 2.39.5