2017-11-16 00:55:49 +01:00
|
|
|
from typing import Any
|
|
|
|
|
2017-11-02 12:39:10 +01:00
|
|
|
from django.core.management.base import CommandParser
|
2017-11-16 00:55:49 +01:00
|
|
|
|
2017-08-29 22:47:52 +02:00
|
|
|
from zerver.lib.actions import do_create_user
|
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
|
|
|
from zerver.models import Realm, UserProfile
|
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2017-08-29 22:47:52 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
|
|
|
help = """Add a new user for manual testing of the onboarding process.
|
|
|
|
If realm is unspecified, will try to use a realm created by add_new_realm,
|
|
|
|
and will otherwise fall back to the zulip realm."""
|
|
|
|
|
2017-10-27 12:57:54 +02:00
|
|
|
def add_arguments(self, parser: CommandParser) -> None:
|
2017-08-29 22:47:52 +02:00
|
|
|
self.add_realm_args(parser)
|
|
|
|
|
2021-08-14 16:51:57 +02:00
|
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
2017-08-29 22:47:52 +02:00
|
|
|
realm = self.get_realm(options)
|
|
|
|
if realm is None:
|
2021-02-12 08:19:30 +01:00
|
|
|
realm = (
|
2021-02-12 08:20:45 +01:00
|
|
|
Realm.objects.filter(string_id__startswith="realm").order_by("-string_id").first()
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2017-08-29 22:47:52 +02:00
|
|
|
if realm is None:
|
2021-02-12 08:19:30 +01:00
|
|
|
print(
|
2021-02-12 08:20:45 +01:00
|
|
|
"Warning: Using default zulip realm, which has an unusual configuration.\n"
|
|
|
|
"Try running `manage.py add_new_realm`, and then running this again."
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
valid_realm = Realm.objects.get(string_id="zulip")
|
|
|
|
domain = "zulip.com"
|
2017-08-29 22:47:52 +02:00
|
|
|
else:
|
2017-12-24 20:44:56 +01:00
|
|
|
valid_realm = realm
|
2021-02-12 08:20:45 +01:00
|
|
|
domain = realm.string_id + ".zulip.com"
|
2017-08-29 22:47:52 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
name = "{:02}-user".format(UserProfile.objects.filter(email__contains="user@").count())
|
|
|
|
do_create_user(f"{name}@{domain}", "password", valid_realm, name, acting_user=None)
|