refactor: inbox issues (#1370)

* refactor: inbox issue endpoints

* dev: update inbox issues endpooint
This commit is contained in:
pablohashescobar 2023-06-23 13:30:52 +05:30 committed by GitHub
parent 71b2884b57
commit 37303e6cb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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(