From 22714715f8bc591fb27e41dd527d925b92603e19 Mon Sep 17 00:00:00 2001 From: Amir <84547283+amir4v@users.noreply.github.com> Date: Tue, 7 Mar 2023 19:49:42 +0330 Subject: [PATCH] IsNotAuthenticated Allows access only to unauthenticated users. --- rest_framework/permissions.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rest_framework/permissions.py b/rest_framework/permissions.py index 8fb4569cb..1a116965b 100644 --- a/rest_framework/permissions.py +++ b/rest_framework/permissions.py @@ -127,6 +127,15 @@ class BasePermission(metaclass=BasePermissionMetaclass): return True +class IsNotAuthenticated(BasePermission): + """ + Allows access only to unauthenticated users. + """ + + def has_permission(self, request, view): + return str(request.user) == 'AnonymousUser' + + class AllowAny(BasePermission): """ Allow any access.