Skip to content

Commit fea16bc

Browse files
author
Matt Stone
committed
fixup! Add update boundary shape route
1 parent 4c8ab5c commit fea16bc

File tree

1 file changed

+11
-29
lines changed

1 file changed

+11
-29
lines changed

src/django/api/views/boundary.py

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -78,40 +78,22 @@ def post(self, request, id, format=None):
7878
boundary_set = boundary_set.prefetch_related('submissions')
7979
boundary = get_object_or_404(boundary_set, pk=id)
8080

81-
if boundary.status == BOUNDARY_STATUS.DRAFT:
82-
if request.user.role not in [Roles.CONTRIBUTOR, Roles.ADMINISTRATOR]:
83-
raise ForbiddenException(
84-
'Only contributors and administrators can edit only drafts.'
85-
)
86-
87-
shape = BoundaryShapeView.get_valid_shape(request.data)
88-
89-
boundary.latest_submission.shape = shape
90-
boundary.latest_submission.save()
91-
92-
elif boundary.status == BOUNDARY_STATUS.IN_REVIEW:
93-
if request.user.role not in [Roles.VALIDATOR, Roles.ADMINISTRATOR]:
94-
raise ForbiddenException(
95-
'Only validators and administrators can edit boundaries in review.'
96-
)
97-
98-
shape = BoundaryShapeView.get_valid_shape(request.data)
99-
100-
boundary.latest_submission.review.shape = shape
101-
boundary.latest_submission.review.save()
81+
if request.user.role not in [Roles.CONTRIBUTOR, Roles.ADMINISTRATOR]:
82+
raise ForbiddenException(
83+
'Only contributors and administrators can edit boundaries.'
84+
)
10285

103-
else:
104-
return BadRequestException(
86+
if boundary.status != BOUNDARY_STATUS.DRAFT:
87+
raise BadRequestException(
10588
'Cannot update shape of boundary with status: {}'.format(
10689
boundary.status
10790
),
10891
)
10992

110-
return Response()
111-
112-
@staticmethod
113-
def get_valid_shape(data):
114-
serializer = ShapeSerializer(data=data)
93+
serializer = ShapeSerializer(data=request.data)
11594
serializer.is_valid(raise_exception=True)
11695

117-
return serializer.validated_data
96+
boundary.latest_submission.shape = serializer.validated_data
97+
boundary.latest_submission.save()
98+
99+
return Response()

0 commit comments

Comments
 (0)