Package expedient :: Package common :: Package permissions :: Module shortcuts
[hide private]
[frames] | no frames]

Module shortcuts

source code

Created on Jul 30, 2010


Author: jnaous

Functions [hide private]
 
get_permittee_from_threadlocals(kw)
Wrapper to get a permittee keyword from threadlocals and make sure it is usable.
source code
bool
has_permission(permittee, target_obj_or_class, perm_name)
Does the object permittee have the permission named by perm_name over target object or class target_obj_or_class.
source code
bool
must_have_permission(permittee, target_obj_or_class, perm_name, allow_redirect=True)
Does the object permittee have the permission named by perm_name over target object or class target_obj_or_class.
source code
 
create_permission(perm_name, description='', view=None, force=True)
Shortcut to create a new permission.
source code
 
give_permission_to(permission, obj_or_class, receiver, giver=None, can_delegate=False)
Give receiver the permission permission over the object or class obj_or_class.
source code
 
delete_permission(permission, obj_or_class, owner)
Take permission away from an owner.
source code
 
require_objs_permissions_for_url(url, perm_names, permittee_func, target_func, methods=['GET', 'POST'])
Convenience wrapper around PermissionMiddleware.
source code
Variables [hide private]
  logger = logging.getLogger("permissions.shortcuts")
  __package__ = 'expedient.common.permissions'
Function Details [hide private]

has_permission(permittee, target_obj_or_class, perm_name)

source code 

Does the object permittee have the permission named by perm_name over target object or class target_obj_or_class.

Parameters:
  • permittee (Permittee or Model instance.) - object that should own the permission or the keyword argument for that object that was stored in the threadlocals middleware.
  • target_obj_or_class (Model instance or class.) - The object or class for whose the permission is being checked.
  • perm_name (str.) - The name of the permission
Returns: bool
Whether or not the permittee has the permission

must_have_permission(permittee, target_obj_or_class, perm_name, allow_redirect=True)

source code 

Does the object permittee have the permission named by perm_name over target object or class target_obj_or_class. If not, then raise a PermissionDenied exception.

Parameters:
  • permittee (Permittee or Model instance.) - object that should own the permission or the keyword argument for that object that was stored in the threadlocals middleware.
  • target_obj_or_class (Model instance or class.) - The object or class for whose the permission is being checked.
  • perm_name (str.) - The name of the permission
  • allow_redirect (bool) - Should the user be redirected if the permission is denied to the permission's redirection URL? Default True
Returns: bool
Whether or not the permittee has the permission

create_permission(perm_name, description='', view=None, force=True)

source code 

Shortcut to create a new permission. See ExpedientPermissionManager.create_permission.

give_permission_to(permission, obj_or_class, receiver, giver=None, can_delegate=False)

source code 

Give receiver the permission permission over the object or class obj_or_class. If giver is specified, then the function checks that the giver is allowed to give the permission to the receiver. If can_delegate is True, the receiver is given the ability to further give the permission to others.

Parameters:
  • permission (str or ExpedientPermission.) - The name of the permission to give to reciever or the ExpedientPermission instance.
  • obj_or_class (Model instance or class.) - The object or class for which the permission is given.
  • receiver (Permittee or Model instance.) - The permittee receiving the permission. If not a Permittee instance, one will be created if not found.
  • giver (Permittee or Model instance.) - The permission owner giving the permission. If not a Permittee instance, one will be created (if not found). defaults to None.
  • can_delegate (bool) - Can the receiver in turn give the permission out? Default is False.
Returns:
The new PermissionOwnership instance.

delete_permission(permission, obj_or_class, owner)

source code 

Take permission away from an owner.

Remove the permission permission to use object or class obj_or_class from the owner owner. If the owner doesn't have the permission to begin with, nothing happens.

Parameters:
  • permission (str or ExpedientPermission.) - The name of the permission to remove or its ExpedientPermission instance.
  • obj_or_class (Model instance or class.) - The object or class for which the permission is being removed
  • owner (Permittee or Model instance.) - The permittee currently owning the permission.