Added permissions to views

This commit is contained in:
Keannu Christian Bernasol 2023-05-20 08:20:20 +08:00
parent 5b296ac367
commit 7ad2654b00
5 changed files with 18 additions and 1 deletions

View file

View file

@ -0,0 +1,9 @@
from rest_framework.permissions import BasePermission
class IsOwner(BasePermission):
"""
Custom permission to only allow the creator of an object to view and manipulate it.
"""
def has_object_permission(self, request, view, obj):
# Only allow the creator of the object to view and manipulate it.
return obj.creator == request.user