From be9eec11ddd2ea18fbc04b82d78d53824c5d3c8d Mon Sep 17 00:00:00 2001 From: gurusainath Date: Tue, 3 Dec 2024 14:39:53 +0530 Subject: [PATCH] chore: updating the workspace slug when we the delete the workspace --- apiserver/plane/app/views/workspace/base.py | 24 +++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/apiserver/plane/app/views/workspace/base.py b/apiserver/plane/app/views/workspace/base.py index 515a3479bb..38ef1b8753 100644 --- a/apiserver/plane/app/views/workspace/base.py +++ b/apiserver/plane/app/views/workspace/base.py @@ -41,6 +41,7 @@ from django.views.decorators.vary import vary_on_cookie from plane.utils.constants import RESTRICTED_WORKSPACE_SLUGS from plane.license.utils.instance_value import get_configuration_value + class WorkSpaceViewSet(BaseViewSet): model = Workspace serializer_class = WorkSpaceSerializer @@ -81,12 +82,12 @@ class WorkSpaceViewSet(BaseViewSet): def create(self, request): try: - DISABLE_WORKSPACE_CREATION, = get_configuration_value( + (DISABLE_WORKSPACE_CREATION,) = get_configuration_value( [ { "key": "DISABLE_WORKSPACE_CREATION", "default": os.environ.get("DISABLE_WORKSPACE_CREATION", "0"), - }, + } ] ) @@ -144,8 +145,23 @@ class WorkSpaceViewSet(BaseViewSet): return super().partial_update(request, *args, **kwargs) @allow_permission([ROLE.ADMIN], level="WORKSPACE") - def destroy(self, request, *args, **kwargs): - return super().destroy(request, *args, **kwargs) + def destroy(self, request, slug): + workspace = Workspace.objects.get(slug=slug) + if workspace is None: + return Response( + {"error": "Workspace not found"}, status=status.HTTP_404_NOT_FOUND + ) + + # Trash the workspace by appending the epoch and `trash` to the slug + epoch = int(timezone.now().timestamp()) + updated_workspace_slug = f"trash-{epoch}-{workspace.slug}" + if len(updated_workspace_slug) > 48: + updated_workspace_slug = updated_workspace_slug[:48] + + workspace.slug = updated_workspace_slug + workspace.save() + workspace.delete() + return Response(status=status.HTTP_204_NO_CONTENT) class UserWorkSpacesEndpoint(BaseAPIView):