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:
|
|
|
|
realm = Realm.objects.filter(string_id__startswith='realm') \
|
|
|
|
.order_by('-string_id').first()
|
|
|
|
if realm is None:
|
|
|
|
print('Warning: Using default zulip realm, which has an unusual configuration.\n'
|
2018-11-06 22:27:57 +01:00
|
|
|
'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'
|
|
|
|
|
|
|
|
name = '%02d-user' % (UserProfile.objects.filter(email__contains='user@').count(),)
|
2017-12-24 20:44:56 +01:00
|
|
|
do_create_user('%s@%s' % (name, domain), 'password', valid_realm, name, name)
|