From 1e2c1cac9c0d9fc2ffeb0edfd2595d6a744fcd0a Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Fri, 16 Jun 2023 18:52:58 +0530 Subject: [PATCH] chore: project list endpoint to show is_member status (#1166) --- apiserver/plane/api/serializers/project.py | 1 + apiserver/plane/api/views/project.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/apiserver/plane/api/serializers/project.py b/apiserver/plane/api/serializers/project.py index 0a8ad1cf8..18ee19e7b 100644 --- a/apiserver/plane/api/serializers/project.py +++ b/apiserver/plane/api/serializers/project.py @@ -85,6 +85,7 @@ class ProjectDetailSerializer(BaseSerializer): total_members = serializers.IntegerField(read_only=True) total_cycles = serializers.IntegerField(read_only=True) total_modules = serializers.IntegerField(read_only=True) + is_member = serializers.BooleanField(read_only=True) class Meta: model = Project diff --git a/apiserver/plane/api/views/project.py b/apiserver/plane/api/views/project.py index bdb758ac9..e49c2fe78 100644 --- a/apiserver/plane/api/views/project.py +++ b/apiserver/plane/api/views/project.py @@ -72,6 +72,7 @@ class ProjectViewSet(BaseViewSet): project_id=OuterRef("pk"), workspace__slug=self.kwargs.get("slug"), ) + return self.filter_queryset( super() .get_queryset() @@ -81,6 +82,15 @@ class ProjectViewSet(BaseViewSet): "workspace", "workspace__owner", "default_assignee", "project_lead" ) .annotate(is_favorite=Exists(subquery)) + .annotate( + is_member=Exists( + ProjectMember.objects.filter( + member=self.request.user, + project_id=OuterRef("pk"), + workspace__slug=self.kwargs.get("slug"), + ) + ) + ) .distinct() )