diff --git a/apiserver/plane/api/views/asset.py b/apiserver/plane/api/views/asset.py index 26fc8e936..0b935a4d3 100644 --- a/apiserver/plane/api/views/asset.py +++ b/apiserver/plane/api/views/asset.py @@ -6,7 +6,7 @@ from sentry_sdk import capture_exception from django.conf import settings # Module imports from .base import BaseAPIView -from plane.db.models import FileAsset +from plane.db.models import FileAsset, Workspace from plane.api.serializers import FileAssetSerializer @@ -27,15 +27,13 @@ class FileAssetEndpoint(BaseAPIView): try: serializer = FileAssetSerializer(data=request.data) if serializer.is_valid(): - if request.user.last_workspace_id is None: - return Response( - {"error": "Workspace id is required"}, - status=status.HTTP_400_BAD_REQUEST, - ) - - serializer.save(workspace_id=request.user.last_workspace_id) + # Get the workspace + workspace = Workspace.objects.get(slug=slug) + serializer.save(workspace_id=workspace.id) return Response(serializer.data, status=status.HTTP_201_CREATED) 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: capture_exception(e) return Response(