Skip to content

Commit b86386c

Browse files
committed
Change & refactor permission to IsNotBlacklisted
1 parent 352b30f commit b86386c

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

demo/app/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from rest_framework.response import Response
66
from rest_framework.views import APIView
77

8-
from rest_framework_jwt.blacklist.permissions import IsAuthenticatedAndNotBlacklisted
8+
from rest_framework_jwt.blacklist.permissions import IsNotBlacklisted
99
from rest_framework_jwt.permissions import IsSuperUser
1010

1111

@@ -22,7 +22,7 @@ def get(self, request):
2222

2323

2424
class BlacklistPermissionTestView(APIView):
25-
permission_classes = (IsAuthenticatedAndNotBlacklisted, )
25+
permission_classes = (IsNotBlacklisted, )
2626

2727
def get(self, request):
2828
return Response({'foo': 'bar'})

demo/demo/settings/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
REST_FRAMEWORK = {
129129
'DEFAULT_PERMISSION_CLASSES': (
130130
'rest_framework.permissions.IsAuthenticated',
131-
'rest_framework_jwt.blacklist.permissions.IsAuthenticatedAndNotBlacklisted',
131+
'rest_framework_jwt.blacklist.permissions.IsNotBlacklisted',
132132
),
133133
'DEFAULT_AUTHENTICATION_CLASSES': (
134134
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
1+
from django.utils.encoding import force_str
22
from rest_framework.permissions import BasePermission
33

44
from rest_framework_jwt.blacklist.models import BlacklistedToken
55
from rest_framework_jwt.settings import api_settings
66

77

8-
class IsAuthenticatedAndNotBlacklisted(BasePermission):
9-
message = 'You are not authenticated or have been blacklisted.'
8+
class IsNotBlacklisted(BasePermission):
9+
message = 'You have been blacklisted.'
1010

1111
def has_permission(self, request, view):
12-
if request.user and not request.user.is_authenticated:
13-
return False
14-
1512
if api_settings.JWT_AUTH_COOKIE:
1613
token = request.COOKIES.get(api_settings.JWT_AUTH_COOKIE)
1714
else:
18-
token = request.auth.decode('utf-8')
15+
token = force_str(request.auth)
1916

2017
return not BlacklistedToken.objects.filter(token=token).exists()

0 commit comments

Comments
 (0)