Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB-1017] chore: instance admin script #4210

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions apiserver/plane/db/management/commands/create_instance_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Django imports
from django.core.management.base import BaseCommand, CommandError

# Module imports
from plane.license.models import Instance, InstanceAdmin
from plane.db.models import User


class Command(BaseCommand):
help = "Add a new instance admin"

def add_arguments(self, parser):
# Positional argument
parser.add_argument(
"admin_email", type=str, help="Instance Admin Email"
)

def handle(self, *args, **options):

admin_email = options.get("admin_email", False)

if not admin_email:
raise CommandError("Please provide the email of the admin.")

user = User.objects.filter(email=admin_email).first()
if user is None:
raise CommandError("User with the provided email does not exist.")

try:
# Get the instance
instance = Instance.objects.last()

# Get or create an instance admin
_, created = InstanceAdmin.objects.get_or_create(
user=user, instance=instance, role=20
)

if not created:
raise CommandError(
"The provided email is already an instance admin."
)

self.stdout.write(
self.style.SUCCESS("Successfully created the admin")
)
except Exception as e:
print(e)
raise CommandError("Failed to create the instance admin.")
Loading