Learning-Management-System/lms/app/permissions.py
2025-01-10 19:54:55 +02:00

19 lines
712 B
Python

from rest_framework.permissions import BasePermission
class IsInstructor(BasePermission):
"""
Custom permission to allow access only to users with role 'instructor'.
"""
def has_permission(self, request, view):
# Ensure the user is authenticated and has a role of 'instructor'
return request.user.is_authenticated and request.user.role == 'instructor'
class IsAdmin(BasePermission):
"""
Custom permission to allow access only to users with role 'instructor'.
"""
def has_permission(self, request, view):
# Ensure the user is authenticated and has a role of 'instructor'
return request.user.is_authenticated and request.user.role == 'admin'