Skip to content

Commit cda75bb

Browse files
authored
Allow Nurses to clear their home facility (#2206)
1 parent d49e4e1 commit cda75bb

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

care/facility/tests/test_unlink_district_admins.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,10 @@ def test_unlink_faciltity_admin_different_district(self):
7979
)
8080
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
8181
self.assertEqual(response.json()["detail"], "User not found")
82+
83+
def test_unlink_home_facility_by_nurse(self):
84+
self.client.force_login(self.staff1)
85+
response = self.client.delete(
86+
f"/api/v1/users/{self.staff1.username}/clear_home_facility/"
87+
)
88+
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

care/users/api/viewsets/users.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ def clear_home_facility(self, request, *args, **kwargs):
287287
if not user.home_facility:
288288
raise ValidationError({"home_facility": "No Home Facility Present"})
289289
if (
290+
requesting_user.id == user.id
291+
and requesting_user.user_type == User.TYPE_VALUE_MAP["Nurse"]
292+
):
293+
pass
294+
elif (
290295
requesting_user.user_type < User.TYPE_VALUE_MAP["DistrictAdmin"]
291296
or requesting_user.user_type in User.READ_ONLY_TYPES
292297
):

0 commit comments

Comments
 (0)