Advertisement
themaleem

permissions.py

Jul 17th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. from rest_framework import permissions
  2.  
  3.  
  4. class IsAdminUserOrReadOnly(permissions.BasePermission):
  5. # Allow GET requests for anyone
  6. # but allow only admin users for other actions
  7. def has_permission(self, request, view):
  8. if request.method in permissions.SAFE_METHODS:
  9. return True
  10. return request.user and request.user.is_staff
  11.  
  12.  
  13. class IsOwnerOrAdmin(permissions.BasePermission):
  14. # Allow GET requests for anyone
  15. def has_object_permission(self, request, view, obj):
  16. return request.user.is_staff or obj.user == request.user
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement