Created
June 27, 2010 13:18
-
-
Save Ciantic/454898 to your computer and use it in GitHub Desktop.
Django object permission backend, that passesthrough
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
class ObjectPermBackend(object): | |
"""Simple object permission backend that passesthrough the has_perm calls | |
to the object. | |
""" | |
supports_object_permissions = True | |
supports_anonymous_user = True | |
def authenticate(self, username, password): #@UnusedVariable | |
"""Stub authenticate, do nothing.""" | |
return None | |
def has_perm(self, user, perm, obj=None): | |
"""Passes the has_perm call to object. | |
:param user: User object | |
:param perm: Permission string | |
:param obj: Object | |
""" | |
if hasattr(obj, "has_perm"): | |
return obj.has_perm(user, perm) | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage in settings.py:
Notice that this does not affect the normal ModelBackend when used like this.