Project

General

Profile

Defect #44680 ยป 0001-Set-assignee-as-watcher-based-on-issue_assigned_to_m.patch

Ivan Kabluchkov, 2026-10-26 15:56

View differences:

app/models/issue.rb
2116 2116
        self.watcher_user_ids.exclude?(author.id)
2117 2117
      self.set_watcher(author, true)
2118 2118
    end
2119

  
2120
    if assigned_to.is_a?(User) &&
2121
        assigned_to.active? &&
2122
        assigned_to.pref.auto_watch_on?('issue_assigned_to_me') &&
2123
        self.watcher_user_ids.exclude?(assigned_to.id)
2124
      self.set_watcher(assigned_to, true)
2125
    end
2119 2126
  end
2120 2127

  
2121 2128
  def send_notification
test/unit/issue_test.rb
3658 3658
    end
3659 3659
  end
3660 3660

  
3661
  def test_create_should_add_assignee_as_watcher
3662
    user = User.first
3663
    user.pref.auto_watch_on = []
3664
    user.pref.save
3665
    assignee = User.find(2)
3666
    assignee.pref.auto_watch_on = ['issue_assigned_to_me']
3667
    assignee.pref.save
3668

  
3669
    issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => user.id, :assigned_to => assignee, :subject => 'test_create_should_add_assignee_as_watcher')
3670

  
3671
    assert_difference 'Watcher.count', 1 do
3672
      assert_equal true, issue.save
3673
    end
3674
    assert issue.watched_by?(assignee)
3675
  end
3676

  
3677
  def test_create_should_not_add_assignee_as_watcher_without_preference
3678
    user = User.first
3679
    user.pref.auto_watch_on = []
3680
    user.pref.save
3681
    assignee = User.find(2)
3682
    assignee.pref.auto_watch_on = []
3683
    assignee.pref.save
3684

  
3685
    issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => user.id, :assigned_to => assignee, :subject => 'test_create_should_not_add_assignee_as_watcher')
3686

  
3687
    assert_no_difference 'Watcher.count' do
3688
      assert_equal true, issue.save
3689
    end
3690
  end
3691

  
3692
  def test_create_should_add_assignee_watcher_only_once_when_author_is_assignee
3693
    user = User.first
3694
    user.pref.auto_watch_on = %w[issue_created issue_assigned_to_me]
3695
    user.pref.save
3696

  
3697
    issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => user.id, :assigned_to => user, :subject => 'test_create_should_add_assignee_watcher_only_once')
3698

  
3699
    assert_difference 'Watcher.count', 1 do
3700
      assert_equal true, issue.save
3701
    end
3702
  end
3703

  
3661 3704
  def test_change_of_project_parent_should_update_shared_versions_with_derived_priorities
3662 3705
    with_settings('parent_issue_priority' => 'derived') do
3663 3706
      parent = Project.find 1
    (1-1/1)