Skip to content

Commit

Permalink
Merge pull request #2543 from ohcnetwork/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad authored Oct 16, 2024
2 parents 8f3315b + 0fc5260 commit fac47f7
Show file tree
Hide file tree
Showing 11 changed files with 433 additions and 188 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
build-args: |
APP_VERSION=${{ github.sha }}
ADDITIONAL_PLUGS=${{ secrets.ADDITIONAL_PLUGS }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

Expand Down
16 changes: 16 additions & 0 deletions care/facility/api/viewsets/facility.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,19 @@ def get_serializer_context(self):
context = super().get_serializer_context()
context["facility"] = facility
return context


class FacilityHubsViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
queryset = FacilityHubSpoke.objects.all().select_related("spoke", "hub")
serializer_class = FacilitySpokeSerializer
permission_classes = (IsAuthenticated,)
lookup_field = "external_id"

def get_queryset(self):
return self.queryset.filter(spoke=self.get_facility())

def get_facility(self):
facilities = get_facility_queryset(self.request.user)
return get_object_or_404(
facilities.filter(external_id=self.kwargs["facility_external_id"])
)
19 changes: 19 additions & 0 deletions care/facility/tests/test_facility_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,25 @@ def test_spoke_is_not_ancestor(self):
)
self.assertIs(response.status_code, status.HTTP_400_BAD_REQUEST)

def test_hubs_list(self):
facility_a = self.create_facility(
self.super_user, self.district, self.local_body
)
facility_b = self.create_facility(
self.super_user, self.district, self.local_body
)

FacilityHubSpoke.objects.create(hub=facility_a, spoke=facility_b)

self.client.force_authenticate(user=self.super_user)
response = self.client.get(f"/api/v1/facility/{facility_b.external_id}/hubs/")
self.assertIs(response.status_code, status.HTTP_200_OK)
data = response.json()
self.assertEqual(data["count"], 1)
self.assertEqual(
data["results"][0]["hub_object"]["id"], str(facility_a.external_id)
)


class FacilityCoverImageTests(TestUtils, APITestCase):
@classmethod
Expand Down
7 changes: 7 additions & 0 deletions care/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ class UserAdmin(auth_admin.UserAdmin, ExportCsvMixin):
list_display = ["username", "is_superuser"]
search_fields = ["first_name", "last_name"]

def get_queryset(self, request):
# use the base manager to avoid filtering out soft deleted objects
qs = self.model._base_manager.get_queryset() # noqa: SLF001
if ordering := self.get_ordering(request):
qs = qs.order_by(*ordering)
return qs


@admin.register(State)
class StateAdmin(admin.ModelAdmin):
Expand Down
2 changes: 1 addition & 1 deletion care/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __str__(self):
class CustomUserManager(UserManager):
def get_queryset(self):
qs = super().get_queryset()
return qs.filter(deleted=False, is_active=True).select_related(
return qs.filter(deleted=False).select_related(
"local_body", "district", "state"
)

Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github_checks:
annotations: false
2 changes: 2 additions & 0 deletions config/api_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
)
from care.facility.api.viewsets.facility import (
AllFacilityViewSet,
FacilityHubsViewSet,
FacilitySpokesViewSet,
FacilityViewSet,
)
Expand Down Expand Up @@ -218,6 +219,7 @@
facility_nested_router.register(
r"spokes", FacilitySpokesViewSet, basename="facility-spokes"
)
facility_nested_router.register(r"hubs", FacilityHubsViewSet, basename="facility-hubs")

router.register("asset", AssetViewSet, basename="asset")
asset_nested_router = NestedSimpleRouter(router, r"asset", lookup="asset")
Expand Down
Loading

0 comments on commit fac47f7

Please sign in to comment.