chore: archive and draft issue description

This commit is contained in:
NarayanBavisetti 2024-06-14 13:30:38 +05:30
parent d8c4461497
commit fbfa536937
5 changed files with 119 additions and 6 deletions

View File

@ -20,6 +20,7 @@ from plane.app.views import (
IssueViewSet,
LabelViewSet,
IssueDescriptionViewSet,
ArchivedIssueDescriptionViewSet,
)
urlpatterns = [
@ -265,6 +266,16 @@ urlpatterns = [
),
name="project-issue-archive-unarchive",
),
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/archived-issues/<uuid:pk>/description/",
ArchivedIssueDescriptionViewSet.as_view(
{
"get": "retrieve",
"patch": "partial_update",
}
),
name="archived-issue-description",
),
## End Issue Archives
## Issue Relation
path(
@ -309,4 +320,14 @@ urlpatterns = [
),
name="project-issue-draft",
),
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-drafts/<uuid:pk>/description/",
IssueDraftViewSet.as_view(
{
"get": "retrieve",
"patch": "partial_update",
}
),
name="draft-issue-description",
),
]

View File

@ -114,9 +114,7 @@ from .issue.activity import (
IssueActivityEndpoint,
)
from .issue.archive import (
IssueArchiveViewSet,
)
from .issue.archive import IssueArchiveViewSet, ArchivedIssueDescriptionViewSet
from .issue.attachment import (
IssueAttachmentEndpoint,
@ -127,7 +125,7 @@ from .issue.comment import (
CommentReactionViewSet,
)
from .issue.draft import IssueDraftViewSet
from .issue.draft import IssueDraftViewSet, DraftIssueDescriptionViewSet
from .issue.label import (
LabelViewSet,

View File

@ -1,5 +1,6 @@
# Python imports
import json
import base64
# Django imports
from django.utils import timezone
@ -18,6 +19,7 @@ from django.db.models import (
UUIDField,
)
from django.core.serializers.json import DjangoJSONEncoder
from django.http import StreamingHttpResponse
from django.utils.decorators import method_decorator
from django.views.decorators.gzip import gzip_page
from django.contrib.postgres.aggregates import ArrayAgg
@ -351,3 +353,48 @@ class IssueArchiveViewSet(BaseViewSet):
issue.save()
return Response(status=status.HTTP_204_NO_CONTENT)
class ArchivedIssueDescriptionViewSet(BaseViewSet):
permission_classes = [
ProjectEntityPermission,
]
def retrieve(self, request, slug, project_id, pk):
issue = Issue.objects.get(
pk=pk, workspace__slug=slug, project_id=project_id
)
binary_data = issue.description_binary
def stream_data():
if binary_data:
yield binary_data
else:
yield b""
response = StreamingHttpResponse(
stream_data(), content_type="application/octet-stream"
)
response["Content-Disposition"] = (
'attachment; filename="issue_description.bin"'
)
return response
def partial_update(self, request, slug, project_id, pk):
issue = Issue.objects.get(
pk=pk, workspace__slug=slug, project_id=project_id
)
base64_data = request.data.get("description_binary")
if base64_data:
# Decode the base64 data to bytes
new_binary_data = base64.b64decode(base64_data)
# Store the updated binary data
issue.description_binary = new_binary_data
issue.description_html = request.data.get("description_html")
issue.save()
return Response({"message": "Updated successfully"})
else:
return Response({"error": "No binary data provided"})

View File

@ -682,7 +682,7 @@ class IssueDescriptionViewSet(BaseViewSet):
]
def retrieve(self, request, slug, project_id, pk):
issue = Issue.objects.get(
issue = Issue.issue_objects.get(
pk=pk, workspace__slug=slug, project_id=project_id
)
binary_data = issue.description_binary
@ -702,7 +702,7 @@ class IssueDescriptionViewSet(BaseViewSet):
return response
def partial_update(self, request, slug, project_id, pk):
issue = Issue.objects.get(
issue = Issue.issue_objects.get(
pk=pk, workspace__slug=slug, project_id=project_id
)

View File

@ -1,8 +1,10 @@
# Python imports
import json
import base64
# Django imports
from django.contrib.postgres.aggregates import ArrayAgg
from django.http import StreamingHttpResponse
from django.contrib.postgres.fields import ArrayField
from django.core.serializers.json import DjangoJSONEncoder
from django.db.models import (
@ -366,3 +368,48 @@ class IssueDraftViewSet(BaseViewSet):
origin=request.META.get("HTTP_ORIGIN"),
)
return Response(status=status.HTTP_204_NO_CONTENT)
class DraftIssueDescriptionViewSet(BaseViewSet):
permission_classes = [
ProjectEntityPermission,
]
def retrieve(self, request, slug, project_id, pk):
issue = Issue.objects.get(
pk=pk, workspace__slug=slug, project_id=project_id
)
binary_data = issue.description_binary
def stream_data():
if binary_data:
yield binary_data
else:
yield b""
response = StreamingHttpResponse(
stream_data(), content_type="application/octet-stream"
)
response["Content-Disposition"] = (
'attachment; filename="issue_description.bin"'
)
return response
def partial_update(self, request, slug, project_id, pk):
issue = Issue.objects.get(
pk=pk, workspace__slug=slug, project_id=project_id
)
base64_data = request.data.get("description_binary")
if base64_data:
# Decode the base64 data to bytes
new_binary_data = base64.b64decode(base64_data)
# Store the updated binary data
issue.description_binary = new_binary_data
issue.description_html = request.data.get("description_html")
issue.save()
return Response({"message": "Updated successfully"})
else:
return Response({"error": "No binary data provided"})