mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
permissions must return a boolean
`x and y` actually returns object y when both are true. the means P & IsAuthenticated will fail with TypeError: unsupported operand type(s) for &: 'instance' and 'bool' as IsAuthenticated now returns a CallableBool which does not overload __ror__
This commit is contained in:
parent
9d001cd84c
commit
6f2c0dbf4d
|
@ -110,7 +110,7 @@ class IsAuthenticated(BasePermission):
|
|||
"""
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return request.user and request.user.is_authenticated
|
||||
return bool(request.user and request.user.is_authenticated)
|
||||
|
||||
|
||||
class IsAdminUser(BasePermission):
|
||||
|
@ -119,7 +119,7 @@ class IsAdminUser(BasePermission):
|
|||
"""
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return request.user and request.user.is_staff
|
||||
return bool(request.user and request.user.is_staff)
|
||||
|
||||
|
||||
class IsAuthenticatedOrReadOnly(BasePermission):
|
||||
|
@ -128,7 +128,7 @@ class IsAuthenticatedOrReadOnly(BasePermission):
|
|||
"""
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return (
|
||||
return bool(
|
||||
request.method in SAFE_METHODS or
|
||||
request.user and
|
||||
request.user.is_authenticated
|
||||
|
|
Loading…
Reference in New Issue
Block a user