Files
zulip/zilencer/management/commands/add_new_user.py
Steve Howell c44500175d database: Remove short_name from UserProfile.
A few major themes here:

    - We remove short_name from UserProfile
      and add the appropriate migration.

    - We remove short_name from various
      cache-related lists of fields.

    - We allow import tools to continue to
      write short_name to their export files,
      and then we simply ignore the field
      at import time.

    - We change functions like do_create_user,
      create_user_profile, etc.

    - We keep short_name in the /json/bots
      API.  (It actually gets turned into
      an email.)

    - We don't modify our LDAP code much
      here.
2020-07-17 11:15:15 -07:00

34 lines
1.4 KiB
Python

from typing import Any
from django.core.management.base import CommandParser
from zerver.lib.actions import do_create_user
from zerver.lib.management import ZulipBaseCommand
from zerver.models import Realm, UserProfile
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."""
def add_arguments(self, parser: CommandParser) -> None:
self.add_realm_args(parser)
def handle(self, **options: Any) -> None:
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'
'Try running `manage.py add_new_realm`, and then running this again.')
valid_realm = Realm.objects.get(string_id='zulip')
domain = 'zulip.com'
else:
valid_realm = realm
domain = realm.string_id + '.zulip.com'
name = '{:02}-user'.format(UserProfile.objects.filter(email__contains='user@').count())
do_create_user(f'{name}@{domain}', 'password', valid_realm, name, acting_user=None)