Skip to content

Commit

Permalink
fixup! Add update boundary shape route
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Stone committed Oct 19, 2022
1 parent 4c8ab5c commit fea16bc
Showing 1 changed file with 11 additions and 29 deletions.
40 changes: 11 additions & 29 deletions src/django/api/views/boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit fea16bc

Please sign in to comment.