Code cleanup: renamed variables in User#allowed_to? with explicit names
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4234 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
e59c927ee5
commit
c43ef6e769
|
@ -353,25 +353,25 @@ class User < Principal
|
||||||
# * a group of projects : returns true if user is allowed on every project
|
# * a group of projects : returns true if user is allowed on every project
|
||||||
# * nil with options[:global] set : check if user has at least one role allowed for this action,
|
# * nil with options[:global] set : check if user has at least one role allowed for this action,
|
||||||
# or falls back to Non Member / Anonymous permissions depending if the user is logged
|
# or falls back to Non Member / Anonymous permissions depending if the user is logged
|
||||||
def allowed_to?(action, project, options={})
|
def allowed_to?(action, context, options={})
|
||||||
if project && project.is_a?(Project)
|
if context && context.is_a?(Project)
|
||||||
# No action allowed on archived projects
|
# No action allowed on archived projects
|
||||||
return false unless project.active?
|
return false unless context.active?
|
||||||
# No action allowed on disabled modules
|
# No action allowed on disabled modules
|
||||||
return false unless project.allows_to?(action)
|
return false unless context.allows_to?(action)
|
||||||
# Admin users are authorized for anything else
|
# Admin users are authorized for anything else
|
||||||
return true if admin?
|
return true if admin?
|
||||||
|
|
||||||
roles = roles_for_project(project)
|
roles = roles_for_project(context)
|
||||||
return false unless roles
|
return false unless roles
|
||||||
roles.detect {|role| (project.is_public? || role.member?) && role.allowed_to?(action)}
|
roles.detect {|role| (context.is_public? || role.member?) && role.allowed_to?(action)}
|
||||||
|
|
||||||
elsif project && project.is_a?(Array)
|
elsif context && context.is_a?(Array)
|
||||||
# Authorize if user is authorized on every element of the array
|
# Authorize if user is authorized on every element of the array
|
||||||
project.map do |p|
|
context.map do |project|
|
||||||
allowed_to?(action,p,options)
|
allowed_to?(action,project,options)
|
||||||
end.inject do |memo,p|
|
end.inject do |memo,allowed|
|
||||||
memo && p
|
memo && allowed
|
||||||
end
|
end
|
||||||
elsif options[:global]
|
elsif options[:global]
|
||||||
# Admin users are always authorized
|
# Admin users are always authorized
|
||||||
|
|
Loading…
Reference in New Issue