Classes for calculating user permissions


>>> req = Permission('foo') & Permission('bar')
>>> req.check(PermissionContainer(['foo', 'baz'], ['bar']))

>>> req = Permission('login')
>>> req.check(['login'])

>>> req = Permission('login') | Permission('admin')
>>> req.check(['none'])
class milla.auth.permissions.BasePermission[source]

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)[source]

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 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=[])[source]

Container object for user and group permissions

  • 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

class milla.auth.permissions.PermissionRequirementAll(*requirements)[source]

Complex permission requirement needing all given permissions

class milla.auth.permissions.PermissionRequirementAny(*requirements)[source]

Complex permission requirement needing any given permissions