forked from github/plane
chore: seperated delete endpoint for file upload (#2870)
This commit is contained in:
parent
11d57a5bf0
commit
1bc859c68c
@ -4,6 +4,7 @@ from django.urls import path
|
|||||||
from plane.app.views import (
|
from plane.app.views import (
|
||||||
FileAssetEndpoint,
|
FileAssetEndpoint,
|
||||||
UserAssetsEndpoint,
|
UserAssetsEndpoint,
|
||||||
|
FileAssetViewSet,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -28,4 +29,13 @@ urlpatterns = [
|
|||||||
UserAssetsEndpoint.as_view(),
|
UserAssetsEndpoint.as_view(),
|
||||||
name="user-file-assets",
|
name="user-file-assets",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/file-assets/<uuid:workspace_id>/<str:asset_key>/restore/",
|
||||||
|
FileAssetViewSet.as_view(
|
||||||
|
{
|
||||||
|
"post": "restore",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="file-assets-restore",
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
@ -61,7 +61,7 @@ from .cycle import (
|
|||||||
TransferCycleIssueEndpoint,
|
TransferCycleIssueEndpoint,
|
||||||
CycleIssueGroupedEndpoint,
|
CycleIssueGroupedEndpoint,
|
||||||
)
|
)
|
||||||
from .asset import FileAssetEndpoint, UserAssetsEndpoint
|
from .asset import FileAssetEndpoint, UserAssetsEndpoint, FileAssetViewSet
|
||||||
from .issue import (
|
from .issue import (
|
||||||
IssueViewSet,
|
IssueViewSet,
|
||||||
IssueListEndpoint,
|
IssueListEndpoint,
|
||||||
|
@ -4,7 +4,7 @@ from rest_framework.response import Response
|
|||||||
from rest_framework.parsers import MultiPartParser, FormParser, JSONParser
|
from rest_framework.parsers import MultiPartParser, FormParser, JSONParser
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from .base import BaseAPIView
|
from .base import BaseAPIView, BaseViewSet
|
||||||
from plane.db.models import FileAsset, Workspace
|
from plane.db.models import FileAsset, Workspace
|
||||||
from plane.app.serializers import FileAssetSerializer
|
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.data, status=status.HTTP_201_CREATED)
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
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
|
asset_key = str(workspace_id) + "/" + asset_key
|
||||||
file_asset = FileAsset.objects.get(asset=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()
|
file_asset.save()
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
@ -63,8 +73,6 @@ class UserAssetsEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
def delete(self, request, asset_key):
|
def delete(self, request, asset_key):
|
||||||
file_asset = FileAsset.objects.get(asset=asset_key, created_by=request.user)
|
file_asset = FileAsset.objects.get(asset=asset_key, created_by=request.user)
|
||||||
# Delete the file from storage
|
file_asset.is_deleted = True
|
||||||
file_asset.asset.delete(save=False)
|
file_asset.save()
|
||||||
# Delete the file object
|
|
||||||
file_asset.delete()
|
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
Loading…
Reference in New Issue
Block a user