Compare commits

...

1 Commits

Author SHA1 Message Date
pablohashescobar
9f633570a8 dev: create command to delete and rename workspaces 2024-07-03 18:01:18 +05:30
2 changed files with 75 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
# Django imports
from django.core.management import BaseCommand, CommandError
# Module imports
from plane.db.models import Workspace
class Command(BaseCommand):
help = "Delete the workspace with the given slug"
def handle(self, *args, **options):
try:
# Get the old and new slug from console
slug = input("Enter the slug of the workspace: ")
# raise error if email is not present
if not slug:
raise CommandError("Error: Slug is required")
# filter the user
workspace = Workspace.objects.filter(slug=slug).first()
# Raise error if the user is not present
if not workspace:
raise CommandError(
f"Error: Workspace with {slug} does not exists"
)
# Activate the user
workspace.delete()
self.stdout.write(
self.style.SUCCESS("Workspace deleted succesfully")
)
except Exception as e:
raise CommandError(f"Error: {e}")

View File

@@ -0,0 +1,39 @@
# Django imports
from django.core.management import BaseCommand, CommandError
# Module imports
from plane.db.models import Workspace
from plane.utils.constants import RESTRICTED_WORKSPACE_SLUGS
class Command(BaseCommand):
help = "Rename the workspace slug"
def handle(self, *args, **options):
# Get the old and new slug from console
old_slug = input("Enter the slug of the workspace: ")
new_slug = input("Enter the new slug of the workspace: ")
# raise error if email is not present
if not old_slug or not new_slug:
raise CommandError("Error: Old and new slugs are required")
# filter the user
workspace = Workspace.objects.filter(slug=old_slug).first()
# Raise error if the user is not present
if not workspace:
raise CommandError(
f"Error: Workspace with {old_slug} does not exists"
)
if new_slug in RESTRICTED_WORKSPACE_SLUGS:
raise CommandError(
f"Error: {new_slug} is a restricted workspace slug"
)
# Activate the user
workspace.slug = new_slug
workspace.save()
self.stdout.write(self.style.SUCCESS("Workspace renamed succesfully"))