milla.auth.permissions¶
Classes for calculating user permissions
Examples:
>>> req = Permission('foo') & Permission('bar')
>>> req.check(PermissionContainer(['foo', 'baz'], ['bar']))
True
>>> req = Permission('login')
>>> req.check(['login'])
True
>>> req = Permission('login') | Permission('admin')
>>> req.check(['none'])
False
-
class
milla.auth.permissions.
BasePermission
[source]¶ Base class for permissions and requirements
Complex permission requirements can be created using the bitwise
and
andor
operators:login_and_view = Permission('login') & Permission('view') admin_or_root = Permission('admin') | Permission('root') complex = Permission('login') & Permission('view') | Permission('admin')
-
class
milla.auth.permissions.
Permission
(name)[source]¶ Simple permission implementation
Parameters: name (str) – Name of the permission Permissions must implement a
check
method that accepts an iterable and returnsTrue
if the permission is present orFalse
otherwise.
-
class
milla.auth.permissions.
PermissionContainer
(user_perms=[], group_perms=[])[source]¶ Container object for user and group permissions
Parameters: - user_perms (list) – List of permissions held by the user itself
- group_perms (list) – List of permissions held by the groups to which the user belongs
Iterating over
PermissionContainer
objects results in a flattened representation of all permissions.
-
class
milla.auth.permissions.
PermissionRequirement
(*requirements)[source]¶ Base class for complex permission requirements