server_initialization: Use tos_version argument in create_users.

This commit is contained in:
Mateusz Mandera 2020-01-27 18:55:11 +01:00 committed by Tim Abbott
parent 261da5999d
commit d24936cbe3
3 changed files with 8 additions and 6 deletions

View File

@ -23,11 +23,11 @@ def create_internal_realm() -> None:
do_change_is_admin(email_gateway_bot, True, permission="api_super_user") do_change_is_admin(email_gateway_bot, True, permission="api_super_user")
def create_users(realm: Realm, name_list: Iterable[Tuple[str, str]], def create_users(realm: Realm, name_list: Iterable[Tuple[str, str]],
tos_version: Optional[str]=None,
bot_type: Optional[int]=None, bot_type: Optional[int]=None,
bot_owner: Optional[UserProfile]=None) -> None: bot_owner: Optional[UserProfile]=None) -> None:
user_set = set() # type: Set[Tuple[str, str, str, bool]] user_set = set() # type: Set[Tuple[str, str, str, bool]]
for full_name, email in name_list: for full_name, email in name_list:
short_name = email_to_username(email) short_name = email_to_username(email)
user_set.add((email, full_name, short_name, True)) user_set.add((email, full_name, short_name, True))
tos_version = settings.TOS_VERSION if bot_type is None else None
bulk_create_users(realm, user_set, bot_type=bot_type, bot_owner=bot_owner, tos_version=tos_version) bulk_create_users(realm, user_set, bot_type=bot_type, bot_owner=bot_owner, tos_version=tos_version)

View File

@ -11,12 +11,14 @@ from zerver.models import Realm, UserProfile, email_to_username, get_client, \
settings.TORNADO_SERVER = None settings.TORNADO_SERVER = None
def create_users(realm: Realm, name_list: Iterable[Tuple[str, str]], bot_type: Optional[int]=None) -> None: def create_users(realm: Realm, name_list: Iterable[Tuple[str, str]],
tos_version: Optional[str]=None,
bot_type: Optional[int]=None) -> None:
user_set = set() user_set = set()
for full_name, email in name_list: for full_name, email in name_list:
short_name = email_to_username(email) short_name = email_to_username(email)
user_set.add((email, full_name, short_name, True)) user_set.add((email, full_name, short_name, True))
bulk_create_users(realm, user_set, bot_type) bulk_create_users(realm, user_set, bot_type=bot_type, 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"

View File

@ -262,7 +262,7 @@ class Command(BaseCommand):
email = fname.lower() + '@zulip.com' email = fname.lower() + '@zulip.com'
names.append((full_name, email)) names.append((full_name, email))
create_users(zulip_realm, names) create_users(zulip_realm, names, tos_version=settings.TOS_VERSION)
iago = get_user("iago@zulip.com", zulip_realm) iago = get_user("iago@zulip.com", zulip_realm)
do_change_is_admin(iago, True) do_change_is_admin(iago, True)
@ -510,13 +510,13 @@ class Command(BaseCommand):
("Athena Consulting Exchange User (MIT)", "starnine@mit.edu"), ("Athena Consulting Exchange User (MIT)", "starnine@mit.edu"),
("Esp Classroom (MIT)", "espuser@mit.edu"), ("Esp Classroom (MIT)", "espuser@mit.edu"),
] ]
create_users(mit_realm, testsuite_mit_users) create_users(mit_realm, testsuite_mit_users, tos_version=settings.TOS_VERSION)
testsuite_lear_users = [ testsuite_lear_users = [
("King Lear", "king@lear.org"), ("King Lear", "king@lear.org"),
("Cordelia Lear", "cordelia@zulip.com"), ("Cordelia Lear", "cordelia@zulip.com"),
] ]
create_users(lear_realm, testsuite_lear_users) create_users(lear_realm, testsuite_lear_users, tos_version=settings.TOS_VERSION)
if not options["test_suite"]: if not options["test_suite"]:
# To keep the messages.json fixtures file for the test # To keep the messages.json fixtures file for the test