From 1bc859c68c181bd886970cc01a80b6c79cf8f44e Mon Sep 17 00:00:00 2001 From: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com> Date: Sat, 25 Nov 2023 21:28:03 +0530 Subject: [PATCH] chore: seperated delete endpoint for file upload (#2870) --- apiserver/plane/app/urls/asset.py | 10 ++++++++++ apiserver/plane/app/views/__init__.py | 2 +- apiserver/plane/app/views/asset.py | 22 +++++++++++++++------- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/apiserver/plane/app/urls/asset.py b/apiserver/plane/app/urls/asset.py index 11ec8b8e8..2d84b93e0 100644 --- a/apiserver/plane/app/urls/asset.py +++ b/apiserver/plane/app/urls/asset.py @@ -4,6 +4,7 @@ from django.urls import path from plane.app.views import ( FileAssetEndpoint, UserAssetsEndpoint, + FileAssetViewSet, ) @@ -28,4 +29,13 @@ urlpatterns = [ UserAssetsEndpoint.as_view(), name="user-file-assets", ), + path( + "workspaces/file-assets///restore/", + FileAssetViewSet.as_view( + { + "post": "restore", + } + ), + name="file-assets-restore", + ), ] diff --git a/apiserver/plane/app/views/__init__.py b/apiserver/plane/app/views/__init__.py index ab81f99c9..1f6e64a78 100644 --- a/apiserver/plane/app/views/__init__.py +++ b/apiserver/plane/app/views/__init__.py @@ -61,7 +61,7 @@ from .cycle import ( TransferCycleIssueEndpoint, CycleIssueGroupedEndpoint, ) -from .asset import FileAssetEndpoint, UserAssetsEndpoint +from .asset import FileAssetEndpoint, UserAssetsEndpoint, FileAssetViewSet from .issue import ( IssueViewSet, IssueListEndpoint, diff --git a/apiserver/plane/app/views/asset.py b/apiserver/plane/app/views/asset.py index dc2827080..17d70d936 100644 --- a/apiserver/plane/app/views/asset.py +++ b/apiserver/plane/app/views/asset.py @@ -4,7 +4,7 @@ from rest_framework.response import Response from rest_framework.parsers import MultiPartParser, FormParser, JSONParser # Module imports -from .base import BaseAPIView +from .base import BaseAPIView, BaseViewSet from plane.db.models import FileAsset, Workspace from plane.app.serializers import FileAssetSerializer @@ -34,10 +34,20 @@ class FileAssetEndpoint(BaseAPIView): return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - def patch(self, request, workspace_id, asset_key): + def delete(self, request, workspace_id, asset_key): asset_key = str(workspace_id) + "/" + asset_key file_asset = FileAsset.objects.get(asset=asset_key) - file_asset.is_deleted = request.data.get("is_deleted", file_asset.is_deleted) + file_asset.is_deleted = True + file_asset.save() + return Response(status=status.HTTP_204_NO_CONTENT) + + +class FileAssetViewSet(BaseViewSet): + + def restore(self, request, workspace_id, asset_key): + asset_key = str(workspace_id) + "/" + asset_key + file_asset = FileAsset.objects.get(asset=asset_key) + file_asset.is_deleted = False file_asset.save() return Response(status=status.HTTP_204_NO_CONTENT) @@ -63,8 +73,6 @@ class UserAssetsEndpoint(BaseAPIView): def delete(self, request, asset_key): file_asset = FileAsset.objects.get(asset=asset_key, created_by=request.user) - # Delete the file from storage - file_asset.asset.delete(save=False) - # Delete the file object - file_asset.delete() + file_asset.is_deleted = True + file_asset.save() return Response(status=status.HTTP_204_NO_CONTENT)