From 42b524b16a5261f14e22f125b372e56b29c3edbb Mon Sep 17 00:00:00 2001 From: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com> Date: Thu, 14 Mar 2024 19:22:54 +0530 Subject: [PATCH] chore: project active filter (#3971) --- apiserver/plane/app/views/project.py | 38 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/apiserver/plane/app/views/project.py b/apiserver/plane/app/views/project.py index 6f9b2618e19..35d997d1544 100644 --- a/apiserver/plane/app/views/project.py +++ b/apiserver/plane/app/views/project.py @@ -88,7 +88,10 @@ def get_queryset(self): .get_queryset() .filter(workspace__slug=self.kwargs.get("slug")) .filter( - Q(project_projectmember__member=self.request.user) + Q( + project_projectmember__member=self.request.user, + project_projectmember__is_active=True, + ) | Q(network=2) ) .select_related( @@ -173,10 +176,7 @@ def list(self, request, slug): for field in request.GET.get("fields", "").split(",") if field ] - projects = ( - self.get_queryset() - .order_by("sort_order", "name") - ) + projects = self.get_queryset().order_by("sort_order", "name") if request.GET.get("per_page", False) and request.GET.get( "cursor", False ): @@ -576,9 +576,11 @@ def post(self, request, slug, project_id, pk): _ = WorkspaceMember.objects.create( workspace_id=project_invite.workspace_id, member=user, - role=15 - if project_invite.role >= 15 - else project_invite.role, + role=( + 15 + if project_invite.role >= 15 + else project_invite.role + ), ) else: # Else make him active @@ -685,9 +687,14 @@ def create(self, request, slug, project_id): ) bulk_project_members = [] - member_roles = {member.get("member_id"): member.get("role") for member in members} + member_roles = { + member.get("member_id"): member.get("role") for member in members + } # Update roles in the members array based on the member_roles dictionary - for project_member in ProjectMember.objects.filter(project_id=project_id, member_id__in=[member.get("member_id") for member in members]): + for project_member in ProjectMember.objects.filter( + project_id=project_id, + member_id__in=[member.get("member_id") for member in members], + ): project_member.role = member_roles[str(project_member.member_id)] project_member.is_active = True bulk_project_members.append(project_member) @@ -710,9 +717,9 @@ def create(self, request, slug, project_id): role=member.get("role", 10), project_id=project_id, workspace_id=project.workspace_id, - sort_order=sort_order[0] - 10000 - if len(sort_order) - else 65535, + sort_order=( + sort_order[0] - 10000 if len(sort_order) else 65535 + ), ) ) bulk_issue_props.append( @@ -733,7 +740,10 @@ def create(self, request, slug, project_id): bulk_issue_props, batch_size=10, ignore_conflicts=True ) - project_members = ProjectMember.objects.filter(project_id=project_id, member_id__in=[member.get("member_id") for member in members]) + project_members = ProjectMember.objects.filter( + project_id=project_id, + member_id__in=[member.get("member_id") for member in members], + ) serializer = ProjectMemberRoleSerializer(project_members, many=True) return Response(serializer.data, status=status.HTTP_201_CREATED)