diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index baec75ebbb..ec0259c4a8 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -29,6 +29,10 @@ jobs: restore-keys: | ${{ runner.os }}-buildx- + - name: Create new cache + run: | + mkdir -p /tmp/.buildx-cache-new + - name: Bake docker images uses: docker/bake-action@v5 with: diff --git a/care/facility/api/viewsets/camera_preset.py b/care/facility/api/viewsets/camera_preset.py index bfb168834b..f6143d6291 100644 --- a/care/facility/api/viewsets/camera_preset.py +++ b/care/facility/api/viewsets/camera_preset.py @@ -38,7 +38,7 @@ def get_serializer_context(self): class CameraPresetViewSet(GenericViewSet, ListModelMixin): serializer_class = CameraPresetSerializer - queryset = CameraPreset.objects.all().select_related( + queryset = CameraPreset.objects.filter(asset_bed__deleted=False).select_related( "asset_bed", "created_by", "updated_by" ) lookup_field = "external_id" diff --git a/care/facility/api/viewsets/facility_users.py b/care/facility/api/viewsets/facility_users.py index ce4cf71c91..06cbab4732 100644 --- a/care/facility/api/viewsets/facility_users.py +++ b/care/facility/api/viewsets/facility_users.py @@ -40,6 +40,7 @@ def get_queryset(self): external_id=self.kwargs.get("facility_external_id"), ) queryset = facility.users.filter( + is_active=True, deleted=False, ).order_by("-last_login") return queryset.prefetch_related( diff --git a/care/facility/tests/test_assetbed_api.py b/care/facility/tests/test_assetbed_api.py index 2129ef1a00..2502c9bd0b 100644 --- a/care/facility/tests/test_assetbed_api.py +++ b/care/facility/tests/test_assetbed_api.py @@ -425,6 +425,42 @@ def setUpTestData(cls): def get_base_url(self, asset_bed_id=None): return f"/api/v1/assetbed/{asset_bed_id or self.asset_bed1.external_id}/camera_presets/" + def test_list_bed_with_deleted_assetbed(self): + res = self.client.post( + self.get_base_url(self.asset_bed1.external_id), + { + "name": "Preset with proper position", + "position": { + "x": 1.0, + "y": 1.0, + "zoom": 1.0, + }, + }, + format="json", + ) + self.assertEqual(res.status_code, status.HTTP_201_CREATED) + res = self.client.post( + self.get_base_url(self.asset_bed2.external_id), + { + "name": "Preset with proper position 2", + "position": { + "x": 1.0, + "y": 1.0, + "zoom": 1.0, + }, + }, + format="json", + ) + self.assertEqual(res.status_code, status.HTTP_201_CREATED) + + res = self.client.get(f"/api/v1/bed/{self.bed.external_id}/camera_presets/") + self.assertEqual(len(res.json()["results"]), 2) + + self.asset_bed1.delete() + self.asset_bed1.refresh_from_db() + res = self.client.get(f"/api/v1/bed/{self.bed.external_id}/camera_presets/") + self.assertEqual(len(res.json()["results"]), 1) + def test_create_camera_preset_without_position(self): res = self.client.post( self.get_base_url(), diff --git a/care/facility/tests/test_facilityuser_api.py b/care/facility/tests/test_facilityuser_api.py index 5958ee9f39..4c0903f61b 100644 --- a/care/facility/tests/test_facilityuser_api.py +++ b/care/facility/tests/test_facilityuser_api.py @@ -77,3 +77,26 @@ def test_user_access_to_facility_on_user_type(self): self.client.force_authenticate(user=district_lab_admin) response = self.client.get(f"/api/v1/facility/{self.facility.external_id}/") self.assertIs(response.status_code, status.HTTP_200_OK) + + def test_user_is_not_listed_if_deleted(self): + # Testing FE's delete functionality (soft delete/is_active is set to false when user is deleted) + response = self.client.get( + f"/api/v1/facility/{self.facility.external_id}/get_users/" + ) + response_json = response.json() + results = response_json["results"] + self.assertIs(response.status_code, status.HTTP_200_OK) + self.assertEqual(len(results), 2) + self.assertIn(self.super_user.username, [user["username"] for user in results]) + self.assertIn(self.user.username, [user["username"] for user in results]) + self.user.is_active = False + self.user.save() + response = self.client.get( + f"/api/v1/facility/{self.facility.external_id}/get_users/" + ) + response_json = response.json() + results = response_json["results"] + self.assertIs(response.status_code, status.HTTP_200_OK) + self.assertEqual(len(results), 1) + self.assertIn(self.super_user.username, [user["username"] for user in results]) + self.assertNotIn(self.user.username, [user["username"] for user in results])