Skip to content

Commit

Permalink
update: update NodesView
Browse files Browse the repository at this point in the history
  • Loading branch information
thepsalmist committed Oct 22, 2024
1 parent a2f06d8 commit 72e30ca
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions sensorsafrica/api/v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 72e30ca

Please sign in to comment.