fix: file asset uploads in workspace (#1234)

This commit is contained in:
pablohashescobar 2023-06-07 12:21:09 +05:30 committed by GitHub
parent c05eb9e240
commit 382a1343ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,7 @@ 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 from plane.db.models import FileAsset, Workspace
from plane.api.serializers import FileAssetSerializer from plane.api.serializers import FileAssetSerializer
@ -27,15 +27,13 @@ class FileAssetEndpoint(BaseAPIView):
try: try:
serializer = FileAssetSerializer(data=request.data) serializer = FileAssetSerializer(data=request.data)
if serializer.is_valid(): if serializer.is_valid():
if request.user.last_workspace_id is None: # Get the workspace
return Response( workspace = Workspace.objects.get(slug=slug)
{"error": "Workspace id is required"}, serializer.save(workspace_id=workspace.id)
status=status.HTTP_400_BAD_REQUEST,
)
serializer.save(workspace_id=request.user.last_workspace_id)
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)
except Workspace.DoesNotExist:
return Response({"error": "Workspace does not exist"}, status=status.HTTP_400_BAD_REQUEST)
except Exception as e: except Exception as e:
capture_exception(e) capture_exception(e)
return Response( return Response(