Fixed that User#allowed_to? should return true or false (#12078).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10614 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2012-10-12 09:12:03 +00:00
parent 92391abd1e
commit 8358dc1cc5
2 changed files with 26 additions and 26 deletions
+7 -7
View File
@@ -487,17 +487,17 @@ class User < Principal
roles = roles_for_project(context)
return false unless roles
roles.detect {|role|
roles.any? {|role|
(context.is_public? || role.member?) &&
role.allowed_to?(action) &&
(block_given? ? yield(role, self) : true)
}
elsif context && context.is_a?(Array)
# Authorize if user is authorized on every element of the array
context.map do |project|
allowed_to?(action, project, options, &block)
end.inject do |memo,allowed|
memo && allowed
if context.empty?
false
else
# Authorize if user is authorized on every element of the array
context.map {|project| allowed_to?(action, project, options, &block)}.reduce(:&)
end
elsif options[:global]
# Admin users are always authorized
@@ -506,7 +506,7 @@ class User < Principal
# authorize if user has at least one role that has this permission
roles = memberships.collect {|m| m.roles}.flatten.uniq
roles << (self.logged? ? Role.non_member : Role.anonymous)
roles.detect {|role|
roles.any? {|role|
role.allowed_to?(action) &&
(block_given? ? yield(role, self) : true)
}