16 lines
450 B
Python
16 lines
450 B
Python
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
|