feat(whole project): huge changes, huge updates

This commit is contained in:
sankalp committed 2025-04-24 20:17:52 +05:45
1 parent 666b5bb827
commit 2bd8bb2dfc
196 files changed
+9146 -4316

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
from rest_framework import permissions
class IsOwnerOrAdmin(permissions.BasePermission):
"""
Custom permission to only allow owners of an object or admins 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
# Admin can do anything
if request.user.is_staff:
return True
# Instance must have an attribute named `user`.
if hasattr(obj, 'user'):
return obj.user == request.user
# If object is a User, check if it's the current user
if hasattr(obj, 'username'):
return obj == request.user
return False