From 0d0936904057c03877e041b2b3ead25f5b1cbe54 Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Wed, 10 Aug 2022 18:41:35 +0530 Subject: [PATCH] Prevent deletion of user's home facility --- care/users/api/viewsets/users.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/care/users/api/viewsets/users.py b/care/users/api/viewsets/users.py index f450072eb5..e60171c6e8 100644 --- a/care/users/api/viewsets/users.py +++ b/care/users/api/viewsets/users.py @@ -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)