From 72e30caab444c4d8ef3ca6dee59aafd5dd2bb059 Mon Sep 17 00:00:00 2001 From: Xavier Frankline Date: Tue, 22 Oct 2024 15:21:26 +0300 Subject: [PATCH] update: update NodesView --- sensorsafrica/api/v2/views.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sensorsafrica/api/v2/views.py b/sensorsafrica/api/v2/views.py index 5f57483..c9843eb 100644 --- a/sensorsafrica/api/v2/views.py +++ b/sensorsafrica/api/v2/views.py @@ -227,13 +227,20 @@ def list_nodes(self, request): def list_my_nodes(self, request): """List only the nodes owned by the authenticated user.""" if request.user.is_authenticated: - queryset = Node.objects.filter(owner=request.user) + queryset = Node.objects.filter( + Q(owner=request.user) + | Q( + owner__groups__name__in=[ + g.name for g in request.user.groups.all() + ] + ) + ) serializer = NodeSerializer(queryset, many=True) return Response(serializer.data) return Response({"detail": "Authentication credentials were not provided."}, status=403) - @action(detail=False, methods=["post"], url_path="create-node", url_name="create_node") - def create_node(self, request): + @action(detail=False, methods=["post"], url_path="register-node", url_name="register_node") + def register_node(self, request): serializer = NodeSerializer(data=request.data) if serializer.is_valid(): serializer.save()