permission package

Subpackages

Submodules

permission.backends module

Logical permission backends module

class permission.backends.PermissionBackend[source]

Bases: object

A handler based permission backend

authenticate(username, password)[source]

Always return None to prevent authentication within this backend.

has_module_perms(user_obj, app_label)[source]

Check if user have permission of specified app based on registered handlers.

It will raise ObjectDoesNotExist exception when the specified string permission does not exist and PERMISSION_CHECK_PERMISSION_PRESENCE is True in settings module.

Parameters
  • user_obj (django user model instance) – A django user model instance which is checked

  • app_label (string) – app_label.codename formatted permission string

Returns

Whether the specified user have specified permission.

Return type

boolean

Raises

django.core.exceptions.ObjectDoesNotExist – If the specified string permission does not exist and PERMISSION_CHECK_PERMISSION_PRESENCE is True in settings module.

has_perm(user_obj, perm, obj=None)[source]

Check if user have permission (of object) based on registered handlers.

It will raise ObjectDoesNotExist exception when the specified string permission does not exist and PERMISSION_CHECK_PERMISSION_PRESENCE is True in settings module.

Parameters
  • user_obj (django user model instance) – A django user model instance which be checked

  • perm (string) – app_label.codename formatted permission string

  • obj (None or django model instance) – None or django model instance for object permission

Returns

Whether the specified user have specified permission (of specified object).

Return type

boolean

Raises

django.core.exceptions.ObjectDoesNotExist – If the specified string permission does not exist and PERMISSION_CHECK_PERMISSION_PRESENCE is True in settings module.

supports_anonymous_user = True
supports_inactive_user = True
supports_object_permissions = True

permission.compat module

permission.compat.is_anonyomus(user_obj)[source]
permission.compat.is_authenticated(user_obj)[source]
permission.compat.isstr(x)[source]

permission.conf module

django-permission2 application configure

permission.handlers module

class permission.handlers.LogicalPermissionHandler(model)[source]

Bases: PermissionHandler

Permission handler class which use permission logics to determine the permission

has_perm(user_obj, perm, obj=None)[source]

Check if user have permission (of object) based on specified models’s _permission_logics attribute.

The result will be stored in user_obj as a cache to reduce method call.

Parameters
  • user_obj (django user model instance) – A django user model instance which be checked

  • perm (string) – app_label.codename formatted permission string

  • obj (None or django model instance) – None or django model instance for object permission

Returns

Whether the specified user have specified permission (of specified object).

Return type

boolean

class permission.handlers.PermissionHandler(model_or_app_label)[source]

Bases: object

Abstract permission handler class

property excludes
get_supported_app_labels()[source]

Get app labels which this handler can treat. Specified with includes and excludes of this instance.

Returns

A set instance of app_label

Return type

set

get_supported_permissions()[source]

Get permissions which this handler can treat. Specified with includes and excludes of this instance.

Returns

A set instance of app_label.codename formatted permission strings

Return type

set

has_module_perms(user_obj, app_label)[source]

Check if user have permission of specified app

Parameters
  • user_obj (django user model instance) – A django user model instance which be checked

  • app_label (string) – Django application name

Returns

Whether the specified user have any permissions of specified app

Return type

boolean

has_perm(user_obj, perm, obj=None)[source]

Check if user have permission (of object)

Parameters
  • user_obj (django user model instance) – A django user model instance which be checked

  • perm (string) – app_label.codename formatted permission string

  • obj (None or django model instance) – None or django model instance for object permission

Returns

  • boolean – Whether the specified user have specified permission (of specified object).

  • .. note:: – Sub class must override this method.

property includes

Module contents

permission.has_permissionif_in_builtins()[source]