Skip to content

Commit

Permalink
Allow Nurses to clear their home facility (#2206)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranshu1902 authored Jun 13, 2024
1 parent d49e4e1 commit cda75bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions care/facility/tests/test_unlink_district_admins.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,10 @@ def test_unlink_faciltity_admin_different_district(self):
)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(response.json()["detail"], "User not found")

def test_unlink_home_facility_by_nurse(self):
self.client.force_login(self.staff1)
response = self.client.delete(
f"/api/v1/users/{self.staff1.username}/clear_home_facility/"
)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
5 changes: 5 additions & 0 deletions care/users/api/viewsets/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ def clear_home_facility(self, request, *args, **kwargs):
if not user.home_facility:
raise ValidationError({"home_facility": "No Home Facility Present"})
if (
requesting_user.id == user.id
and requesting_user.user_type == User.TYPE_VALUE_MAP["Nurse"]
):
pass
elif (
requesting_user.user_type < User.TYPE_VALUE_MAP["DistrictAdmin"]
or requesting_user.user_type in User.READ_ONLY_TYPES
):
Expand Down

0 comments on commit cda75bb

Please sign in to comment.