Logics

Base Logic

class permission.logics.base.PermissionLogic[source]

Bases: object

Abstract permission logic class

get_full_permission_string(perm)[source]

Return full permission string (app_label.perm_model)

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.

Author logic

Permission logic module for author based permission system

class permission.logics.author.AuthorPermissionLogic(field_name=None, any_permission=None, change_permission=None, delete_permission=None)[source]

Bases: PermissionLogic

Permission logic class for author based permission system

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

Check if user have permission (of object)

If the user_obj is not authenticated, it return False.

If no object is specified, it return True when the corresponding permission was specified to True (changed from v0.7.0). This behavior is based on the django system. https://code.djangoproject.com/wiki/RowLevelPermissions

If an object is specified, it will return True if the user is specified in field_name of the object (e.g. obj.author). So once user create an object and the object store who is the author in field_name attribute (default: author), the author can change or delete the object (you can change this behavior to set any_permission, change_permissino or delete_permission attributes of this instance).

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

Collaborators logic

Permission logic module for collaborators based permission system

class permission.logics.collaborators.CollaboratorsPermissionLogic(field_name=None, any_permission=None, change_permission=None, delete_permission=None)[source]

Bases: PermissionLogic

Permission logic class for collaborators based permission system

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

Check if user have permission (of object)

If the user_obj is not authenticated, it return False.

If no object is specified, it return True when the corresponding permission was specified to True (changed from v0.7.0). This behavior is based on the django system. https://code.djangoproject.com/wiki/RowLevelPermissions

If an object is specified, it will return True if the user is found in field_name of the object (e.g. obj.collaborators). So once the object store the user as a collaborator in field_name attribute (default: collaborators), the collaborator can change or delete the object (you can change this behavior to set any_permission, change_permission or delete_permission attributes of this instance).

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

GrouIn logic

Permission logic module for group based permission system

class permission.logics.groupin.GroupInPermissionLogic(group_names, any_permission=None, add_permission=None, change_permission=None, delete_permission=None)[source]

Bases: PermissionLogic

Permission logic class for group based permission system

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

Check if user have permission (of object)

If the user_obj is not authenticated, it return False.

If no object is specified, it return True when the corresponding permission was specified to True (changed from v0.7.0). This behavior is based on the django system. https://code.djangoproject.com/wiki/RowLevelPermissions

If an object is specified, it will return True if the user is in group specified in group_names of this instance. This permission logic is used mainly for group based role permission system. You can change this behavior to set any_permission, add_permission, change_permission, or delete_permission attributes of this instance.

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

Oneself logic

Permission logic module to manage users’ self-modifications

class permission.logics.oneself.OneselfPermissionLogic(any_permission=None, change_permission=None, delete_permission=None)[source]

Bases: PermissionLogic

Permission logic class to manage users’ self-modifications

Written by quasiyoke. https://github.com/lambdalisue/django-permission/pull/27

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

Check if user have permission of himself

If the user_obj is not authenticated, it return False.

If no object is specified, it return True when the corresponding permission was specified to True (changed from v0.7.0). This behavior is based on the django system. https://code.djangoproject.com/wiki/RowLevelPermissions

If an object is specified, it will return True if the object is the user. So users can change or delete themselves (you can change this behavior to set any_permission, change_permissino or delete_permission attributes of this instance).

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

Staff logic

Permission logic module for author based permission system

class permission.logics.staff.StaffPermissionLogic(any_permission=None, add_permission=None, change_permission=None, delete_permission=None)[source]

Bases: PermissionLogic

Permission logic class for is_staff authority based permission system

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

Check if user have permission (of object)

If the user_obj is not authenticated, it return False.

If no object is specified, it return True when the corresponding permission was specified to True (changed from v0.7.0). This behavior is based on the django system. https://code.djangoproject.com/wiki/RowLevelPermissions

If an object is specified, it will return True if the user is staff. The staff can add, change or delete the object (you can change this behavior to set any_permission, add_permission, change_permission, or delete_permission attributes of this instance).

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:

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

Return type:

boolean