]> source.dussan.org Git - redmine.git/commitdiff
Do not propose users that can't view an issue as watchers (#7412).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 22 May 2011 09:14:36 +0000 (09:14 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 22 May 2011 09:14:36 +0000 (09:14 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5876 e93f8b46-1217-0410-a6f0-8f06a7374b81

test/unit/watcher_test.rb
vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb

index 86d96b2cb108fcbe474f779f02e81bda48da8602..d9abb7f6d0a76c1c2820c53b132f63f81ad5e6ee 100644 (file)
@@ -53,6 +53,17 @@ class WatcherTest < ActiveSupport::TestCase
     assert issue.watched_by?(User.find(1))
   end
   
+  def test_addable_watcher_users
+    addable_watcher_users = @issue.addable_watcher_users
+    assert_kind_of Array, addable_watcher_users
+    assert_kind_of User, addable_watcher_users.first
+  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| !issue.visible?(user)}
+  end
+  
   def test_recipients
     @issue.watchers.delete_all
     @issue.reload
index 61196d9a8cf6bd50a41cd38d06dba388dbca7c61..a22098eec587f9cb6372b55afd3dba7543023d6f 100644 (file)
@@ -31,7 +31,11 @@ module Redmine
         
         # Returns an array of users that are proposed as watchers
         def addable_watcher_users
-          self.project.users.sort - self.watcher_users
+          users = self.project.users.sort - self.watcher_users
+          if respond_to?(:visible?)
+            users.reject! {|user| !visible?(user)}
+          end
+          users
         end
         
         # Adds user as a watcher