]> source.dussan.org Git - redmine.git/commitdiff
Fixed: User#allowed_to? returning true in any case if array of projects had only...
authorJean-Baptiste Barth <jeanbaptiste.barth@gmail.com>
Wed, 6 Oct 2010 05:08:31 +0000 (05:08 +0000)
committerJean-Baptiste Barth <jeanbaptiste.barth@gmail.com>
Wed, 6 Oct 2010 05:08:31 +0000 (05:08 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4233 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/user.rb
test/unit/user_test.rb

index 4b65b3d118e4d7f7e7f96dac1f9c91ccf1cb236b..45ab4b4c2dbe3aee4ad905879806959c4ec7c3b6 100644 (file)
@@ -368,8 +368,10 @@ class User < Principal
       
     elsif project && project.is_a?(Array)
       # Authorize if user is authorized on every element of the array
-      project.inject do |memo,p|
-        memo && allowed_to?(action,p,options)
+      project.map do |p|
+        allowed_to?(action,p,options)
+      end.inject do |memo,p|
+        memo && p
       end
     elsif options[:global]
       # Admin users are always authorized
index b451c1e6b72146a58864396aa8ad364d07a0cd3e..3f824f9fe89db07ccb1782345eb0b3e337eb7d9a 100644 (file)
@@ -408,6 +408,10 @@ class UserTest < ActiveSupport::TestCase
         assert @jsmith.allowed_to?(:edit_issues, @jsmith.projects) #Manager or Developer everywhere
         assert ! @jsmith.allowed_to?(:delete_issue_watchers, @jsmith.projects) #Dev cannot delete_issue_watchers
       end
+      
+      should "behave correctly with arrays of 1 project" do
+        assert ! User.anonymous.allowed_to?(:delete_issues, [Project.first])
+      end
     end
     
     context "with options[:global]" do