The has_perm
method of the AbstractUser
(if your User model inherits from it) actually checks, for every auth backend you set up, the inner has_perm
function, the code is below:
def _user_has_perm(user, perm, obj):
"""
A backend can raise `PermissionDenied` to short-circuit permission checking.
"""
for backend in auth.get_backends():
if not hasattr(backend, 'has_perm'):
continue
try:
if backend.has_perm(user, perm, obj):
return True
except PermissionDenied:
return False
return False
So the first thing to check if wheter you have an authorization backend that actually checks the group permissions, you can either create a custom one or use the default ModelBackend
,you can specify this in your settings through the following key:
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
]
After that, be sure to pass the permission as a string formatted in the same format used by the backend, in this case the ModelBackend formats it like this f"{perm..content_type.app_label}.{perm.codename}
A working example for your case would be:
user.has_perm("app_name.can_show_distribute_page")