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.
This commit is contained in:
Steve Howell 2020-07-16 12:10:43 +00:00 committed by Tim Abbott
parent c60f4236a9
commit c44500175d
39 changed files with 156 additions and 114 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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,

View File

@ -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,

View File

@ -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')

View File

@ -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,

View File

@ -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,

View File

@ -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,
)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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)

View File

@ -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.")

View File

@ -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',
),
]

View File

@ -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)

View File

@ -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)

View File

@ -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]

View File

@ -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,

View File

@ -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,
)

View File

@ -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,

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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):
'<RealmFilter(zulip): #(?P<id>[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),
'<p><span class="user-mention" '

View File

@ -183,7 +183,6 @@ class MessagePOSTTest(ZulipTestCase):
password='',
realm=non_admin_profile.realm,
full_name='freebot',
short_name='freebot',
bot_type=UserProfile.DEFAULT_BOT,
)
self._send_and_verify_message(bot_without_owner, stream_name,
@ -248,7 +247,6 @@ class MessagePOSTTest(ZulipTestCase):
password='',
realm=non_admin_profile.realm,
full_name='freebot',
short_name='freebot',
bot_type=UserProfile.DEFAULT_BOT,
)
self._send_and_verify_message(bot_without_owner, stream_name,
@ -1302,7 +1300,6 @@ class StreamMessagesTest(ZulipTestCase):
password='',
realm=realm,
full_name='Normal Bot',
short_name='',
bot_type=UserProfile.DEFAULT_BOT,
bot_owner=cordelia,
)
@ -1903,7 +1900,6 @@ class CheckMessageTest(ZulipTestCase):
password='',
realm=parent.realm,
full_name='',
short_name='',
bot_type=UserProfile.DEFAULT_BOT,
bot_owner=parent,
)

View File

@ -165,7 +165,6 @@ class TestOutgoingWebhookMessaging(ZulipTestCase):
full_name='Outgoing Webhook Bot',
email='whatever',
realm=bot_owner.realm,
short_name='',
password=None,
)

View File

@ -269,11 +269,12 @@ class RealmEmojiTest(ZulipTestCase):
# Test that two different realm emojis in two different realms but
# having same name can be administered independently.
realm_1 = do_create_realm('test_realm', 'test_realm')
emoji_author_1 = do_create_user('abc@example.com',
password='abc',
realm=realm_1,
full_name='abc',
short_name='abc')
emoji_author_1 = do_create_user(
'abc@example.com',
password='abc',
realm=realm_1,
full_name='abc',
)
self.create_test_emoji('test_emoji', emoji_author_1)
emoji_author_2 = self.example_user('othello')

View File

@ -25,7 +25,6 @@ class TestServiceBotBasics(ZulipTestCase):
password="test",
realm=get_realm("zulip"),
full_name="BarBot",
short_name='bb',
bot_type=UserProfile.OUTGOING_WEBHOOK_BOT,
bot_owner=self.example_user('cordelia'),
)
@ -170,14 +169,12 @@ class TestServiceBotStateHandler(ZulipTestCase):
password="test",
realm=get_realm("zulip"),
full_name="EmbeddedBo1",
short_name="embedded-bot-1",
bot_type=UserProfile.EMBEDDED_BOT,
bot_owner=self.user_profile)
self.second_bot_profile = do_create_user(email="embedded-bot-2@zulip.com",
password="test",
realm=get_realm("zulip"),
full_name="EmbeddedBot2",
short_name="embedded-bot-2",
bot_type=UserProfile.EMBEDDED_BOT,
bot_owner=self.user_profile)
@ -397,14 +394,12 @@ class TestServiceBotEventTriggers(ZulipTestCase):
password="test",
realm=get_realm("zulip"),
full_name="FooBot",
short_name="foo-bot",
bot_type=UserProfile.OUTGOING_WEBHOOK_BOT,
bot_owner=self.user_profile)
self.second_bot_profile = do_create_user(email="bar-bot@zulip.com",
password="test",
realm=get_realm("zulip"),
full_name="BarBot",
short_name="bar-bot",
bot_type=UserProfile.OUTGOING_WEBHOOK_BOT,
bot_owner=self.user_profile)

View File

@ -1579,7 +1579,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
'foo@zulip.com',
'password',
self.user_profile.realm,
'full name', 'short name',
'full name',
prereg_user=prereg_user,
)
@ -3392,8 +3392,6 @@ class UserSignUpTest(InviteUserBase):
user_profile = UserProfile.objects.get(delivery_email=email)
# Name comes from form which was set by LDAP.
self.assertEqual(user_profile.full_name, full_name)
# Short name comes from LDAP.
self.assertEqual(user_profile.short_name, "shortname")
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',
'zproject.backends.ZulipDummyBackend'))
@ -3435,8 +3433,6 @@ class UserSignUpTest(InviteUserBase):
user_profile = UserProfile.objects.get(delivery_email=email)
# Name comes from form which was set by LDAP.
self.assertEqual(user_profile.full_name, "First Last")
# Short name comes from LDAP.
self.assertEqual(user_profile.short_name, "First")
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',
'zproject.backends.ZulipDummyBackend'))
@ -3472,7 +3468,6 @@ class UserSignUpTest(InviteUserBase):
user_profile = UserProfile.objects.get(delivery_email=email)
# Name comes from form which was set by LDAP.
self.assertEqual(user_profile.full_name, full_name)
self.assertEqual(user_profile.short_name, 'shortname')
# Test custom profile fields are properly synced.
phone_number_field = CustomProfileField.objects.get(realm=user_profile.realm, name='Phone number')

View File

@ -356,7 +356,6 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(zerver_userprofile[3]['email'], 'matt.perry@foreignteam.slack.com')
self.assertEqual(zerver_userprofile[3]['realm'], 1)
self.assertEqual(zerver_userprofile[3]['full_name'], 'Matt Perry')
self.assertEqual(zerver_userprofile[3]['short_name'], 'matt.perry')
self.assertEqual(zerver_userprofile[3]['is_mirror_dummy'], True)
self.assertEqual(zerver_userprofile[3]['is_api_super_user'], False)

View File

@ -824,7 +824,6 @@ class AdminCreateUserTest(ZulipTestCase):
# Romeo is a newly registered user
new_user = get_user_by_delivery_email('romeo@zulip.net', get_realm('zulip'))
self.assertEqual(new_user.full_name, 'Romeo Montague')
self.assertEqual(new_user.short_name, 'deprecated')
# Make sure the recipient field is set correctly.
self.assertEqual(new_user.recipient, Recipient.objects.get(type=Recipient.PERSONAL,
@ -1442,7 +1441,6 @@ class RecipientInfoTest(ZulipTestCase):
password='',
realm=realm,
full_name='',
short_name='',
bot_type=UserProfile.EMBEDDED_BOT,
)
@ -1462,7 +1460,6 @@ class RecipientInfoTest(ZulipTestCase):
password='',
realm=realm,
full_name='',
short_name='',
bot_type=UserProfile.DEFAULT_BOT,
)

View File

@ -61,7 +61,6 @@ from zerver.models import (
Realm,
Stream,
UserProfile,
email_to_username,
get_default_stream_groups,
get_realm,
get_source_profile,
@ -286,7 +285,6 @@ def accounts_register(request: HttpRequest) -> 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,

View File

@ -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:

View File

@ -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')

View File

@ -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])

View File

@ -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)

View File

@ -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)