@@ -353,25 +353,25 class User < Principal | |||||
353 | # * a group of projects : returns true if user is allowed on every project |
|
353 | # * a group of projects : returns true if user is allowed on every project | |
354 | # * nil with options[:global] set : check if user has at least one role allowed for this action, |
|
354 | # * nil with options[:global] set : check if user has at least one role allowed for this action, | |
355 | # or falls back to Non Member / Anonymous permissions depending if the user is logged |
|
355 | # or falls back to Non Member / Anonymous permissions depending if the user is logged | |
356 |
def allowed_to?(action, |
|
356 | def allowed_to?(action, context, options={}) | |
357 |
if |
|
357 | if context && context.is_a?(Project) | |
358 | # No action allowed on archived projects |
|
358 | # No action allowed on archived projects | |
359 |
return false unless |
|
359 | return false unless context.active? | |
360 | # No action allowed on disabled modules |
|
360 | # No action allowed on disabled modules | |
361 |
return false unless |
|
361 | return false unless context.allows_to?(action) | |
362 | # Admin users are authorized for anything else |
|
362 | # Admin users are authorized for anything else | |
363 | return true if admin? |
|
363 | return true if admin? | |
364 |
|
364 | |||
365 |
roles = roles_for_project( |
|
365 | roles = roles_for_project(context) | |
366 | return false unless roles |
|
366 | return false unless roles | |
367 |
roles.detect {|role| ( |
|
367 | roles.detect {|role| (context.is_public? || role.member?) && role.allowed_to?(action)} | |
368 |
|
368 | |||
369 |
elsif |
|
369 | elsif context && context.is_a?(Array) | |
370 | # Authorize if user is authorized on every element of the array |
|
370 | # Authorize if user is authorized on every element of the array | |
371 |
|
|
371 | context.map do |project| | |
372 | allowed_to?(action,p,options) |
|
372 | allowed_to?(action,project,options) | |
373 |
end.inject do |memo, |
|
373 | end.inject do |memo,allowed| | |
374 |
memo && |
|
374 | memo && allowed | |
375 | end |
|
375 | end | |
376 | elsif options[:global] |
|
376 | elsif options[:global] | |
377 | # Admin users are always authorized |
|
377 | # Admin users are always authorized |
General Comments 0
You need to be logged in to leave comments.
Login now