Skip to content

Commit fac47f7

Browse files
Merge pull request #2543 from ohcnetwork/develop
2 parents 8f3315b + 0fc5260 commit fac47f7

File tree

11 files changed

+433
-188
lines changed

11 files changed

+433
-188
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ jobs:
102102
tags: ${{ steps.meta.outputs.tags }}
103103
build-args: |
104104
APP_VERSION=${{ github.sha }}
105+
ADDITIONAL_PLUGS=${{ secrets.ADDITIONAL_PLUGS }}
105106
cache-from: type=local,src=/tmp/.buildx-cache
106107
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
107108

care/facility/api/viewsets/facility.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,19 @@ def get_serializer_context(self):
204204
context = super().get_serializer_context()
205205
context["facility"] = facility
206206
return context
207+
208+
209+
class FacilityHubsViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
210+
queryset = FacilityHubSpoke.objects.all().select_related("spoke", "hub")
211+
serializer_class = FacilitySpokeSerializer
212+
permission_classes = (IsAuthenticated,)
213+
lookup_field = "external_id"
214+
215+
def get_queryset(self):
216+
return self.queryset.filter(spoke=self.get_facility())
217+
218+
def get_facility(self):
219+
facilities = get_facility_queryset(self.request.user)
220+
return get_object_or_404(
221+
facilities.filter(external_id=self.kwargs["facility_external_id"])
222+
)

care/facility/tests/test_facility_api.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,25 @@ def test_spoke_is_not_ancestor(self):
229229
)
230230
self.assertIs(response.status_code, status.HTTP_400_BAD_REQUEST)
231231

232+
def test_hubs_list(self):
233+
facility_a = self.create_facility(
234+
self.super_user, self.district, self.local_body
235+
)
236+
facility_b = self.create_facility(
237+
self.super_user, self.district, self.local_body
238+
)
239+
240+
FacilityHubSpoke.objects.create(hub=facility_a, spoke=facility_b)
241+
242+
self.client.force_authenticate(user=self.super_user)
243+
response = self.client.get(f"/api/v1/facility/{facility_b.external_id}/hubs/")
244+
self.assertIs(response.status_code, status.HTTP_200_OK)
245+
data = response.json()
246+
self.assertEqual(data["count"], 1)
247+
self.assertEqual(
248+
data["results"][0]["hub_object"]["id"], str(facility_a.external_id)
249+
)
250+
232251

233252
class FacilityCoverImageTests(TestUtils, APITestCase):
234253
@classmethod

care/users/admin.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ class UserAdmin(auth_admin.UserAdmin, ExportCsvMixin):
5858
list_display = ["username", "is_superuser"]
5959
search_fields = ["first_name", "last_name"]
6060

61+
def get_queryset(self, request):
62+
# use the base manager to avoid filtering out soft deleted objects
63+
qs = self.model._base_manager.get_queryset() # noqa: SLF001
64+
if ordering := self.get_ordering(request):
65+
qs = qs.order_by(*ordering)
66+
return qs
67+
6168

6269
@admin.register(State)
6370
class StateAdmin(admin.ModelAdmin):

care/users/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def __str__(self):
130130
class CustomUserManager(UserManager):
131131
def get_queryset(self):
132132
qs = super().get_queryset()
133-
return qs.filter(deleted=False, is_active=True).select_related(
133+
return qs.filter(deleted=False).select_related(
134134
"local_body", "district", "state"
135135
)
136136

codecov.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github_checks:
2+
annotations: false

config/api_router.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
)
3838
from care.facility.api.viewsets.facility import (
3939
AllFacilityViewSet,
40+
FacilityHubsViewSet,
4041
FacilitySpokesViewSet,
4142
FacilityViewSet,
4243
)
@@ -218,6 +219,7 @@
218219
facility_nested_router.register(
219220
r"spokes", FacilitySpokesViewSet, basename="facility-spokes"
220221
)
222+
facility_nested_router.register(r"hubs", FacilityHubsViewSet, basename="facility-hubs")
221223

222224
router.register("asset", AssetViewSet, basename="asset")
223225
asset_nested_router = NestedSimpleRouter(router, r"asset", lookup="asset")

0 commit comments

Comments
 (0)