You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
846 B

4 years ago
  1. from rest_framework.permissions import BasePermission
  2. class CanEditAnnotation(BasePermission):
  3. def __init__(self, queryset):
  4. super().__init__()
  5. self.queryset = queryset
  6. def has_permission(self, request, view):
  7. if request.user.is_superuser:
  8. return True
  9. annotation_id = view.kwargs.get('annotation_id')
  10. return self.queryset.filter(id=annotation_id, user=request.user).exists()
  11. class IsOwnComment(BasePermission):
  12. @classmethod
  13. def has_object_permission(cls, request, view, obj):
  14. if request.user.is_superuser:
  15. return True
  16. return obj.user.id == request.user.id
  17. class IsStaff(BasePermission):
  18. def has_permission(self, request, view):
  19. if request.user.is_superuser or request.user.is_staff:
  20. return True
  21. return False