Advertisement
object_254

Untitled

Feb 19th, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. from rest_framework.permissions import SAFE_METHODS, BasePermission
  2.  
  3.  
  4. class IsAuthorized(BasePermission):
  5.  
  6.     def has_object_permission(self, request, view, obj):
  7.         if request.method in SAFE_METHODS:
  8.             return True
  9.         if request.user.is_authenticated == False:
  10.             return False
  11.         if request.method == 'POST':
  12.             return True
  13.         if request.method in ['PATCH', 'DELETE']:
  14.             return request.user.role in ['admin', 'moderator']
  15.         return True
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement