From 8303406e0ed1fb7030107ad69cef5e3c6a9a9f06 Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Thu, 11 May 2023 20:13:43 +0530 Subject: [PATCH 1/2] fix: query params for analytics --- apiserver/plane/api/views/analytic.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/apiserver/plane/api/views/analytic.py b/apiserver/plane/api/views/analytic.py index d22eb35e868..3279507c68d 100644 --- a/apiserver/plane/api/views/analytic.py +++ b/apiserver/plane/api/views/analytic.py @@ -26,7 +26,7 @@ from plane.api.serializers import AnalyticViewSerializer from plane.utils.analytics_plot import build_graph_plot from plane.bgtasks.analytic_plot_export import analytic_export_task - +from plane.utils.issue_filters import issue_filters class AnalyticsEndpoint(BaseAPIView): permission_classes = [ @@ -44,19 +44,11 @@ def get(self, request, slug): status=status.HTTP_400_BAD_REQUEST, ) - project_ids = request.GET.getlist("project") - cycle_ids = request.GET.getlist("cycle") - module_ids = request.GET.getlist("module") segment = request.GET.get("segment", False) + filters = issue_filters(request.GET, "GET") - queryset = Issue.objects.filter(workspace__slug=slug) - if project_ids: - queryset = queryset.filter(project_id__in=project_ids) - if cycle_ids: - queryset = queryset.filter(issue_cycle__cycle_id__in=cycle_ids) - if module_ids: - queryset = queryset.filter(issue_module__module_id__in=module_ids) + queryset = Issue.objects.filter(workspace__slug=slug, **filters) total_issues = queryset.count() distribution = build_graph_plot( @@ -75,18 +67,18 @@ def get(self, request, slug): colors = ( State.objects.filter( - workspace__slug=slug, project_id__in=project_ids + workspace__slug=slug, project_id__in=filters.get("project__in") ).values(key, "color") - if project_ids + if filters.get("project__in", False) else State.objects.filter(workspace__slug=slug).values(key, "color") ) if x_axis in ["labels__name"] or segment in ["labels__name"]: colors = ( Label.objects.filter( - workspace__slug=slug, project_id__in=project_ids + workspace__slug=slug, project_id__in=filters.get("project__in") ).values("name", "color") - if project_ids + if filters.get("project__in", False) else Label.objects.filter(workspace__slug=slug).values( "name", "color" ) From dc2f9b6f81f85c9afc3c77131e7e1969fb8efeaa Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Thu, 11 May 2023 20:21:53 +0530 Subject: [PATCH 2/2] fix: default analytics filters --- apiserver/plane/api/views/analytic.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/apiserver/plane/api/views/analytic.py b/apiserver/plane/api/views/analytic.py index 3279507c68d..56cb08727ba 100644 --- a/apiserver/plane/api/views/analytic.py +++ b/apiserver/plane/api/views/analytic.py @@ -28,6 +28,7 @@ from plane.bgtasks.analytic_plot_export import analytic_export_task from plane.utils.issue_filters import issue_filters + class AnalyticsEndpoint(BaseAPIView): permission_classes = [ WorkSpaceAdminPermission, @@ -44,9 +45,8 @@ def get(self, request, slug): status=status.HTTP_400_BAD_REQUEST, ) - segment = request.GET.get("segment", False) - filters = issue_filters(request.GET, "GET") + filters = issue_filters(request.GET, "GET") queryset = Issue.objects.filter(workspace__slug=slug, **filters) @@ -205,18 +205,9 @@ class DefaultAnalyticsEndpoint(BaseAPIView): def get(self, request, slug): try: - queryset = Issue.objects.filter(workspace__slug=slug) - - project_ids = request.GET.getlist("project") - cycle_ids = request.GET.getlist("cycle") - module_ids = request.GET.getlist("module") - - if project_ids: - queryset = queryset.filter(project_id__in=project_ids) - if cycle_ids: - queryset = queryset.filter(issue_cycle__cycle_id__in=cycle_ids) - if module_ids: - queryset = queryset.filter(issue_module__module_id__in=module_ids) + filters = issue_filters(request.GET, "GET") + + queryset = Issue.objects.filter(workspace__slug=slug, **filters) total_issues = queryset.count()