Compare commits

...

2 Commits

Author SHA1 Message Date
gurusainath f842b73227 chore: updated try catch 2024-12-03 14:56:28 +05:30
gurusainath be9eec11dd chore: updating the workspace slug when we the delete the workspace 2024-12-03 14:39:53 +05:30
+21 -4
View File
@@ -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,24 @@ 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):
try:
workspace = Workspace.objects.get(slug=slug)
except Workspace.DoesNotExist:
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):