diff options
author | Jean-Baptiste Barth <jeanbaptiste.barth@gmail.com> | 2010-09-29 05:22:45 +0000 |
---|---|---|
committer | Jean-Baptiste Barth <jeanbaptiste.barth@gmail.com> | 2010-09-29 05:22:45 +0000 |
commit | e8f3dd07dd8462d8d80948d5c8f094bdcc966d9a (patch) | |
tree | 7f2110ce12961a4faf6552d496f4e26e722fd4e1 /app/models | |
parent | fda1a0cb3b57830679405de1859270673bdcb0ba (diff) | |
download | redmine-e8f3dd07dd8462d8d80948d5c8f094bdcc966d9a.tar.gz redmine-e8f3dd07dd8462d8d80948d5c8f094bdcc966d9a.zip |
Added ability to specify multiple projects in User#allowed_to? (#5332)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4227 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/user.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 638e5f7bd..4b65b3d11 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -344,12 +344,17 @@ class User < Principal !roles_for_project(project).detect {|role| role.member?}.nil? end - # Return true if the user is allowed to do the specified action on project - # action can be: + # Return true if the user is allowed to do the specified action on a specific context + # Action can be: # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit') # * a permission Symbol (eg. :edit_project) + # Context can be: + # * a project : returns true if user is allowed to do the specified action on this 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, + # or falls back to Non Member / Anonymous permissions depending if the user is logged def allowed_to?(action, project, options={}) - if project + if project && project.is_a?(Project) # No action allowed on archived projects return false unless project.active? # No action allowed on disabled modules @@ -361,6 +366,11 @@ class User < Principal return false unless roles roles.detect {|role| (project.is_public? || role.member?) && role.allowed_to?(action)} + 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) + end elsif options[:global] # Admin users are always authorized return true if admin? |