[Django]-Debug Django Permission Typo

3๐Ÿ‘

โœ…

I found the answer. Just modify (temporarily) the code of backends.py:

--- django/contrib/auth/backends.py (Revision 17045)
+++ django/contrib/auth/backends.py (Arbeitskopie)
@@ -43,6 +43,9 @@
         return user_obj._perm_cache

     def has_perm(self, user_obj, perm):
+        all_perms=[u'%s.%s' % (ct, name) for ct, name in Permission.objects.values_list('content_type__app_label', 'codename')]
+        if not perm in all_perms:
+            raise Exception('Permission %s does not exist. foo permissions: %s' % (perm, [p for p in all_perms if 'foo' in p]))
         if not user_obj.is_active:
             return False
         return perm in self.get_all_permissions(user_obj)
๐Ÿ‘คguettli

2๐Ÿ‘

well i guess you could look at all defined permissions:

from django.contrib.auth.models import Permission
perms = ['%s.%s' % (p.content_type.app_label, p.codename) 
    for p in Permission.objects.all()]

>>> 'foo.bar' in perms
False
๐Ÿ‘คsecond

Leave a comment