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)
|
|
|
|
|
2017-10-27 12:57:54 +02:00
|
|
|
def handle(self, **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 = (
|
|
|
|
Realm.objects.filter(string_id__startswith='realm').order_by('-string_id').first()
|
|
|
|
)
|
2017-08-29 22:47:52 +02:00
|
|
|
if realm is None:
|
2021-02-12 08:19:30 +01:00
|
|
|
print(
|
|
|
|
'Warning: Using default zulip realm, which has an unusual configuration.\n'
|
|
|
|
'Try running `manage.py add_new_realm`, and then running this again.'
|
|
|
|
)
|
2017-12-24 20:44:56 +01:00
|
|
|
valid_realm = Realm.objects.get(string_id='zulip')
|
2017-08-29 22:47:52 +02:00
|
|
|
domain = 'zulip.com'
|
|
|
|
else:
|
2017-12-24 20:44:56 +01:00
|
|
|
valid_realm = realm
|
2017-08-29 22:47:52 +02:00
|
|
|
domain = realm.string_id + '.zulip.com'
|
|
|
|
|
2020-06-13 08:59:37 +02:00
|
|
|
name = '{:02}-user'.format(UserProfile.objects.filter(email__contains='user@').count())
|
2020-07-16 14:10:43 +02:00
|
|
|
do_create_user(f'{name}@{domain}', 'password', valid_realm, name, acting_user=None)
|