2017-11-16 00:55:49 +01:00
|
|
|
from typing import Any
|
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.lib.actions import bulk_add_subscriptions, do_create_realm, do_create_user
|
2017-08-29 22:47:52 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2019-02-23 23:38:54 +01:00
|
|
|
from zerver.lib.onboarding import send_initial_realm_messages
|
2017-08-29 22:47:52 +02:00
|
|
|
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 realm and initial user for manual testing of the onboarding process."""
|
|
|
|
|
2017-10-27 12:57:54 +02:00
|
|
|
def handle(self, **options: Any) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
string_id = "realm{:02}".format(Realm.objects.filter(string_id__startswith="realm").count())
|
2017-08-29 22:47:52 +02:00
|
|
|
realm = do_create_realm(string_id, string_id)
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
name = "{:02}-user".format(UserProfile.objects.filter(email__contains="user@").count())
|
2020-07-16 14:10:43 +02:00
|
|
|
user = do_create_user(
|
2021-02-12 08:20:45 +01:00
|
|
|
f"{name}@{string_id}.zulip.com",
|
|
|
|
"password",
|
2020-07-16 14:10:43 +02:00
|
|
|
realm,
|
|
|
|
name,
|
|
|
|
role=UserProfile.ROLE_REALM_ADMINISTRATOR,
|
|
|
|
acting_user=None,
|
|
|
|
)
|
2020-07-05 00:35:06 +02:00
|
|
|
assert realm.signup_notifications_stream is not None
|
2021-04-02 18:33:28 +02:00
|
|
|
bulk_add_subscriptions(realm, [realm.signup_notifications_stream], [user], acting_user=None)
|
2017-08-29 22:47:52 +02:00
|
|
|
|
|
|
|
send_initial_realm_messages(realm)
|