Project

General

Profile

Patch #43429 ยป remove-addable_watcher_users.patch

Go MAEDA, 2025-11-03 02:34

View differences:

lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb
51 51
          base.extend ClassMethods
52 52
        end
53 53

  
54
        # Returns an array of users that are proposed as watchers
55
        def addable_watcher_users
56
          users = self.project.principals.assignable_watchers.sort - self.watcher_users
57
          if respond_to?(:visible?)
58
            users.reject! {|user| user.is_a?(User) && !visible?(user)}
59
          end
60
          users
61
        end
62

  
63 54
        # array of watchers that the given user is allowed to see
64 55
        def visible_watcher_users(user = User.current)
65 56
          if user.allowed_to?(:"view_#{self.class.name.underscore}_watchers", project)
test/unit/watcher_test.rb
110 110
    assert_equal 2, issue.watchers.count
111 111
  end
112 112

  
113
  def test_addable_watcher_users
114
    addable_watcher_users = @issue.addable_watcher_users
115
    assert_kind_of Array, addable_watcher_users
116
    addable_watcher_users.each do |addable_watcher|
117
      assert_equal true, addable_watcher.is_a?(User) || addable_watcher.is_a?(Group)
118
    end
119
  end
120

  
121 113
  def test_add_watcher_with_unsaved_object
122 114
    issue = Issue.new(project: Project.find(1), tracker_id: 1, subject: "test", author: User.find(2))
123 115
    assert_not issue.persisted?
......
155 147
    assert 0, Watcher.where(watchable: issue).count
156 148
  end
157 149

  
158
  def test_addable_watcher_users_should_not_include_user_that_cannot_view_the_object
159
    issue = Issue.new(:project => Project.find(1), :is_private => true)
160
    assert_nil issue.addable_watcher_users.detect {|user| user.is_a?(User) && !issue.visible?(user)}
161
  end
162

  
163 150
  def test_any_watched_should_return_false_if_no_object_is_watched
164 151
    objects = (0..2).map {Issue.generate!}
165 152

  
    (1-1/1)