##// END OF EJS Templates
Code cleanup: renamed variables in User#allowed_to? with explicit names...
Jean-Baptiste Barth -
r4120:c43ef6e7696e
parent child
Show More
@@ -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, project, options={})
356 def allowed_to?(action, context, options={})
357 if project && project.is_a?(Project)
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 project.active?
359 return false unless context.active?
360 # No action allowed on disabled modules
360 # No action allowed on disabled modules
361 return false unless project.allows_to?(action)
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(project)
365 roles = roles_for_project(context)
366 return false unless roles
366 return false unless roles
367 roles.detect {|role| (project.is_public? || role.member?) && role.allowed_to?(action)}
367 roles.detect {|role| (context.is_public? || role.member?) && role.allowed_to?(action)}
368
368
369 elsif project && project.is_a?(Array)
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 project.map do |p|
371 context.map do |project|
372 allowed_to?(action,p,options)
372 allowed_to?(action,project,options)
373 end.inject do |memo,p|
373 end.inject do |memo,allowed|
374 memo && p
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