From 377ab63989971ba611321417e044d96c5780ceb2 Mon Sep 17 00:00:00 2001 From: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com> Date: Wed, 29 Nov 2023 19:08:14 +0530 Subject: [PATCH] chore: v3 global issues (#2938) --- apiserver/plane/app/urls/views.py | 6 +++ apiserver/plane/app/views/__init__.py | 1 + apiserver/plane/app/views/view.py | 56 ++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/apiserver/plane/app/urls/views.py b/apiserver/plane/app/urls/views.py index 36372c03a..b2d8917b2 100644 --- a/apiserver/plane/app/urls/views.py +++ b/apiserver/plane/app/urls/views.py @@ -6,6 +6,7 @@ from plane.app.views import ( GlobalViewViewSet, GlobalViewIssuesViewSet, IssueViewFavoriteViewSet, + GlobalViewIssuesGroupedEndpoint ) @@ -63,6 +64,11 @@ urlpatterns = [ ), name="global-view-issues", ), + path( + "v3/workspaces//issues/", + GlobalViewIssuesGroupedEndpoint.as_view(), + name="global-view-issues", + ), path( "workspaces//projects//user-favorite-views/", IssueViewFavoriteViewSet.as_view( diff --git a/apiserver/plane/app/views/__init__.py b/apiserver/plane/app/views/__init__.py index 1f6e64a78..85d708a38 100644 --- a/apiserver/plane/app/views/__init__.py +++ b/apiserver/plane/app/views/__init__.py @@ -52,6 +52,7 @@ from .view import ( GlobalViewIssuesViewSet, IssueViewViewSet, IssueViewFavoriteViewSet, + GlobalViewIssuesGroupedEndpoint ) from .cycle import ( CycleViewSet, diff --git a/apiserver/plane/app/views/view.py b/apiserver/plane/app/views/view.py index 1fd1ccf76..56770a99d 100644 --- a/apiserver/plane/app/views/view.py +++ b/apiserver/plane/app/views/view.py @@ -20,7 +20,7 @@ from rest_framework.response import Response from rest_framework import status # Module imports -from . import BaseViewSet +from . import BaseViewSet, BaseAPIView from plane.app.serializers import ( GlobalViewSerializer, IssueViewSerializer, @@ -198,6 +198,60 @@ class GlobalViewIssuesViewSet(BaseViewSet): return Response(issues, status=status.HTTP_200_OK) +class GlobalViewIssuesGroupedEndpoint(BaseAPIView): + permission_classes = [ + WorkspaceEntityPermission, + ] + + def get(self, request, slug): + filters = issue_filters(request.query_params, "GET") + fields = [field for field in request.GET.get("fields", "").split(",") if field] + + issue_queryset = ( + Issue.issue_objects.annotate( + sub_issues_count=Issue.issue_objects.filter(parent=OuterRef("id")) + .order_by() + .annotate(count=Func(F("id"), function="Count")) + .values("count") + ) + .filter(workspace__slug=self.kwargs.get("slug")) + .filter(project__project_projectmember__member=self.request.user) + .filter(**filters) + .select_related("project") + .select_related("workspace") + .select_related("state") + .select_related("parent") + .prefetch_related("assignees") + .prefetch_related("labels") + .prefetch_related( + Prefetch( + "issue_reactions", + queryset=IssueReaction.objects.select_related("actor"), + ) + ) + .annotate(cycle_id=F("issue_cycle__cycle_id")) + .annotate(module_id=F("issue_module__module_id")) + .annotate( + link_count=IssueLink.objects.filter(issue=OuterRef("id")) + .order_by() + .annotate(count=Func(F("id"), function="Count")) + .values("count") + ) + .annotate( + attachment_count=IssueAttachment.objects.filter(issue=OuterRef("id")) + .order_by() + .annotate(count=Func(F("id"), function="Count")) + .values("count") + ) + ) + + issues = IssueLiteSerializer(issue_queryset, many=True, fields=fields if fields else None).data + issue_dict = {str(issue["id"]): issue for issue in issues} + return Response( + issue_dict, + status=status.HTTP_200_OK, + ) + class IssueViewViewSet(BaseViewSet): serializer_class = IssueViewSerializer model = IssueView