From 37303e6cb86a71e5ac7b94ed28ae7268f6967b29 Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Fri, 23 Jun 2023 13:30:52 +0530 Subject: [PATCH] refactor: inbox issues (#1370) * refactor: inbox issue endpoints * dev: update inbox issues endpooint --- apiserver/plane/api/views/inbox.py | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/apiserver/plane/api/views/inbox.py b/apiserver/plane/api/views/inbox.py index 0e4c1603e..f794db058 100644 --- a/apiserver/plane/api/views/inbox.py +++ b/apiserver/plane/api/views/inbox.py @@ -68,13 +68,12 @@ class InboxViewSet(BaseViewSet): inbox = Inbox.objects.get( workspace__slug=slug, project_id=project_id, pk=pk ) - + # Handle default inbox delete if inbox.is_default: return Response( {"error": "You cannot delete the default inbox"}, status=status.HTTP_400_BAD_REQUEST, ) - inbox.delete() return Response(status=status.HTTP_204_NO_CONTENT) except Exception as e: @@ -120,23 +119,17 @@ class InboxIssueViewSet(BaseViewSet): workspace__slug=slug, project_id=project_id, ) + .filter(**filters) + .order_by(order_by) + .annotate(bridge_id=F("issue_inbox__id")) + .select_related("workspace", "project", "state", "parent") + .prefetch_related("assignees", "labels") .annotate( sub_issues_count=Issue.issue_objects.filter(parent=OuterRef("id")) .order_by() .annotate(count=Func(F("id"), function="Count")) .values("count") ) - .annotate(bridge_id=F("issue_inbox__id")) - .filter(project_id=project_id) - .filter(workspace__slug=slug) - .select_related("project") - .select_related("workspace") - .select_related("state") - .select_related("parent") - .prefetch_related("assignees") - .prefetch_related("labels") - .order_by(order_by) - .filter(**filters) .annotate( link_count=IssueLink.objects.filter(issue=OuterRef("id")) .order_by() @@ -180,7 +173,8 @@ class InboxIssueViewSet(BaseViewSet): {"error": "Name is required"}, status=status.HTTP_400_BAD_REQUEST ) - if not request.data.get("issue", {}).get("priority", "low") in [ + # Check for valid priority + if not request.data.get("issue", {}).get("priority", None) in [ "low", "medium", "high", @@ -213,7 +207,6 @@ class InboxIssueViewSet(BaseViewSet): ) # Create an Issue Activity - # Track the issue issue_activity.delay( type="issue.activity.created", requested_data=json.dumps(request.data, cls=DjangoJSONEncoder), @@ -231,9 +224,7 @@ class InboxIssueViewSet(BaseViewSet): ) serializer = IssueStateInboxSerializer(issue) - return Response(serializer.data, status=status.HTTP_200_OK) - except Exception as e: capture_exception(e) return Response(