]> source.dussan.org Git - redmine.git/commitdiff
Make sure user can not watch what he is not allowed to view.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 13 Dec 2009 14:48:28 +0000 (14:48 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 13 Dec 2009 14:48:28 +0000 (14:48 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3170 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/watchers_controller.rb
test/functional/watchers_controller_test.rb

index 694718e281195fad97c2a90fc5d0f74d76c83709..06e5802f6c06be0d0b47e24b9a9ad42f93d72426 100644 (file)
@@ -25,7 +25,11 @@ class WatchersController < ApplicationController
          :render => { :nothing => true, :status => :method_not_allowed }
   
   def watch
-    set_watcher(User.current, true)
+    if @watched.respond_to?(:visible?) && !@watched.visible?(User.current)
+      render_403
+    else
+      set_watcher(User.current, true)
+    end
   end
   
   def unwatch
index cf977887ec200f110ccd56b19693e1012ce00429..01dee37471ae5a3cc5d104a34152115373ce02c7 100644 (file)
@@ -47,6 +47,15 @@ class WatchersControllerTest < ActionController::TestCase
     end
     assert Issue.find(1).watched_by?(User.find(3))
   end
+  
+  def test_watch_should_be_denied_without_permission
+    Role.find(2).remove_permission! :view_issues
+    @request.session[:user_id] = 3
+    assert_no_difference('Watcher.count') do
+      xhr :post, :watch, :object_type => 'issue', :object_id => '1'
+      assert_response 403
+    end
+  end
 
   def test_watch_with_multiple_replacements
     @request.session[:user_id] = 3