Skip to content

Commit

Permalink
Prevent removal of user's home facility (#974)
Browse files Browse the repository at this point in the history
Prevent deletion of user's home facility
  • Loading branch information
Ashesh3 authored Aug 11, 2022
1 parent 144302e commit f5271c3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions care/users/api/viewsets/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ def delete_facility(self, request, *args, **kwargs):
raise ValidationError({"facility": "Facility Access not Present"})
if not self.has_facility_permission(user, facility):
raise ValidationError({"facility": "Intended User Does not have permission to this facility"})
if user.home_facility == facility:
raise ValidationError({"facility": "Cannot Delete User's Home Facility"})
FacilityUser.objects.filter(facility=facility, user=user).delete()
return Response(status=status.HTTP_204_NO_CONTENT)

Expand Down

0 comments on commit f5271c3

Please sign in to comment.