#32255: User.has_perm should forward **kwargs to allow more flexibility in
authentication backends
-------------------------------------+-------------------------------------
Reporter: Matteo Parrucci | Owner: nobody
Type: New feature | Status: new
Component: contrib.auth | Version: 3.1
Severity: Normal | Resolution:
Keywords: auth, | Triage Stage:
django.contrib.auth, | Unreviewed
authentication, request, |
has_perm, has_perms, sites, |
django.contrib.sites |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Matteo Parrucci):
I've implemented it in a demo project and it now looks like this:
Into django.contrib.auth.models.AbstractUser
{{{
def has_perm(self, perm, obj=None, **kwargs):
return _user_has_perm(self, perm, obj=obj, **kwargs)
def has_perms(self, perm_list, obj=None, **kwargs):
return all(self.has_perm(perm, obj, **kwargs) for perm in
perm_list)
}}}
In the same module the checking permission function:
{{{
def _user_has_perm(user, perm, obj, **kwargs):
"""
A backend can raise `PermissionDenied` to short-circuit permission
checking.
"""
for backend in get_backends():
if not hasattr(backend, 'has_perm'):
continue
try:
if backend.has_perm(user, perm, obj, **kwargs):
return True
except PermissionDenied:
return False
return False
}}}
And it works for me now. It is a small change and I think it could be
useful for others too. Basically I only added **kwargs to the signatures
and forwarded it to the auth backends.
--
Ticket URL: <https://code.djangoproject.com/ticket/32255#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.963be8d5d012c81883e0a3f75e452bb9%40djangoproject.com.