From 070c2f90d7efef3515f4cfaa5601b83b1cb8ee17 Mon Sep 17 00:00:00 2001 From: Ishan Gujarathi Date: Thu, 29 Feb 2024 11:21:53 +0530 Subject: [PATCH] added an API endpoint for excluding the guest workspaces where the user is already a part off --- backend/workspaces/views.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/backend/workspaces/views.py b/backend/workspaces/views.py index b5527afd..7cc2bdcb 100644 --- a/backend/workspaces/views.py +++ b/backend/workspaces/views.py @@ -167,6 +167,25 @@ def list_guest_workspaces(self, request): {"message": "Error fetching guest workspaces."}, status=status.HTTP_500_INTERNAL_SERVER_ERROR, ) + + @action( + detail=False, + methods=["GET"], + name="Unauthenticated Guest Wroskapce", + url_path="list_unauthenticated_guest_workspaces", + ) + def list_unauthenticated_guest_workspaces(self,request): + try: + workspaces = Workspace.objects.filter(members__in=[request.user.pk]) + this_user_workspace_ids = workspaces.values_list('id',flat=True) + guest_workspaces = Workspace.objects.filter(guest_workspace=True).exclude(id__in = this_user_workspace_ids) + serializer = WorkspaceSerializer(guest_workspaces, many=True) + return Response(serializer.data, status = status.HTTP_200_OK) + except Exception as e: + return Response( + {"message": "Error Fetching guest workspace"}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR, + ) @action( detail=True, @@ -174,7 +193,7 @@ def list_guest_workspaces(self, request): name="Guest Authentication", url_path="guest_auth", serializer_class=WorkspacePasswordSerializer, - ) + ) def guest_auth(self, request, pk=None, *args, **kwargs): """ This endpoint is specifically designed for guest workspaces.