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.

20 lines
792 B

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. from django.shortcuts import get_object_or_404
  2. from rest_framework.permissions import IsAuthenticated
  3. from rest_framework.response import Response
  4. from rest_framework.views import APIView
  5. from members.permissions import IsAnnotationApprover, IsProjectAdmin
  6. from ..models import Example
  7. from ..serializers import ApproverSerializer
  8. class ApprovalAPI(APIView):
  9. permission_classes = [IsAuthenticated & (IsAnnotationApprover | IsProjectAdmin)]
  10. def post(self, request, *args, **kwargs):
  11. approved = self.request.data.get('approved', True)
  12. example = get_object_or_404(Example, pk=self.kwargs['example_id'])
  13. example.annotations_approved_by = self.request.user if approved else None
  14. example.save()
  15. return Response(ApproverSerializer(example).data)