From c44500175d81de7b175db3d6d1afef789c527a3d Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 16 Jul 2020 12:10:43 +0000 Subject: [PATCH] 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. --- .../commands/populate_analytics_db.py | 10 +++++-- analytics/tests/test_counts.py | 30 +++++++++++-------- corporate/tests/test_stripe.py | 2 +- tools/generate-integration-docs-screenshot | 1 - tools/test-api | 8 +++-- zerver/data_import/gitter.py | 6 +++- zerver/data_import/import_util.py | 8 ++++- zerver/data_import/slack.py | 1 - zerver/lib/actions.py | 9 ++---- zerver/lib/bulk_create.py | 6 ++-- zerver/lib/cache.py | 5 ++-- zerver/lib/create_user.py | 29 +++++++++++++----- zerver/lib/import_realm.py | 8 +++-- zerver/lib/server_initialization.py | 5 ++-- zerver/management/commands/create_user.py | 9 ++++-- .../0296_remove_userprofile_short_name.py | 17 +++++++++++ zerver/models.py | 9 ++---- zerver/tests/test_audit_log.py | 2 +- zerver/tests/test_auth_backends.py | 2 +- zerver/tests/test_digest.py | 9 ++++-- zerver/tests/test_events.py | 9 ++++-- zerver/tests/test_home.py | 2 -- zerver/tests/test_hotspots.py | 6 +++- zerver/tests/test_import_export.py | 1 - zerver/tests/test_management_commands.py | 2 +- zerver/tests/test_markdown.py | 13 ++++---- zerver/tests/test_message_send.py | 4 --- zerver/tests/test_outgoing_webhook_system.py | 1 - zerver/tests/test_realm_emoji.py | 11 +++---- zerver/tests/test_service_bot_system.py | 5 ---- zerver/tests/test_signup.py | 7 +---- zerver/tests/test_slack_importer.py | 1 - zerver/tests/test_users.py | 3 -- zerver/views/registration.py | 4 +-- zerver/views/users.py | 5 +--- .../commands/add_mock_conversation.py | 6 ++-- zilencer/management/commands/add_new_realm.py | 10 +++++-- zilencer/management/commands/add_new_user.py | 2 +- zproject/backends.py | 2 +- 39 files changed, 156 insertions(+), 114 deletions(-) create mode 100644 zerver/migrations/0296_remove_userprofile_short_name.py diff --git a/analytics/management/commands/populate_analytics_db.py b/analytics/management/commands/populate_analytics_db.py index dfc9afbd6b..4c9e83570b 100644 --- a/analytics/management/commands/populate_analytics_db.py +++ b/analytics/management/commands/populate_analytics_db.py @@ -61,9 +61,13 @@ class Command(BaseCommand): realm = Realm.objects.create( string_id='analytics', name='Analytics', date_created=installation_time) with mock.patch("zerver.lib.create_user.timezone_now", return_value=installation_time): - shylock = create_user('shylock@analytics.ds', 'Shylock', realm, - full_name='Shylock', short_name='shylock', - role=UserProfile.ROLE_REALM_ADMINISTRATOR) + shylock = create_user( + 'shylock@analytics.ds', + 'Shylock', + realm, + full_name='Shylock', + role=UserProfile.ROLE_REALM_ADMINISTRATOR + ) do_change_user_role(shylock, UserProfile.ROLE_REALM_ADMINISTRATOR, acting_user=None) stream = Stream.objects.create( name='all', realm=realm, date_created=installation_time) diff --git a/analytics/tests/test_counts.py b/analytics/tests/test_counts.py index 6822ef2da1..f911891d06 100644 --- a/analytics/tests/test_counts.py +++ b/analytics/tests/test_counts.py @@ -89,7 +89,6 @@ class AnalyticsTestCase(ZulipTestCase): 'email': f'user{self.name_counter}@domain.tld', 'date_joined': self.TIME_LAST_HOUR, 'full_name': 'full_name', - 'short_name': 'short_name', 'is_active': True, 'is_bot': False, 'realm': self.default_realm} @@ -101,10 +100,15 @@ class AnalyticsTestCase(ZulipTestCase): if kwargs['is_bot']: pass_kwargs['bot_type'] = UserProfile.DEFAULT_BOT pass_kwargs['bot_owner'] = None - return create_user(kwargs['email'], 'password', kwargs['realm'], - active=kwargs['is_active'], - full_name=kwargs['full_name'], short_name=kwargs['short_name'], - role=UserProfile.ROLE_REALM_ADMINISTRATOR, **pass_kwargs) + return create_user( + kwargs['email'], + 'password', + kwargs['realm'], + active=kwargs['is_active'], + full_name=kwargs['full_name'], + role=UserProfile.ROLE_REALM_ADMINISTRATOR, + **pass_kwargs + ) def create_stream_with_recipient(self, **kwargs: Any) -> Tuple[Stream, Recipient]: self.name_counter += 1 @@ -1099,7 +1103,7 @@ class TestLoggingCountStats(AnalyticsTestCase): def test_active_users_log_by_is_bot(self) -> None: property = 'active_users_log:is_bot:day' - user = do_create_user('email', 'password', self.default_realm, 'full_name', 'short_name') + user = do_create_user('email', 'password', self.default_realm, 'full_name') self.assertEqual(1, RealmCount.objects.filter(property=property, subgroup=False) .aggregate(Sum('value'))['value__sum']) do_deactivate_user(user) @@ -1363,10 +1367,10 @@ class TestActiveUsersAudit(AnalyticsTestCase): [[user1, 'false'], [user2, 'false']]) def test_end_to_end_with_actions_dot_py(self) -> None: - user1 = do_create_user('email1', 'password', self.default_realm, 'full_name', 'short_name') - user2 = do_create_user('email2', 'password', self.default_realm, 'full_name', 'short_name') - user3 = do_create_user('email3', 'password', self.default_realm, 'full_name', 'short_name') - user4 = do_create_user('email4', 'password', self.default_realm, 'full_name', 'short_name') + user1 = do_create_user('email1', 'password', self.default_realm, 'full_name') + user2 = do_create_user('email2', 'password', self.default_realm, 'full_name') + user3 = do_create_user('email3', 'password', self.default_realm, 'full_name') + user4 = do_create_user('email4', 'password', self.default_realm, 'full_name') do_deactivate_user(user2) do_activate_user(user3) do_reactivate_user(user4) @@ -1458,9 +1462,9 @@ class TestRealmActiveHumans(AnalyticsTestCase): [2, second_realm, self.TIME_ZERO - self.DAY]]) def test_end_to_end(self) -> None: - user1 = do_create_user('email1', 'password', self.default_realm, 'full_name', 'short_name') - user2 = do_create_user('email2', 'password', self.default_realm, 'full_name', 'short_name') - do_create_user('email3', 'password', self.default_realm, 'full_name', 'short_name') + user1 = do_create_user('email1', 'password', self.default_realm, 'full_name') + user2 = do_create_user('email2', 'password', self.default_realm, 'full_name') + do_create_user('email3', 'password', self.default_realm, 'full_name') time_zero = floor_to_day(timezone_now()) + self.DAY update_user_activity_interval(user1, time_zero) update_user_activity_interval(user2, time_zero) diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 107a07d453..9d00f36870 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -2084,7 +2084,7 @@ class LicenseLedgerTest(StripeTestCase): def test_user_changes(self) -> None: self.local_upgrade(self.seat_count, True, CustomerPlan.ANNUAL, 'token') - user = do_create_user('email', 'password', get_realm('zulip'), 'name', 'name') + user = do_create_user('email', 'password', get_realm('zulip'), 'name') do_deactivate_user(user) do_reactivate_user(user) # Not a proper use of do_activate_user, but fine for this test diff --git a/tools/generate-integration-docs-screenshot b/tools/generate-integration-docs-screenshot index 7c06334d65..1c3e5d12e8 100755 --- a/tools/generate-integration-docs-screenshot +++ b/tools/generate-integration-docs-screenshot @@ -67,7 +67,6 @@ def create_integration_bot(integration: WebhookIntegration, bot_name: Optional[s password="123", realm=owner.realm, full_name=bot_name, - short_name=bot_name, bot_type=UserProfile.INCOMING_WEBHOOK_BOT, bot_owner=owner, acting_user=owner, diff --git a/tools/test-api b/tools/test-api index ef61dbbc56..9b4b2192ab 100755 --- a/tools/test-api +++ b/tools/test-api @@ -68,8 +68,12 @@ with test_server_running(force=options.force, external_host='zulipdev.com:9981') # Prepare the non-admin client email = 'guest@zulip.com' # guest is not an admin - guest_user = do_create_user('guest@zulip.com', 'secret', - get_realm('zulip'), 'Mr. Guest', 'guest') + guest_user = do_create_user( + 'guest@zulip.com', + 'secret', + get_realm('zulip'), + 'Mr. Guest', + ) api_key = get_api_key(guest_user) nonadmin_client = Client( email=email, diff --git a/zerver/data_import/gitter.py b/zerver/data_import/gitter.py index c407985cf9..0ca081c3fc 100644 --- a/zerver/data_import/gitter.py +++ b/zerver/data_import/gitter.py @@ -89,7 +89,6 @@ def build_userprofile(timestamp: Any, domain_name: str, # Build userprofile object userprofile = UserProfile( full_name=user_data['displayName'], - short_name=user_data['username'], id=user_id, email=email, delivery_email=email, @@ -100,6 +99,11 @@ def build_userprofile(timestamp: Any, domain_name: str, # Set realm id separately as the corresponding realm is not yet a Realm model # instance userprofile_dict['realm'] = realm_id + + # We use this later, even though Zulip doesn't + # support short_name + userprofile_dict['short_name'] = user_data['username'] + zerver_userprofile.append(userprofile_dict) user_id += 1 logging.info('######### IMPORTING USERS FINISHED #########\n') diff --git a/zerver/data_import/import_util.py b/zerver/data_import/import_util.py index 1352e48565..df1e00e62c 100644 --- a/zerver/data_import/import_util.py +++ b/zerver/data_import/import_util.py @@ -99,10 +99,16 @@ def build_user_profile(avatar_source: str, is_active=is_active, role=role, realm_id=realm_id, - short_name=short_name, timezone=timezone, ) dct = model_to_dict(obj) + + ''' + Even though short_name is no longer in the Zulip + UserProfile, it's helpful to have it in our import + dictionaries for legacy reasons. + ''' + dct['short_name'] = short_name return dct def build_avatar(zulip_user_id: int, realm_id: int, email: str, avatar_url: str, diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py index 5cf2186f73..56736e5507 100755 --- a/zerver/data_import/slack.py +++ b/zerver/data_import/slack.py @@ -206,7 +206,6 @@ def users_to_zerver_userprofile(slack_data_dir: str, users: List[ZerverFieldsT], userprofile = UserProfile( full_name=get_user_full_name(user), - short_name=user['name'], is_active=not user.get('deleted', False) and not user["is_mirror_dummy"], is_mirror_dummy=user["is_mirror_dummy"], id=user_id, diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 43e062224d..790aa40552 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -209,7 +209,6 @@ from zerver.models import ( active_non_guest_user_ids, active_user_ids, custom_profile_fields_for_realm, - email_to_username, filter_to_valid_prereg_users, get_active_streams, get_bot_dicts_in_realm, @@ -566,12 +565,11 @@ def notify_created_bot(user_profile: UserProfile) -> None: def create_users(realm: Realm, name_list: Iterable[Tuple[str, str]], bot_type: Optional[int]=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)) + user_set.add((email, full_name, True)) bulk_create_users(realm, user_set, bot_type) def do_create_user(email: str, password: Optional[str], realm: Realm, full_name: str, - short_name: str, bot_type: Optional[int]=None, role: Optional[int]=None, + bot_type: Optional[int]=None, role: Optional[int]=None, bot_owner: Optional[UserProfile]=None, tos_version: Optional[str]=None, timezone: str="", avatar_source: str=UserProfile.AVATAR_FROM_GRAVATAR, default_sending_stream: Optional[Stream]=None, @@ -585,7 +583,7 @@ def do_create_user(email: str, password: Optional[str], realm: Realm, full_name: acting_user: Optional[UserProfile]=None) -> UserProfile: user_profile = create_user(email=email, password=password, realm=realm, - full_name=full_name, short_name=short_name, + full_name=full_name, role=role, bot_type=bot_type, bot_owner=bot_owner, tos_version=tos_version, timezone=timezone, avatar_source=avatar_source, default_sending_stream=default_sending_stream, @@ -1044,7 +1042,6 @@ def create_mirror_user_if_needed(realm: Realm, email: str, password=None, realm=realm, full_name=email_to_fullname(email), - short_name=email_to_username(email), active=False, is_mirror_dummy=True, ) diff --git a/zerver/lib/bulk_create.py b/zerver/lib/bulk_create.py index c988197827..eb37044502 100644 --- a/zerver/lib/bulk_create.py +++ b/zerver/lib/bulk_create.py @@ -9,7 +9,7 @@ from zerver.models import Realm, RealmAuditLog, Recipient, Stream, Subscription, def bulk_create_users(realm: Realm, - users_raw: Set[Tuple[str, str, str, bool]], + users_raw: Set[Tuple[str, str, bool]], bot_type: Optional[int]=None, bot_owner: Optional[UserProfile]=None, tos_version: Optional[str]=None, @@ -24,10 +24,10 @@ def bulk_create_users(realm: Realm, # Now create user_profiles profiles_to_create: List[UserProfile] = [] - for (email, full_name, short_name, active) in users: + for (email, full_name, active) in users: profile = create_user_profile(realm, email, initial_password(email), active, bot_type, - full_name, short_name, bot_owner, False, tos_version, + full_name, bot_owner, False, tos_version, timezone, tutorial_status=UserProfile.TUTORIAL_FINISHED, enter_sends=True) profiles_to_create.append(profile) diff --git a/zerver/lib/cache.py b/zerver/lib/cache.py index b3d175362b..204f4788bf 100644 --- a/zerver/lib/cache.py +++ b/zerver/lib/cache.py @@ -472,7 +472,7 @@ def user_profile_by_api_key_cache_key(api_key: str) -> str: return f"user_profile_by_api_key:{api_key}" realm_user_dict_fields: List[str] = [ - 'id', 'full_name', 'short_name', 'email', + 'id', 'full_name', 'email', 'avatar_source', 'avatar_version', 'is_active', 'role', 'is_bot', 'realm_id', 'timezone', 'date_joined', 'bot_owner_id', 'delivery_email', @@ -505,7 +505,6 @@ bot_dict_fields: List[str] = [ 'id', 'is_active', 'realm_id', - 'short_name', ] def bot_dicts_in_realm_cache_key(realm: 'Realm') -> str: @@ -569,7 +568,7 @@ def flush_user_profile(sender: Any, **kwargs: Any) -> None: if changed(kwargs, ['role']): cache_delete(active_non_guest_user_ids_cache_key(user_profile.realm_id)) - if changed(kwargs, ['email', 'full_name', 'short_name', 'id', 'is_mirror_dummy']): + if changed(kwargs, ['email', 'full_name', 'id', 'is_mirror_dummy']): delete_display_recipient_cache(user_profile) # Invalidate our bots_in_realm info dict if any bot has diff --git a/zerver/lib/create_user.py b/zerver/lib/create_user.py index 41618a6001..93e2644ce3 100644 --- a/zerver/lib/create_user.py +++ b/zerver/lib/create_user.py @@ -68,7 +68,7 @@ def get_role_for_new_user(invited_as: int, realm_creation: bool=False) -> int: # Recipient objects def create_user_profile(realm: Realm, email: str, password: Optional[str], active: bool, bot_type: Optional[int], full_name: str, - short_name: str, bot_owner: Optional[UserProfile], + bot_owner: Optional[UserProfile], is_mirror_dummy: bool, tos_version: Optional[str], timezone: Optional[str], tutorial_status: str = UserProfile.TUTORIAL_WAITING, @@ -77,7 +77,7 @@ def create_user_profile(realm: Realm, email: str, password: Optional[str], email = UserManager.normalize_email(email) user_profile = UserProfile(is_staff=False, is_active=active, - full_name=full_name, short_name=short_name, + full_name=full_name, last_login=now, date_joined=now, realm=realm, is_bot=bool(bot_type), bot_type=bot_type, bot_owner=bot_owner, is_mirror_dummy=is_mirror_dummy, @@ -97,21 +97,34 @@ def create_user_profile(realm: Realm, email: str, password: Optional[str], user_profile.api_key = generate_api_key() return user_profile -def create_user(email: str, password: Optional[str], realm: Realm, - full_name: str, short_name: str, active: bool = True, +def create_user(email: str, + password: Optional[str], + realm: Realm, + full_name: str, + active: bool = True, role: Optional[int] = None, bot_type: Optional[int] = None, bot_owner: Optional[UserProfile] = None, - tos_version: Optional[str] = None, timezone: str = "", + tos_version: Optional[str] = None, + timezone: str = "", avatar_source: str = UserProfile.AVATAR_FROM_GRAVATAR, is_mirror_dummy: bool = False, default_sending_stream: Optional[Stream] = None, default_events_register_stream: Optional[Stream] = None, default_all_public_streams: Optional[bool] = None, source_profile: Optional[UserProfile] = None) -> UserProfile: - user_profile = create_user_profile(realm, email, password, active, bot_type, - full_name, short_name, bot_owner, - is_mirror_dummy, tos_version, timezone) + user_profile = create_user_profile( + realm, + email, + password, + active, + bot_type, + full_name, + bot_owner, + is_mirror_dummy, + tos_version, + timezone + ) user_profile.avatar_source = avatar_source user_profile.timezone = timezone user_profile.default_sending_stream = default_sending_stream diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.py index 4f3cf5b4fe..3e77e3e555 100644 --- a/zerver/lib/import_realm.py +++ b/zerver/lib/import_realm.py @@ -62,7 +62,6 @@ from zerver.models import ( UserMessage, UserPresence, UserProfile, - email_to_username, get_huddle_hash, get_system_bot, get_user_profile_by_id, @@ -880,6 +879,10 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int=1) -> Realm # Since Zulip doesn't use these permissions, drop them del user_profile_dict['user_permissions'] del user_profile_dict['groups'] + # The short_name field is obsolete in Zulip, but it's + # convenient for third party exports to populate it. + if 'short_name' in user_profile_dict: + del user_profile_dict['short_name'] user_profiles = [UserProfile(**item) for item in data['zerver_userprofile']] for user_profile in user_profiles: @@ -1097,9 +1100,8 @@ def create_users(realm: Realm, name_list: Iterable[Tuple[str, str]], bot_type: Optional[int]=None) -> None: user_set = set() for full_name, email in name_list: - short_name = email_to_username(email) if not UserProfile.objects.filter(email=email): - user_set.add((email, full_name, short_name, True)) + user_set.add((email, full_name, True)) bulk_create_users(realm, user_set, bot_type) def update_message_foreign_keys(import_dir: Path, diff --git a/zerver/lib/server_initialization.py b/zerver/lib/server_initialization.py index cdf0185760..8d69b3b793 100644 --- a/zerver/lib/server_initialization.py +++ b/zerver/lib/server_initialization.py @@ -3,7 +3,7 @@ from typing import Iterable, Optional, Tuple from django.conf import settings from zerver.lib.bulk_create import bulk_create_users -from zerver.models import Realm, UserProfile, email_to_username, get_client, get_system_bot +from zerver.models import Realm, UserProfile, get_client, get_system_bot def server_initialized() -> bool: @@ -41,6 +41,5 @@ def create_users(realm: Realm, name_list: Iterable[Tuple[str, str]], 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)) + user_set.add((email, full_name, True)) bulk_create_users(realm, user_set, bot_type=bot_type, bot_owner=bot_owner, tos_version=tos_version) diff --git a/zerver/management/commands/create_user.py b/zerver/management/commands/create_user.py index 5ca7f3559a..d1f6a129d7 100644 --- a/zerver/management/commands/create_user.py +++ b/zerver/management/commands/create_user.py @@ -10,7 +10,6 @@ from django.db.utils import IntegrityError from zerver.lib.actions import do_create_user from zerver.lib.initial_password import initial_password from zerver.lib.management import ZulipBaseCommand -from zerver.models import email_to_username class Command(ZulipBaseCommand): @@ -87,6 +86,12 @@ parameters, or specify no parameters for interactive user creation.""") if user_initial_password is None: raise CommandError("Password is unusable.") pw = user_initial_password - do_create_user(email, pw, realm, full_name, email_to_username(email), acting_user=None) + do_create_user( + email, + pw, + realm, + full_name, + acting_user=None, + ) except IntegrityError: raise CommandError("User already exists.") diff --git a/zerver/migrations/0296_remove_userprofile_short_name.py b/zerver/migrations/0296_remove_userprofile_short_name.py new file mode 100644 index 0000000000..cbdaeb2ec5 --- /dev/null +++ b/zerver/migrations/0296_remove_userprofile_short_name.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2.14 on 2020-07-16 11:06 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('zerver', '0295_case_insensitive_email_indexes'), + ] + + operations = [ + migrations.RemoveField( + model_name='userprofile', + name='short_name', + ), + ] diff --git a/zerver/models.py b/zerver/models.py index 24db7aabb6..bc72efbe8b 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -885,16 +885,13 @@ class UserProfile(AbstractBaseUser, PermissionsMixin): # Foreign key to the Recipient object for PERSONAL type messages to this user. recipient = models.ForeignKey(Recipient, null=True, on_delete=models.SET_NULL) - # The user's name. We prefer the model of a full_name and - # short_name over first+last because cultures vary on how many + # The user's name. We prefer the model of a full_name + # over first+last because cultures vary on how many # names one has, whether the family name is first or last, etc. # It also allows organizations to encode a bit of non-name data in # the "name" attribute if desired, like gender pronouns, - # graduation year, etc. The short_name attribute is currently not - # used anywhere, but the intent is that it would be used as the - # shorter familiar name for addressing the user in the UI. + # graduation year, etc. full_name: str = models.CharField(max_length=MAX_NAME_LENGTH) - short_name: str = models.CharField(max_length=MAX_NAME_LENGTH) date_joined: datetime.datetime = models.DateTimeField(default=timezone_now) tos_version: Optional[str] = models.CharField(null=True, max_length=10) diff --git a/zerver/tests/test_audit_log.py b/zerver/tests/test_audit_log.py index 6052d4c940..14774e8d56 100644 --- a/zerver/tests/test_audit_log.py +++ b/zerver/tests/test_audit_log.py @@ -46,7 +46,7 @@ class TestRealmAuditLog(ZulipTestCase): def test_user_activation(self) -> None: realm = get_realm('zulip') now = timezone_now() - user = do_create_user('email', 'password', realm, 'full_name', 'short_name', acting_user=None) + user = do_create_user('email', 'password', realm, 'full_name', acting_user=None) do_deactivate_user(user, acting_user=user) do_activate_user(user, acting_user=user) do_deactivate_user(user, acting_user=user) diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index d9357be024..9049216ef2 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -4491,7 +4491,7 @@ class TestZulipLDAPUserPopulator(ZulipLDAPTestCase): None, test_realm, hamlet.full_name, - hamlet.short_name) + ) self.change_ldap_user_attr('hamlet', 'cn', 'Second Hamlet') expected_call_args = [hamlet2, 'Second Hamlet', None] diff --git a/zerver/tests/test_digest.py b/zerver/tests/test_digest.py index cc3d3fb124..5fff68ca0e 100644 --- a/zerver/tests/test_digest.py +++ b/zerver/tests/test_digest.py @@ -254,8 +254,13 @@ class TestDigestEmailMessages(ZulipTestCase): cutoff = timezone_now() # A Tuesday mock_django_timezone.return_value = datetime.datetime(year=2016, month=1, day=5) - bot = do_create_user('some_bot@example.com', 'password', get_realm('zulip'), 'some_bot', '', - bot_type=UserProfile.DEFAULT_BOT) + bot = do_create_user( + 'some_bot@example.com', + 'password', + get_realm('zulip'), + 'some_bot', + bot_type=UserProfile.DEFAULT_BOT, + ) UserActivity.objects.create( last_visit=cutoff - datetime.timedelta(days=1), user_profile=bot, diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index fa49af6a06..bae18bd02b 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -749,8 +749,13 @@ class NormalActionsTest(BaseAction): prereg_user = PreregistrationUser.objects.get(email="foo@zulip.com") events = self.verify_action( - lambda: do_create_user('foo@zulip.com', 'password', self.user_profile.realm, - 'full name', 'short name', prereg_user=prereg_user), + lambda: do_create_user( + 'foo@zulip.com', + 'password', + self.user_profile.realm, + 'full name', + prereg_user=prereg_user, + ), state_change_expected=True, num_events=5, ) diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py index 5fb329e26a..637f4324a9 100644 --- a/zerver/tests/test_home.py +++ b/zerver/tests/test_home.py @@ -477,7 +477,6 @@ class HomeTest(ZulipTestCase): password='123', realm=owner.realm, full_name=bot_name, - short_name=bot_name, bot_type=UserProfile.DEFAULT_BOT, bot_owner=owner, ) @@ -489,7 +488,6 @@ class HomeTest(ZulipTestCase): password='123', realm=realm, full_name=name, - short_name=name, ) # Doing a full-stack deactivation would be expensive here, diff --git a/zerver/tests/test_hotspots.py b/zerver/tests/test_hotspots.py index 59123353b4..13dec9866b 100644 --- a/zerver/tests/test_hotspots.py +++ b/zerver/tests/test_hotspots.py @@ -12,7 +12,11 @@ class TestGetNextHotspots(ZulipTestCase): def setUp(self) -> None: super().setUp() self.user = do_create_user( - 'user@zulip.com', 'password', get_realm('zulip'), 'user', 'user') + 'user@zulip.com', + 'password', + get_realm('zulip'), + 'user', + ) def test_first_hotspot(self) -> None: hotspots = get_next_hotspots(self.user) diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py index eafa0f07b6..6f19a764a9 100644 --- a/zerver/tests/test_import_export.py +++ b/zerver/tests/test_import_export.py @@ -720,7 +720,6 @@ class ImportExportTest(ZulipTestCase): password="test", realm=original_realm, full_name="bot", - short_name="bot", bot_type=UserProfile.EMBEDDED_BOT, bot_owner=sample_user) storage = StateHandler(bot_profile) diff --git a/zerver/tests/test_management_commands.py b/zerver/tests/test_management_commands.py index 3d9e245245..ac3672ba26 100644 --- a/zerver/tests/test_management_commands.py +++ b/zerver/tests/test_management_commands.py @@ -74,7 +74,7 @@ class TestZulipBaseCommand(ZulipTestCase): with self.assertRaisesRegex(CommandError, "server does not contain a user with email"): self.command.get_user('invalid_email@example.com', None) - do_create_user(email, 'password', mit_realm, 'full_name', 'short_name') + do_create_user(email, 'password', mit_realm, 'full_name') with self.assertRaisesRegex(CommandError, "server contains multiple users with that email"): self.command.get_user(email, None) diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.py index b952708a48..f5f4c7e6c7 100644 --- a/zerver/tests/test_markdown.py +++ b/zerver/tests/test_markdown.py @@ -208,7 +208,6 @@ class MarkdownMiscTest(ZulipTestCase): password='whatever', realm=realm, full_name=full_name, - short_name='whatever', ) fred1 = make_user('fred1@example.com', 'Fred Flintstone') @@ -1576,7 +1575,6 @@ class MarkdownTest(ZulipTestCase): password='whatever', realm=realm, full_name=full_name, - short_name='whatever', ) sender_user_profile = self.example_user('othello') @@ -1622,11 +1620,12 @@ class MarkdownTest(ZulipTestCase): '[0-9]{2,8})' ' https://trac.example.com/ticket/%(id)s>') # Create a user that potentially interferes with the pattern. - test_user = create_user(email='atomic@example.com', - password='whatever', - realm=realm, - full_name='Atomic #123', - short_name='whatever') + test_user = create_user( + email='atomic@example.com', + password='whatever', + realm=realm, + full_name='Atomic #123', + ) content = "@**Atomic #123**" self.assertEqual(render_markdown(msg, content), '

HttpResponse: assert(realm is not None) full_name = form.cleaned_data['full_name'] - short_name = email_to_username(email) default_stream_group_names = request.POST.getlist('default_stream_group') default_stream_groups = lookup_default_stream_groups(default_stream_group_names, realm) @@ -374,7 +372,7 @@ def accounts_register(request: HttpRequest) -> HttpResponse: # make it respect invited_as_admin / is_realm_admin. if user_profile is None: - user_profile = do_create_user(email, password, realm, full_name, short_name, + user_profile = do_create_user(email, password, realm, full_name, prereg_user=prereg_user, role=role, tos_version=settings.TOS_VERSION, diff --git a/zerver/views/users.py b/zerver/views/users.py index d3c4bb3af2..bab1d6730e 100644 --- a/zerver/views/users.py +++ b/zerver/views/users.py @@ -382,7 +382,6 @@ def add_bot_backend( bot_profile = do_create_user(email=email, password=None, realm=user_profile.realm, full_name=full_name, - short_name=short_name, bot_type=bot_type, bot_owner=user_profile, avatar_source=avatar_source, @@ -522,9 +521,7 @@ def create_user_backend( if not check_password_strength(password): return json_error(PASSWORD_TOO_WEAK_ERROR) - short_name = 'deprecated' - - do_create_user(email, password, realm, full_name, short_name, acting_user=user_profile) + do_create_user(email, password, realm, full_name, acting_user=user_profile) return json_success() def get_profile_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: diff --git a/zilencer/management/commands/add_mock_conversation.py b/zilencer/management/commands/add_mock_conversation.py index e9dd515218..1be57f9882 100644 --- a/zilencer/management/commands/add_mock_conversation.py +++ b/zilencer/management/commands/add_mock_conversation.py @@ -45,11 +45,11 @@ From image editing program: stream = ensure_stream(realm, 'zulip features', acting_user=None) UserProfile.objects.filter(email__contains='stage').delete() - starr = do_create_user('1@stage.example.com', 'password', realm, 'Ada Starr', '', acting_user=None) + starr = do_create_user('1@stage.example.com', 'password', realm, 'Ada Starr', acting_user=None) self.set_avatar(starr, 'static/images/characters/starr.png') - fisher = do_create_user('2@stage.example.com', 'password', realm, 'Bel Fisher', '', acting_user=None) + fisher = do_create_user('2@stage.example.com', 'password', realm, 'Bel Fisher', acting_user=None) self.set_avatar(fisher, 'static/images/characters/fisher.png') - twitter_bot = do_create_user('3@stage.example.com', 'password', realm, 'Twitter Bot', '', + twitter_bot = do_create_user('3@stage.example.com', 'password', realm, 'Twitter Bot', bot_type=UserProfile.DEFAULT_BOT, acting_user=None) self.set_avatar(twitter_bot, 'static/images/features/twitter.png') diff --git a/zilencer/management/commands/add_new_realm.py b/zilencer/management/commands/add_new_realm.py index 5a7b1074ca..6f20a44513 100644 --- a/zilencer/management/commands/add_new_realm.py +++ b/zilencer/management/commands/add_new_realm.py @@ -16,8 +16,14 @@ class Command(ZulipBaseCommand): name = '{:02}-user'.format( UserProfile.objects.filter(email__contains='user@').count()) - user = do_create_user(f'{name}@{string_id}.zulip.com', - 'password', realm, name, name, role=UserProfile.ROLE_REALM_ADMINISTRATOR, acting_user=None) + user = do_create_user( + f'{name}@{string_id}.zulip.com', + 'password', + realm, + name, + role=UserProfile.ROLE_REALM_ADMINISTRATOR, + acting_user=None, + ) assert realm.signup_notifications_stream is not None bulk_add_subscriptions([realm.signup_notifications_stream], [user]) diff --git a/zilencer/management/commands/add_new_user.py b/zilencer/management/commands/add_new_user.py index b34fa09a05..22eed000f6 100644 --- a/zilencer/management/commands/add_new_user.py +++ b/zilencer/management/commands/add_new_user.py @@ -30,4 +30,4 @@ and will otherwise fall back to the zulip 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, name, acting_user=None) + do_create_user(f'{name}@{domain}', 'password', valid_realm, name, acting_user=None) diff --git a/zproject/backends.py b/zproject/backends.py index 3684e434f8..edea432b17 100644 --- a/zproject/backends.py +++ b/zproject/backends.py @@ -749,7 +749,7 @@ class ZulipLDAPAuthBackend(ZulipLDAPAuthBackendBase): # the LDAP flow. opts['default_stream_groups'] = [] - user_profile = do_create_user(username, None, self._realm, full_name, short_name, acting_user=None, **opts) + user_profile = do_create_user(username, None, self._realm, full_name, acting_user=None, **opts) self.sync_avatar_from_ldap(user_profile, ldap_user) self.sync_custom_profile_fields_from_ldap(user_profile, ldap_user)