Compare commits

...

3 Commits

Author SHA1 Message Date
NarayanBavisetti
0fe3dfddc6 fix: changed workspace id to slug 2023-11-13 14:36:07 +05:30
NarayanBavisetti
77b7d43042 fix: removed the local file changes 2023-11-13 12:53:08 +05:30
NarayanBavisetti
619b392b37 fix: file upload 2023-11-13 12:50:58 +05:30
4 changed files with 33 additions and 2 deletions

View File

@ -12,3 +12,14 @@ class FileAssetSerializer(BaseSerializer):
"created_at", "created_at",
"updated_at", "updated_at",
] ]
def to_representation(self, instance):
representation = super().to_representation(instance)
# Extract everything after the first slash in the asset field
asset_id = instance.asset.name.split('/', 1)[-1]
# Include only the asset id in the serialized data
representation['asset'] = asset_id
return representation

View File

@ -4,6 +4,7 @@ from django.urls import path
from plane.api.views import ( from plane.api.views import (
FileAssetEndpoint, FileAssetEndpoint,
UserAssetsEndpoint, UserAssetsEndpoint,
AssetsEndpoint,
) )
@ -18,6 +19,11 @@ urlpatterns = [
FileAssetEndpoint.as_view(), FileAssetEndpoint.as_view(),
name="file-assets", name="file-assets",
), ),
path(
"<str:slug>/<str:asset_key>/",
AssetsEndpoint.as_view(),
name="file-assets",
),
path( path(
"users/file-assets/", "users/file-assets/",
UserAssetsEndpoint.as_view(), UserAssetsEndpoint.as_view(),

View File

@ -67,7 +67,7 @@ from .cycle import (
CycleFavoriteViewSet, CycleFavoriteViewSet,
TransferCycleIssueEndpoint, TransferCycleIssueEndpoint,
) )
from .asset import FileAssetEndpoint, UserAssetsEndpoint from .asset import FileAssetEndpoint, UserAssetsEndpoint, AssetsEndpoint
from .issue import ( from .issue import (
IssueViewSet, IssueViewSet,
IssueListEndpoint, IssueListEndpoint,

View File

@ -1,13 +1,14 @@
# Third party imports # Third party imports
from rest_framework import status from rest_framework import status
from django.http import StreamingHttpResponse
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.parsers import MultiPartParser, FormParser from rest_framework.parsers import MultiPartParser, FormParser
from sentry_sdk import capture_exception
from django.conf import settings from django.conf import settings
# Module imports # Module imports
from .base import BaseAPIView from .base import BaseAPIView
from plane.db.models import FileAsset, Workspace from plane.db.models import FileAsset, Workspace
from plane.api.serializers import FileAssetSerializer from plane.api.serializers import FileAssetSerializer
from plane.api.permissions.workspace import WorkspaceEntityPermission
class FileAssetEndpoint(BaseAPIView): class FileAssetEndpoint(BaseAPIView):
@ -73,3 +74,16 @@ class UserAssetsEndpoint(BaseAPIView):
# Delete the file object # Delete the file object
file_asset.delete() file_asset.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
class AssetsEndpoint(BaseAPIView):
permission_classes = [WorkspaceEntityPermission]
parser_classes = (MultiPartParser, FormParser)
def get(self, request, slug, asset_key):
workspace = Workspace.objects.get(slug=slug)
asset_key = str(workspace.id) + "/" + asset_key
file_asset = FileAsset.objects.get(workspace_id=workspace.id, asset=asset_key)
response = StreamingHttpResponse(file_asset.asset.open(mode='rb'), content_type='application/octet-stream')
return response