Project

General

Profile

« Previous | Next » 

Revision 16856

Fixed notification of previous assignee (#26499).

View differences:

sandbox/rails-5.1/app/models/issue.rb
1010 1010
    statuses
1011 1011
  end
1012 1012

  
1013
  # Returns the previous assignee (user or group) if changed
1014
  def assigned_to_was
1015
    if assigned_to_id_was
1016
      Principal.find_by_id(assigned_to_id_was)
1017
    end
1013
  # Returns the original tracker
1014
  def tracker_was
1015
    Tracker.find_by_id(tracker_id_in_database)
1018 1016
  end
1019 1017

  
1020
  # Returns the assignee before last change
1021
  def assigned_to_before_last_save
1022
    if assigned_to_id_before_last_save
1023
      Principal.find_by_id(assigned_to_id_before_last_save)
1018
  # Returns the previous assignee whenever we're before the save
1019
  # or in after_* callbacks
1020
  def previous_assignee
1021
    # This is how ActiveRecord::AttributeMethods::Dirty checks if we're in a after_* callback
1022
    if previous_assigned_to_id = mutation_tracker.equal?(mutations_from_database) ? assigned_to_id_in_database : assigned_to_id_before_last_save
1023
      Principal.find_by_id(previous_assigned_to_id)
1024 1024
    end
1025 1025
  end
1026 1026

  
1027
  # Returns the original tracker
1028
  def tracker_was
1029
    Tracker.find_by_id(tracker_id_was)
1030
  end
1031

  
1032 1027
  # Returns the users that should be notified
1033 1028
  def notified_users
1034 1029
    notified = []
......
1038 1033
    if assigned_to
1039 1034
      notified += (assigned_to.is_a?(Group) ? assigned_to.users : [assigned_to])
1040 1035
    end
1041
    if previous = assigned_to_before_last_save
1036
    if previous = previous_assignee
1042 1037
      notified += (previous.is_a?(Group) ? previous.users : [previous])
1043 1038
    end
1044 1039
    notified = notified.select {|u| u.active? && u.notify_about?(self)}
sandbox/rails-5.1/app/models/user.rb
768 768
        case mail_notification
769 769
        when 'selected', 'only_my_events'
770 770
          # user receives notifications for created/assigned issues on unselected projects
771
          object.author == self || is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.assigned_to_before_last_save)
771
          object.author == self || is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.previous_assignee)
772 772
        when 'only_assigned'
773
          is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.assigned_to_before_last_save)
773
          is_or_belongs_to?(object.assigned_to) || is_or_belongs_to?(object.previous_assignee)
774 774
        when 'only_owner'
775 775
          object.author == self
776 776
        end
sandbox/rails-5.1/test/unit/issue_test.rb
3045 3045
    assert_equal IssueStatus.find(3), issue.status
3046 3046
  end
3047 3047

  
3048
  def test_assigned_to_was_with_a_group
3048
  def test_previous_assignee_with_a_group
3049 3049
    group = Group.find(10)
3050 3050
    Member.create!(:project_id => 1, :principal => group, :role_ids => [1])
3051 3051

  
3052 3052
    with_settings :issue_group_assignment => '1' do
3053 3053
      issue = Issue.generate!(:assigned_to => group)
3054 3054
      issue.reload.assigned_to = nil
3055
      assert_equal group, issue.assigned_to_was
3055
      assert_equal group, issue.previous_assignee
3056 3056
    end
3057 3057
  end
3058 3058

  

Also available in: Unified diff