update
This commit is contained in:
15
core/apps/accounts/permissions.py
Normal file
15
core/apps/accounts/permissions.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from rest_framework.exceptions import PermissionDenied
|
||||
from rest_framework.permissions import BasePermission
|
||||
|
||||
from core.apps.accounts.choices import RoleChoice
|
||||
|
||||
|
||||
class IsAdminRole(BasePermission):
|
||||
def has_permission(self, request, view):
|
||||
if not request.user.is_authenticated:
|
||||
return False
|
||||
|
||||
if request.user.role != RoleChoice.ADMIN:
|
||||
raise PermissionDenied("Only admin can access this")
|
||||
|
||||
return True
|
||||
Reference in New Issue
Block a user