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

Base class for permissions and requirements

Complex permission requirements can be created using the bitwise and and or 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)

Simple permission implementation

Parameters:name (str) – Name of the permission

Permissions must implement a check method that accepts an iterable and returns True if the permission is present or False otherwise.

check(perms)

Check if the permission is held

This method can be overridden to provide more robust support, but this implementation is simple:

return self in perms
class milla.auth.permissions.PermissionContainer(user_perms=, []group_perms=[])

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)

Base class for complex permission requirements

class milla.auth.permissions.PermissionRequirementAll(*requirements)

Complex permission requirement needing all given permissions

class milla.auth.permissions.PermissionRequirementAny(*requirements)

Complex permission requirement needing any given permissions