mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
26 lines
989 B
Python
26 lines
989 B
Python
from rest_framework import permissions
|
|
|
|
|
|
class IsOwnerOrReadOnly(permissions.BasePermission):
|
|
"""
|
|
Custom permission to only allow owners of an object to edit it.
|
|
"""
|
|
|
|
def has_object_permission(self, request, view, obj):
|
|
# Read permissions are allowed to any request,
|
|
# so we'll always allow GET, HEAD or OPTIONS requests.
|
|
if request.method in permissions.SAFE_METHODS:
|
|
return True
|
|
|
|
# Write permissions are only allowed to the owner of the snippet.
|
|
return obj.user == request.user or request.user.is_superuser
|
|
|
|
class isTeacher(permissions.BasePermission):
|
|
#only teachers can make classes and assignmenst
|
|
def has_object_permission(self, request, view, obj):
|
|
if request.method in permissions.SAFE_METHODS:
|
|
return True
|
|
|
|
# Write permissions are only allowed to the owner of the snippet.
|
|
return request.user.groups.filter(name__in=['teachers']).exists() or request.user.is_superuser
|