Skip to content

Commit

Permalink
Add the initialize_tenants command
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Apr 23, 2024
1 parent 19d0efb commit 6165b88
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions tcms_tenants/management/commands/initialize_tenants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (c) 2024 Alexander Todorov <[email protected]>

# Licensed under the GPL 3.0: https://www.gnu.org/licenses/gpl-3.0.txt

import datetime

from django.contrib.auth import get_user_model
from django.core.management import call_command
from django.core.management.base import BaseCommand
from django.utils import timezone


class Command(BaseCommand):
help = "Initialize tenants for a *NEW* Kiwi TCMS Enterprise installation."

def add_arguments(self, parser):
parser.add_argument(
"--domain",
action="store",
dest="domain",
required=True,
help="The primary tenant domain",
)

def handle(self, *args, **kwargs):
superuser = get_user_model().objects.filter(is_superuser=True).first()
paid_until = timezone.now() + datetime.timedelta(days=100 * 365)
domain = kwargs["domain"]

call_command(
"create_tenant",
f"--verbosity={kwargs['verbosity']}",
"--schema_name",
"public",
"--name",
"Public tenant",
"--paid_until",
paid_until.isoformat(),
"--publicly_readable",
False,
"--owner_id",
superuser.pk,
"--organization",
"Testing department",
"--domain-domain",
domain,
"--domain-is_primary",
True,
)

# a special tenant to make cloning faster
call_command(
"create_tenant",
f"--verbosity={kwargs['verbosity']}",
"--schema_name",
"empty",
"--name",
"Cloning Template",
"--paid_until",
paid_until.isoformat(),
"--publicly_readable",
False,
"--owner_id",
superuser.pk,
"--organization",
"Kiwi TCMS",
"--domain-domain",
"empty.example.org",
"--domain-is_primary",
True,
)

0 comments on commit 6165b88

Please sign in to comment.