diff --git a/src/django/api/views/boundary.py b/src/django/api/views/boundary.py index 1adfa685..92ad5345 100644 --- a/src/django/api/views/boundary.py +++ b/src/django/api/views/boundary.py @@ -78,40 +78,22 @@ def post(self, request, id, format=None): boundary_set = boundary_set.prefetch_related('submissions') boundary = get_object_or_404(boundary_set, pk=id) - if boundary.status == BOUNDARY_STATUS.DRAFT: - if request.user.role not in [Roles.CONTRIBUTOR, Roles.ADMINISTRATOR]: - raise ForbiddenException( - 'Only contributors and administrators can edit only drafts.' - ) - - shape = BoundaryShapeView.get_valid_shape(request.data) - - boundary.latest_submission.shape = shape - boundary.latest_submission.save() - - elif boundary.status == BOUNDARY_STATUS.IN_REVIEW: - if request.user.role not in [Roles.VALIDATOR, Roles.ADMINISTRATOR]: - raise ForbiddenException( - 'Only validators and administrators can edit boundaries in review.' - ) - - shape = BoundaryShapeView.get_valid_shape(request.data) - - boundary.latest_submission.review.shape = shape - boundary.latest_submission.review.save() + if request.user.role not in [Roles.CONTRIBUTOR, Roles.ADMINISTRATOR]: + raise ForbiddenException( + 'Only contributors and administrators can edit boundaries.' + ) - else: - return BadRequestException( + if boundary.status != BOUNDARY_STATUS.DRAFT: + raise BadRequestException( 'Cannot update shape of boundary with status: {}'.format( boundary.status ), ) - return Response() - - @staticmethod - def get_valid_shape(data): - serializer = ShapeSerializer(data=data) + serializer = ShapeSerializer(data=request.data) serializer.is_valid(raise_exception=True) - return serializer.validated_data + boundary.latest_submission.shape = serializer.validated_data + boundary.latest_submission.save() + + return Response()