initialize_voyager_db: Deduplicate create_users.

zerver.lib.server_initialization.create_users has precisely the same
code (you can copy-and-paste swap them without generating any diff) so
they can be trivially deduplicated.
This commit is contained in:
Mateusz Mandera 2020-01-28 15:11:06 +01:00 committed by Tim Abbott
parent 68abddb534
commit c5662d5fa3
1 changed files with 3 additions and 13 deletions

View File

@ -1,26 +1,16 @@
from argparse import ArgumentParser from argparse import ArgumentParser
from typing import Any, Iterable, Optional, Tuple from typing import Any
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from zerver.lib.actions import do_change_is_admin from zerver.lib.actions import do_change_is_admin
from zerver.lib.bulk_create import bulk_create_users from zerver.lib.server_initialization import create_users
from zerver.models import Realm, UserProfile, email_to_username, get_client, \ from zerver.models import Realm, UserProfile, get_client, \
get_system_bot get_system_bot
settings.TORNADO_SERVER = None settings.TORNADO_SERVER = None
def create_users(realm: Realm, name_list: Iterable[Tuple[str, str]],
tos_version: Optional[str]=None,
bot_type: Optional[int]=None,
bot_owner: Optional[UserProfile]=None) -> None:
user_set = set()
for full_name, email in name_list:
short_name = email_to_username(email)
user_set.add((email, full_name, short_name, True))
bulk_create_users(realm, user_set, bot_type=bot_type, bot_owner=bot_owner, tos_version=tos_version)
class Command(BaseCommand): class Command(BaseCommand):
help = "Populate an initial database for Zulip Voyager" help = "Populate an initial database for Zulip Voyager"