Michael Hall committed c5e3ee3

Add object-permissions capable backed based on Roles

Comments (0)

Files changed (2)


 @author: Michael Hall <>
+from django.contrib.auth.backends import ModelBackend
+from extauth import roles
+class RoleBackend(ModelBackend):
+    supports_object_permissions = True
+    def has_perm(self, user_obj, perm, obj=None):
+        if obj is None:
+            return False
+        obj_roles = roles.get_roles(obj, user_obj)
+        return obj_roles.has_perm(perm)
+    def get_group_permissions(self, user_obj, obj=None):
+        return None
+    def get_all_permissions(self, user_obj, obj=None):
+        obj_roles = roles.get_roles(obj, user_obj)
+        return obj_roles.getUserPerms()
+    def has_module_perms(self, user_obj, app_label, obj=None):
+        return False
         return uRoles
+    def getUserPerms(self):
+        perms = Role.objects.filter(model=model_type, 
+                                        role__in=self.getUserRoles(),
+                                        permissions__content_type__app_label=app,
+                                        permissions__codename=perm)
+        return set([u"%s.%s" % (p.content_type.app_label, p.codename) for p in perms])
     def has_perm(self, pName):
         model_type = ContentType.objects.get_for_model(self.model.__class__)
         (app, sep, perm) = pName.partition('.')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.