Patch #43429 ยป remove-addable_watcher_users.patch
| lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb | ||
|---|---|---|
|
base.extend ClassMethods
|
||
|
end
|
||
|
# Returns an array of users that are proposed as watchers
|
||
|
def addable_watcher_users
|
||
|
users = self.project.principals.assignable_watchers.sort - self.watcher_users
|
||
|
if respond_to?(:visible?)
|
||
|
users.reject! {|user| user.is_a?(User) && !visible?(user)}
|
||
|
end
|
||
|
users
|
||
|
end
|
||
|
# array of watchers that the given user is allowed to see
|
||
|
def visible_watcher_users(user = User.current)
|
||
|
if user.allowed_to?(:"view_#{self.class.name.underscore}_watchers", project)
|
||
| test/unit/watcher_test.rb | ||
|---|---|---|
|
assert_equal 2, issue.watchers.count
|
||
|
end
|
||
|
def test_addable_watcher_users
|
||
|
addable_watcher_users = @issue.addable_watcher_users
|
||
|
assert_kind_of Array, addable_watcher_users
|
||
|
addable_watcher_users.each do |addable_watcher|
|
||
|
assert_equal true, addable_watcher.is_a?(User) || addable_watcher.is_a?(Group)
|
||
|
end
|
||
|
end
|
||
|
def test_add_watcher_with_unsaved_object
|
||
|
issue = Issue.new(project: Project.find(1), tracker_id: 1, subject: "test", author: User.find(2))
|
||
|
assert_not issue.persisted?
|
||
| ... | ... | |
|
assert 0, Watcher.where(watchable: issue).count
|
||
|
end
|
||
|
def test_addable_watcher_users_should_not_include_user_that_cannot_view_the_object
|
||
|
issue = Issue.new(:project => Project.find(1), :is_private => true)
|
||
|
assert_nil issue.addable_watcher_users.detect {|user| user.is_a?(User) && !issue.visible?(user)}
|
||
|
end
|
||
|
def test_any_watched_should_return_false_if_no_object_is_watched
|
||
|
objects = (0..2).map {Issue.generate!}
|
||