permissionsx.models

PermissionsX - Authorization for Django.

copyright:Copyright (c) 2013-2014 by Robert Pogorzelski.
license:BSD, see LICENSE for more details.
class permissionsx.models.Arg(argument, request=None)[source]

Resolves string to an attribute of the request object.

A wrapper class used with P instances to change behaviour of Permissions.rules_evaluate() method.

If Arg is passed, it will be used an argument for the method defined in the rule (i.e. the last part of the keyword argument name), e.g.:

P(user__has_access_to=Arg('invoice'))

Will translate to:

is_authorized = request.user.has_access_to(request.invoice)
class permissionsx.models.Cmp(argument, request=None)[source]

Resolves string to an attribute of the request object.

A wrapper class used with P instances to change behaviour of Permissions.rules_evaluate() method.

If Cmp is passed, it will be used to retrieve attribute of the request object, e.g.:

P(user__equals_to=Cmp('invoice'))

Will translate to:

is_authorized = (request.user.equals_to == request.invoice)
class permissionsx.models.P(children=None, connector=None, negated=False, **kwargs)[source]

Base building block for defining rules.

Based on django.db.models.query_utils.Q mixed with django.utils.tree.Node.

class permissionsx.models.Permissions(*args, **kwargs)[source]

Base class for defining permissions. Usage:

permissions = SuperuserPermissions

Or when there is no need of reusing permissions in other parts of the code:

permissions = Permissions(P(user__is_superuser=True))
get_rules(request=None, **kwargs)[source]

Used for overriding rules.