mirror of https://github.com/zulip/zulip.git
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:
parent
c60f4236a9
commit
c44500175d
|
@ -61,9 +61,13 @@ class Command(BaseCommand):
|
||||||
realm = Realm.objects.create(
|
realm = Realm.objects.create(
|
||||||
string_id='analytics', name='Analytics', date_created=installation_time)
|
string_id='analytics', name='Analytics', date_created=installation_time)
|
||||||
with mock.patch("zerver.lib.create_user.timezone_now", return_value=installation_time):
|
with mock.patch("zerver.lib.create_user.timezone_now", return_value=installation_time):
|
||||||
shylock = create_user('shylock@analytics.ds', 'Shylock', realm,
|
shylock = create_user(
|
||||||
full_name='Shylock', short_name='shylock',
|
'shylock@analytics.ds',
|
||||||
role=UserProfile.ROLE_REALM_ADMINISTRATOR)
|
'Shylock',
|
||||||
|
realm,
|
||||||
|
full_name='Shylock',
|
||||||
|
role=UserProfile.ROLE_REALM_ADMINISTRATOR
|
||||||
|
)
|
||||||
do_change_user_role(shylock, UserProfile.ROLE_REALM_ADMINISTRATOR, acting_user=None)
|
do_change_user_role(shylock, UserProfile.ROLE_REALM_ADMINISTRATOR, acting_user=None)
|
||||||
stream = Stream.objects.create(
|
stream = Stream.objects.create(
|
||||||
name='all', realm=realm, date_created=installation_time)
|
name='all', realm=realm, date_created=installation_time)
|
||||||
|
|
|
@ -89,7 +89,6 @@ class AnalyticsTestCase(ZulipTestCase):
|
||||||
'email': f'user{self.name_counter}@domain.tld',
|
'email': f'user{self.name_counter}@domain.tld',
|
||||||
'date_joined': self.TIME_LAST_HOUR,
|
'date_joined': self.TIME_LAST_HOUR,
|
||||||
'full_name': 'full_name',
|
'full_name': 'full_name',
|
||||||
'short_name': 'short_name',
|
|
||||||
'is_active': True,
|
'is_active': True,
|
||||||
'is_bot': False,
|
'is_bot': False,
|
||||||
'realm': self.default_realm}
|
'realm': self.default_realm}
|
||||||
|
@ -101,10 +100,15 @@ class AnalyticsTestCase(ZulipTestCase):
|
||||||
if kwargs['is_bot']:
|
if kwargs['is_bot']:
|
||||||
pass_kwargs['bot_type'] = UserProfile.DEFAULT_BOT
|
pass_kwargs['bot_type'] = UserProfile.DEFAULT_BOT
|
||||||
pass_kwargs['bot_owner'] = None
|
pass_kwargs['bot_owner'] = None
|
||||||
return create_user(kwargs['email'], 'password', kwargs['realm'],
|
return create_user(
|
||||||
active=kwargs['is_active'],
|
kwargs['email'],
|
||||||
full_name=kwargs['full_name'], short_name=kwargs['short_name'],
|
'password',
|
||||||
role=UserProfile.ROLE_REALM_ADMINISTRATOR, **pass_kwargs)
|
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]:
|
def create_stream_with_recipient(self, **kwargs: Any) -> Tuple[Stream, Recipient]:
|
||||||
self.name_counter += 1
|
self.name_counter += 1
|
||||||
|
@ -1099,7 +1103,7 @@ class TestLoggingCountStats(AnalyticsTestCase):
|
||||||
|
|
||||||
def test_active_users_log_by_is_bot(self) -> None:
|
def test_active_users_log_by_is_bot(self) -> None:
|
||||||
property = 'active_users_log:is_bot:day'
|
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)
|
self.assertEqual(1, RealmCount.objects.filter(property=property, subgroup=False)
|
||||||
.aggregate(Sum('value'))['value__sum'])
|
.aggregate(Sum('value'))['value__sum'])
|
||||||
do_deactivate_user(user)
|
do_deactivate_user(user)
|
||||||
|
@ -1363,10 +1367,10 @@ class TestActiveUsersAudit(AnalyticsTestCase):
|
||||||
[[user1, 'false'], [user2, 'false']])
|
[[user1, 'false'], [user2, 'false']])
|
||||||
|
|
||||||
def test_end_to_end_with_actions_dot_py(self) -> None:
|
def test_end_to_end_with_actions_dot_py(self) -> None:
|
||||||
user1 = do_create_user('email1', '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', 'short_name')
|
user2 = do_create_user('email2', 'password', self.default_realm, 'full_name')
|
||||||
user3 = do_create_user('email3', 'password', self.default_realm, 'full_name', 'short_name')
|
user3 = do_create_user('email3', 'password', self.default_realm, 'full_name')
|
||||||
user4 = do_create_user('email4', 'password', self.default_realm, 'full_name', 'short_name')
|
user4 = do_create_user('email4', 'password', self.default_realm, 'full_name')
|
||||||
do_deactivate_user(user2)
|
do_deactivate_user(user2)
|
||||||
do_activate_user(user3)
|
do_activate_user(user3)
|
||||||
do_reactivate_user(user4)
|
do_reactivate_user(user4)
|
||||||
|
@ -1458,9 +1462,9 @@ class TestRealmActiveHumans(AnalyticsTestCase):
|
||||||
[2, second_realm, self.TIME_ZERO - self.DAY]])
|
[2, second_realm, self.TIME_ZERO - self.DAY]])
|
||||||
|
|
||||||
def test_end_to_end(self) -> None:
|
def test_end_to_end(self) -> None:
|
||||||
user1 = do_create_user('email1', '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', 'short_name')
|
user2 = do_create_user('email2', 'password', self.default_realm, 'full_name')
|
||||||
do_create_user('email3', 'password', self.default_realm, 'full_name', 'short_name')
|
do_create_user('email3', 'password', self.default_realm, 'full_name')
|
||||||
time_zero = floor_to_day(timezone_now()) + self.DAY
|
time_zero = floor_to_day(timezone_now()) + self.DAY
|
||||||
update_user_activity_interval(user1, time_zero)
|
update_user_activity_interval(user1, time_zero)
|
||||||
update_user_activity_interval(user2, time_zero)
|
update_user_activity_interval(user2, time_zero)
|
||||||
|
|
|
@ -2084,7 +2084,7 @@ class LicenseLedgerTest(StripeTestCase):
|
||||||
|
|
||||||
def test_user_changes(self) -> None:
|
def test_user_changes(self) -> None:
|
||||||
self.local_upgrade(self.seat_count, True, CustomerPlan.ANNUAL, 'token')
|
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_deactivate_user(user)
|
||||||
do_reactivate_user(user)
|
do_reactivate_user(user)
|
||||||
# Not a proper use of do_activate_user, but fine for this test
|
# Not a proper use of do_activate_user, but fine for this test
|
||||||
|
|
|
@ -67,7 +67,6 @@ def create_integration_bot(integration: WebhookIntegration, bot_name: Optional[s
|
||||||
password="123",
|
password="123",
|
||||||
realm=owner.realm,
|
realm=owner.realm,
|
||||||
full_name=bot_name,
|
full_name=bot_name,
|
||||||
short_name=bot_name,
|
|
||||||
bot_type=UserProfile.INCOMING_WEBHOOK_BOT,
|
bot_type=UserProfile.INCOMING_WEBHOOK_BOT,
|
||||||
bot_owner=owner,
|
bot_owner=owner,
|
||||||
acting_user=owner,
|
acting_user=owner,
|
||||||
|
|
|
@ -68,8 +68,12 @@ with test_server_running(force=options.force, external_host='zulipdev.com:9981')
|
||||||
|
|
||||||
# Prepare the non-admin client
|
# Prepare the non-admin client
|
||||||
email = 'guest@zulip.com' # guest is not an admin
|
email = 'guest@zulip.com' # guest is not an admin
|
||||||
guest_user = do_create_user('guest@zulip.com', 'secret',
|
guest_user = do_create_user(
|
||||||
get_realm('zulip'), 'Mr. Guest', 'guest')
|
'guest@zulip.com',
|
||||||
|
'secret',
|
||||||
|
get_realm('zulip'),
|
||||||
|
'Mr. Guest',
|
||||||
|
)
|
||||||
api_key = get_api_key(guest_user)
|
api_key = get_api_key(guest_user)
|
||||||
nonadmin_client = Client(
|
nonadmin_client = Client(
|
||||||
email=email,
|
email=email,
|
||||||
|
|
|
@ -89,7 +89,6 @@ def build_userprofile(timestamp: Any, domain_name: str,
|
||||||
# Build userprofile object
|
# Build userprofile object
|
||||||
userprofile = UserProfile(
|
userprofile = UserProfile(
|
||||||
full_name=user_data['displayName'],
|
full_name=user_data['displayName'],
|
||||||
short_name=user_data['username'],
|
|
||||||
id=user_id,
|
id=user_id,
|
||||||
email=email,
|
email=email,
|
||||||
delivery_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
|
# Set realm id separately as the corresponding realm is not yet a Realm model
|
||||||
# instance
|
# instance
|
||||||
userprofile_dict['realm'] = realm_id
|
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)
|
zerver_userprofile.append(userprofile_dict)
|
||||||
user_id += 1
|
user_id += 1
|
||||||
logging.info('######### IMPORTING USERS FINISHED #########\n')
|
logging.info('######### IMPORTING USERS FINISHED #########\n')
|
||||||
|
|
|
@ -99,10 +99,16 @@ def build_user_profile(avatar_source: str,
|
||||||
is_active=is_active,
|
is_active=is_active,
|
||||||
role=role,
|
role=role,
|
||||||
realm_id=realm_id,
|
realm_id=realm_id,
|
||||||
short_name=short_name,
|
|
||||||
timezone=timezone,
|
timezone=timezone,
|
||||||
)
|
)
|
||||||
dct = model_to_dict(obj)
|
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
|
return dct
|
||||||
|
|
||||||
def build_avatar(zulip_user_id: int, realm_id: int, email: str, avatar_url: str,
|
def build_avatar(zulip_user_id: int, realm_id: int, email: str, avatar_url: str,
|
||||||
|
|
|
@ -206,7 +206,6 @@ def users_to_zerver_userprofile(slack_data_dir: str, users: List[ZerverFieldsT],
|
||||||
|
|
||||||
userprofile = UserProfile(
|
userprofile = UserProfile(
|
||||||
full_name=get_user_full_name(user),
|
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_active=not user.get('deleted', False) and not user["is_mirror_dummy"],
|
||||||
is_mirror_dummy=user["is_mirror_dummy"],
|
is_mirror_dummy=user["is_mirror_dummy"],
|
||||||
id=user_id,
|
id=user_id,
|
||||||
|
|
|
@ -209,7 +209,6 @@ from zerver.models import (
|
||||||
active_non_guest_user_ids,
|
active_non_guest_user_ids,
|
||||||
active_user_ids,
|
active_user_ids,
|
||||||
custom_profile_fields_for_realm,
|
custom_profile_fields_for_realm,
|
||||||
email_to_username,
|
|
||||||
filter_to_valid_prereg_users,
|
filter_to_valid_prereg_users,
|
||||||
get_active_streams,
|
get_active_streams,
|
||||||
get_bot_dicts_in_realm,
|
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:
|
def create_users(realm: Realm, name_list: Iterable[Tuple[str, str]], 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)
|
user_set.add((email, full_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)
|
||||||
|
|
||||||
def do_create_user(email: str, password: Optional[str], realm: Realm, full_name: str,
|
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,
|
bot_owner: Optional[UserProfile]=None, tos_version: Optional[str]=None,
|
||||||
timezone: str="", avatar_source: str=UserProfile.AVATAR_FROM_GRAVATAR,
|
timezone: str="", avatar_source: str=UserProfile.AVATAR_FROM_GRAVATAR,
|
||||||
default_sending_stream: Optional[Stream]=None,
|
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:
|
acting_user: Optional[UserProfile]=None) -> UserProfile:
|
||||||
|
|
||||||
user_profile = create_user(email=email, password=password, realm=realm,
|
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,
|
role=role, bot_type=bot_type, bot_owner=bot_owner,
|
||||||
tos_version=tos_version, timezone=timezone, avatar_source=avatar_source,
|
tos_version=tos_version, timezone=timezone, avatar_source=avatar_source,
|
||||||
default_sending_stream=default_sending_stream,
|
default_sending_stream=default_sending_stream,
|
||||||
|
@ -1044,7 +1042,6 @@ def create_mirror_user_if_needed(realm: Realm, email: str,
|
||||||
password=None,
|
password=None,
|
||||||
realm=realm,
|
realm=realm,
|
||||||
full_name=email_to_fullname(email),
|
full_name=email_to_fullname(email),
|
||||||
short_name=email_to_username(email),
|
|
||||||
active=False,
|
active=False,
|
||||||
is_mirror_dummy=True,
|
is_mirror_dummy=True,
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,7 +9,7 @@ from zerver.models import Realm, RealmAuditLog, Recipient, Stream, Subscription,
|
||||||
|
|
||||||
|
|
||||||
def bulk_create_users(realm: Realm,
|
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_type: Optional[int]=None,
|
||||||
bot_owner: Optional[UserProfile]=None,
|
bot_owner: Optional[UserProfile]=None,
|
||||||
tos_version: Optional[str]=None,
|
tos_version: Optional[str]=None,
|
||||||
|
@ -24,10 +24,10 @@ def bulk_create_users(realm: Realm,
|
||||||
|
|
||||||
# Now create user_profiles
|
# Now create user_profiles
|
||||||
profiles_to_create: List[UserProfile] = []
|
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,
|
profile = create_user_profile(realm, email,
|
||||||
initial_password(email), active, bot_type,
|
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,
|
timezone, tutorial_status=UserProfile.TUTORIAL_FINISHED,
|
||||||
enter_sends=True)
|
enter_sends=True)
|
||||||
profiles_to_create.append(profile)
|
profiles_to_create.append(profile)
|
||||||
|
|
|
@ -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}"
|
return f"user_profile_by_api_key:{api_key}"
|
||||||
|
|
||||||
realm_user_dict_fields: List[str] = [
|
realm_user_dict_fields: List[str] = [
|
||||||
'id', 'full_name', 'short_name', 'email',
|
'id', 'full_name', 'email',
|
||||||
'avatar_source', 'avatar_version', 'is_active',
|
'avatar_source', 'avatar_version', 'is_active',
|
||||||
'role', 'is_bot', 'realm_id', 'timezone',
|
'role', 'is_bot', 'realm_id', 'timezone',
|
||||||
'date_joined', 'bot_owner_id', 'delivery_email',
|
'date_joined', 'bot_owner_id', 'delivery_email',
|
||||||
|
@ -505,7 +505,6 @@ bot_dict_fields: List[str] = [
|
||||||
'id',
|
'id',
|
||||||
'is_active',
|
'is_active',
|
||||||
'realm_id',
|
'realm_id',
|
||||||
'short_name',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def bot_dicts_in_realm_cache_key(realm: 'Realm') -> str:
|
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']):
|
if changed(kwargs, ['role']):
|
||||||
cache_delete(active_non_guest_user_ids_cache_key(user_profile.realm_id))
|
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)
|
delete_display_recipient_cache(user_profile)
|
||||||
|
|
||||||
# Invalidate our bots_in_realm info dict if any bot has
|
# Invalidate our bots_in_realm info dict if any bot has
|
||||||
|
|
|
@ -68,7 +68,7 @@ def get_role_for_new_user(invited_as: int, realm_creation: bool=False) -> int:
|
||||||
# Recipient objects
|
# Recipient objects
|
||||||
def create_user_profile(realm: Realm, email: str, password: Optional[str],
|
def create_user_profile(realm: Realm, email: str, password: Optional[str],
|
||||||
active: bool, bot_type: Optional[int], full_name: 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],
|
is_mirror_dummy: bool, tos_version: Optional[str],
|
||||||
timezone: Optional[str],
|
timezone: Optional[str],
|
||||||
tutorial_status: str = UserProfile.TUTORIAL_WAITING,
|
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)
|
email = UserManager.normalize_email(email)
|
||||||
|
|
||||||
user_profile = UserProfile(is_staff=False, is_active=active,
|
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,
|
last_login=now, date_joined=now, realm=realm,
|
||||||
is_bot=bool(bot_type), bot_type=bot_type,
|
is_bot=bool(bot_type), bot_type=bot_type,
|
||||||
bot_owner=bot_owner, is_mirror_dummy=is_mirror_dummy,
|
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()
|
user_profile.api_key = generate_api_key()
|
||||||
return user_profile
|
return user_profile
|
||||||
|
|
||||||
def create_user(email: str, password: Optional[str], realm: Realm,
|
def create_user(email: str,
|
||||||
full_name: str, short_name: str, active: bool = True,
|
password: Optional[str],
|
||||||
|
realm: Realm,
|
||||||
|
full_name: str,
|
||||||
|
active: bool = True,
|
||||||
role: Optional[int] = None,
|
role: Optional[int] = None,
|
||||||
bot_type: Optional[int] = None,
|
bot_type: Optional[int] = None,
|
||||||
bot_owner: Optional[UserProfile] = 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,
|
avatar_source: str = UserProfile.AVATAR_FROM_GRAVATAR,
|
||||||
is_mirror_dummy: bool = False,
|
is_mirror_dummy: bool = False,
|
||||||
default_sending_stream: Optional[Stream] = None,
|
default_sending_stream: Optional[Stream] = None,
|
||||||
default_events_register_stream: Optional[Stream] = None,
|
default_events_register_stream: Optional[Stream] = None,
|
||||||
default_all_public_streams: Optional[bool] = None,
|
default_all_public_streams: Optional[bool] = None,
|
||||||
source_profile: Optional[UserProfile] = None) -> UserProfile:
|
source_profile: Optional[UserProfile] = None) -> UserProfile:
|
||||||
user_profile = create_user_profile(realm, email, password, active, bot_type,
|
user_profile = create_user_profile(
|
||||||
full_name, short_name, bot_owner,
|
realm,
|
||||||
is_mirror_dummy, tos_version, timezone)
|
email,
|
||||||
|
password,
|
||||||
|
active,
|
||||||
|
bot_type,
|
||||||
|
full_name,
|
||||||
|
bot_owner,
|
||||||
|
is_mirror_dummy,
|
||||||
|
tos_version,
|
||||||
|
timezone
|
||||||
|
)
|
||||||
user_profile.avatar_source = avatar_source
|
user_profile.avatar_source = avatar_source
|
||||||
user_profile.timezone = timezone
|
user_profile.timezone = timezone
|
||||||
user_profile.default_sending_stream = default_sending_stream
|
user_profile.default_sending_stream = default_sending_stream
|
||||||
|
|
|
@ -62,7 +62,6 @@ from zerver.models import (
|
||||||
UserMessage,
|
UserMessage,
|
||||||
UserPresence,
|
UserPresence,
|
||||||
UserProfile,
|
UserProfile,
|
||||||
email_to_username,
|
|
||||||
get_huddle_hash,
|
get_huddle_hash,
|
||||||
get_system_bot,
|
get_system_bot,
|
||||||
get_user_profile_by_id,
|
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
|
# Since Zulip doesn't use these permissions, drop them
|
||||||
del user_profile_dict['user_permissions']
|
del user_profile_dict['user_permissions']
|
||||||
del user_profile_dict['groups']
|
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']]
|
user_profiles = [UserProfile(**item) for item in data['zerver_userprofile']]
|
||||||
for user_profile in user_profiles:
|
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:
|
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)
|
|
||||||
if not UserProfile.objects.filter(email=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)
|
bulk_create_users(realm, user_set, bot_type)
|
||||||
|
|
||||||
def update_message_foreign_keys(import_dir: Path,
|
def update_message_foreign_keys(import_dir: Path,
|
||||||
|
|
|
@ -3,7 +3,7 @@ from typing import Iterable, Optional, Tuple
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from zerver.lib.bulk_create import bulk_create_users
|
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:
|
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:
|
bot_owner: Optional[UserProfile]=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)
|
user_set.add((email, full_name, True))
|
||||||
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)
|
bulk_create_users(realm, user_set, bot_type=bot_type, bot_owner=bot_owner, tos_version=tos_version)
|
||||||
|
|
|
@ -10,7 +10,6 @@ from django.db.utils import IntegrityError
|
||||||
from zerver.lib.actions import do_create_user
|
from zerver.lib.actions import do_create_user
|
||||||
from zerver.lib.initial_password import initial_password
|
from zerver.lib.initial_password import initial_password
|
||||||
from zerver.lib.management import ZulipBaseCommand
|
from zerver.lib.management import ZulipBaseCommand
|
||||||
from zerver.models import email_to_username
|
|
||||||
|
|
||||||
|
|
||||||
class Command(ZulipBaseCommand):
|
class Command(ZulipBaseCommand):
|
||||||
|
@ -87,6 +86,12 @@ parameters, or specify no parameters for interactive user creation.""")
|
||||||
if user_initial_password is None:
|
if user_initial_password is None:
|
||||||
raise CommandError("Password is unusable.")
|
raise CommandError("Password is unusable.")
|
||||||
pw = user_initial_password
|
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:
|
except IntegrityError:
|
||||||
raise CommandError("User already exists.")
|
raise CommandError("User already exists.")
|
||||||
|
|
|
@ -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',
|
||||||
|
),
|
||||||
|
]
|
|
@ -885,16 +885,13 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
|
||||||
# Foreign key to the Recipient object for PERSONAL type messages to this user.
|
# Foreign key to the Recipient object for PERSONAL type messages to this user.
|
||||||
recipient = models.ForeignKey(Recipient, null=True, on_delete=models.SET_NULL)
|
recipient = models.ForeignKey(Recipient, null=True, on_delete=models.SET_NULL)
|
||||||
|
|
||||||
# The user's name. We prefer the model of a full_name and
|
# The user's name. We prefer the model of a full_name
|
||||||
# short_name over first+last because cultures vary on how many
|
# over first+last because cultures vary on how many
|
||||||
# names one has, whether the family name is first or last, etc.
|
# 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
|
# It also allows organizations to encode a bit of non-name data in
|
||||||
# the "name" attribute if desired, like gender pronouns,
|
# the "name" attribute if desired, like gender pronouns,
|
||||||
# graduation year, etc. The short_name attribute is currently not
|
# graduation year, etc.
|
||||||
# used anywhere, but the intent is that it would be used as the
|
|
||||||
# shorter familiar name for addressing the user in the UI.
|
|
||||||
full_name: str = models.CharField(max_length=MAX_NAME_LENGTH)
|
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)
|
date_joined: datetime.datetime = models.DateTimeField(default=timezone_now)
|
||||||
tos_version: Optional[str] = models.CharField(null=True, max_length=10)
|
tos_version: Optional[str] = models.CharField(null=True, max_length=10)
|
||||||
|
|
|
@ -46,7 +46,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
def test_user_activation(self) -> None:
|
def test_user_activation(self) -> None:
|
||||||
realm = get_realm('zulip')
|
realm = get_realm('zulip')
|
||||||
now = timezone_now()
|
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_deactivate_user(user, acting_user=user)
|
||||||
do_activate_user(user, acting_user=user)
|
do_activate_user(user, acting_user=user)
|
||||||
do_deactivate_user(user, acting_user=user)
|
do_deactivate_user(user, acting_user=user)
|
||||||
|
|
|
@ -4491,7 +4491,7 @@ class TestZulipLDAPUserPopulator(ZulipLDAPTestCase):
|
||||||
None,
|
None,
|
||||||
test_realm,
|
test_realm,
|
||||||
hamlet.full_name,
|
hamlet.full_name,
|
||||||
hamlet.short_name)
|
)
|
||||||
|
|
||||||
self.change_ldap_user_attr('hamlet', 'cn', 'Second Hamlet')
|
self.change_ldap_user_attr('hamlet', 'cn', 'Second Hamlet')
|
||||||
expected_call_args = [hamlet2, 'Second Hamlet', None]
|
expected_call_args = [hamlet2, 'Second Hamlet', None]
|
||||||
|
|
|
@ -254,8 +254,13 @@ class TestDigestEmailMessages(ZulipTestCase):
|
||||||
cutoff = timezone_now()
|
cutoff = timezone_now()
|
||||||
# A Tuesday
|
# A Tuesday
|
||||||
mock_django_timezone.return_value = datetime.datetime(year=2016, month=1, day=5)
|
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 = do_create_user(
|
||||||
bot_type=UserProfile.DEFAULT_BOT)
|
'some_bot@example.com',
|
||||||
|
'password',
|
||||||
|
get_realm('zulip'),
|
||||||
|
'some_bot',
|
||||||
|
bot_type=UserProfile.DEFAULT_BOT,
|
||||||
|
)
|
||||||
UserActivity.objects.create(
|
UserActivity.objects.create(
|
||||||
last_visit=cutoff - datetime.timedelta(days=1),
|
last_visit=cutoff - datetime.timedelta(days=1),
|
||||||
user_profile=bot,
|
user_profile=bot,
|
||||||
|
|
|
@ -749,8 +749,13 @@ class NormalActionsTest(BaseAction):
|
||||||
prereg_user = PreregistrationUser.objects.get(email="foo@zulip.com")
|
prereg_user = PreregistrationUser.objects.get(email="foo@zulip.com")
|
||||||
|
|
||||||
events = self.verify_action(
|
events = self.verify_action(
|
||||||
lambda: do_create_user('foo@zulip.com', 'password', self.user_profile.realm,
|
lambda: do_create_user(
|
||||||
'full name', 'short name', prereg_user=prereg_user),
|
'foo@zulip.com',
|
||||||
|
'password',
|
||||||
|
self.user_profile.realm,
|
||||||
|
'full name',
|
||||||
|
prereg_user=prereg_user,
|
||||||
|
),
|
||||||
state_change_expected=True,
|
state_change_expected=True,
|
||||||
num_events=5,
|
num_events=5,
|
||||||
)
|
)
|
||||||
|
|
|
@ -477,7 +477,6 @@ class HomeTest(ZulipTestCase):
|
||||||
password='123',
|
password='123',
|
||||||
realm=owner.realm,
|
realm=owner.realm,
|
||||||
full_name=bot_name,
|
full_name=bot_name,
|
||||||
short_name=bot_name,
|
|
||||||
bot_type=UserProfile.DEFAULT_BOT,
|
bot_type=UserProfile.DEFAULT_BOT,
|
||||||
bot_owner=owner,
|
bot_owner=owner,
|
||||||
)
|
)
|
||||||
|
@ -489,7 +488,6 @@ class HomeTest(ZulipTestCase):
|
||||||
password='123',
|
password='123',
|
||||||
realm=realm,
|
realm=realm,
|
||||||
full_name=name,
|
full_name=name,
|
||||||
short_name=name,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Doing a full-stack deactivation would be expensive here,
|
# Doing a full-stack deactivation would be expensive here,
|
||||||
|
|
|
@ -12,7 +12,11 @@ class TestGetNextHotspots(ZulipTestCase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.user = do_create_user(
|
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:
|
def test_first_hotspot(self) -> None:
|
||||||
hotspots = get_next_hotspots(self.user)
|
hotspots = get_next_hotspots(self.user)
|
||||||
|
|
|
@ -720,7 +720,6 @@ class ImportExportTest(ZulipTestCase):
|
||||||
password="test",
|
password="test",
|
||||||
realm=original_realm,
|
realm=original_realm,
|
||||||
full_name="bot",
|
full_name="bot",
|
||||||
short_name="bot",
|
|
||||||
bot_type=UserProfile.EMBEDDED_BOT,
|
bot_type=UserProfile.EMBEDDED_BOT,
|
||||||
bot_owner=sample_user)
|
bot_owner=sample_user)
|
||||||
storage = StateHandler(bot_profile)
|
storage = StateHandler(bot_profile)
|
||||||
|
|
|
@ -74,7 +74,7 @@ class TestZulipBaseCommand(ZulipTestCase):
|
||||||
with self.assertRaisesRegex(CommandError, "server does not contain a user with email"):
|
with self.assertRaisesRegex(CommandError, "server does not contain a user with email"):
|
||||||
self.command.get_user('invalid_email@example.com', None)
|
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"):
|
with self.assertRaisesRegex(CommandError, "server contains multiple users with that email"):
|
||||||
self.command.get_user(email, None)
|
self.command.get_user(email, None)
|
||||||
|
|
|
@ -208,7 +208,6 @@ class MarkdownMiscTest(ZulipTestCase):
|
||||||
password='whatever',
|
password='whatever',
|
||||||
realm=realm,
|
realm=realm,
|
||||||
full_name=full_name,
|
full_name=full_name,
|
||||||
short_name='whatever',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
fred1 = make_user('fred1@example.com', 'Fred Flintstone')
|
fred1 = make_user('fred1@example.com', 'Fred Flintstone')
|
||||||
|
@ -1576,7 +1575,6 @@ class MarkdownTest(ZulipTestCase):
|
||||||
password='whatever',
|
password='whatever',
|
||||||
realm=realm,
|
realm=realm,
|
||||||
full_name=full_name,
|
full_name=full_name,
|
||||||
short_name='whatever',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
sender_user_profile = self.example_user('othello')
|
sender_user_profile = self.example_user('othello')
|
||||||
|
@ -1622,11 +1620,12 @@ class MarkdownTest(ZulipTestCase):
|
||||||
'<RealmFilter(zulip): #(?P<id>[0-9]{2,8})'
|
'<RealmFilter(zulip): #(?P<id>[0-9]{2,8})'
|
||||||
' https://trac.example.com/ticket/%(id)s>')
|
' https://trac.example.com/ticket/%(id)s>')
|
||||||
# Create a user that potentially interferes with the pattern.
|
# Create a user that potentially interferes with the pattern.
|
||||||
test_user = create_user(email='atomic@example.com',
|
test_user = create_user(
|
||||||
password='whatever',
|
email='atomic@example.com',
|
||||||
realm=realm,
|
password='whatever',
|
||||||
full_name='Atomic #123',
|
realm=realm,
|
||||||
short_name='whatever')
|
full_name='Atomic #123',
|
||||||
|
)
|
||||||
content = "@**Atomic #123**"
|
content = "@**Atomic #123**"
|
||||||
self.assertEqual(render_markdown(msg, content),
|
self.assertEqual(render_markdown(msg, content),
|
||||||
'<p><span class="user-mention" '
|
'<p><span class="user-mention" '
|
||||||
|
|
|
@ -183,7 +183,6 @@ class MessagePOSTTest(ZulipTestCase):
|
||||||
password='',
|
password='',
|
||||||
realm=non_admin_profile.realm,
|
realm=non_admin_profile.realm,
|
||||||
full_name='freebot',
|
full_name='freebot',
|
||||||
short_name='freebot',
|
|
||||||
bot_type=UserProfile.DEFAULT_BOT,
|
bot_type=UserProfile.DEFAULT_BOT,
|
||||||
)
|
)
|
||||||
self._send_and_verify_message(bot_without_owner, stream_name,
|
self._send_and_verify_message(bot_without_owner, stream_name,
|
||||||
|
@ -248,7 +247,6 @@ class MessagePOSTTest(ZulipTestCase):
|
||||||
password='',
|
password='',
|
||||||
realm=non_admin_profile.realm,
|
realm=non_admin_profile.realm,
|
||||||
full_name='freebot',
|
full_name='freebot',
|
||||||
short_name='freebot',
|
|
||||||
bot_type=UserProfile.DEFAULT_BOT,
|
bot_type=UserProfile.DEFAULT_BOT,
|
||||||
)
|
)
|
||||||
self._send_and_verify_message(bot_without_owner, stream_name,
|
self._send_and_verify_message(bot_without_owner, stream_name,
|
||||||
|
@ -1302,7 +1300,6 @@ class StreamMessagesTest(ZulipTestCase):
|
||||||
password='',
|
password='',
|
||||||
realm=realm,
|
realm=realm,
|
||||||
full_name='Normal Bot',
|
full_name='Normal Bot',
|
||||||
short_name='',
|
|
||||||
bot_type=UserProfile.DEFAULT_BOT,
|
bot_type=UserProfile.DEFAULT_BOT,
|
||||||
bot_owner=cordelia,
|
bot_owner=cordelia,
|
||||||
)
|
)
|
||||||
|
@ -1903,7 +1900,6 @@ class CheckMessageTest(ZulipTestCase):
|
||||||
password='',
|
password='',
|
||||||
realm=parent.realm,
|
realm=parent.realm,
|
||||||
full_name='',
|
full_name='',
|
||||||
short_name='',
|
|
||||||
bot_type=UserProfile.DEFAULT_BOT,
|
bot_type=UserProfile.DEFAULT_BOT,
|
||||||
bot_owner=parent,
|
bot_owner=parent,
|
||||||
)
|
)
|
||||||
|
|
|
@ -165,7 +165,6 @@ class TestOutgoingWebhookMessaging(ZulipTestCase):
|
||||||
full_name='Outgoing Webhook Bot',
|
full_name='Outgoing Webhook Bot',
|
||||||
email='whatever',
|
email='whatever',
|
||||||
realm=bot_owner.realm,
|
realm=bot_owner.realm,
|
||||||
short_name='',
|
|
||||||
password=None,
|
password=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -269,11 +269,12 @@ class RealmEmojiTest(ZulipTestCase):
|
||||||
# Test that two different realm emojis in two different realms but
|
# Test that two different realm emojis in two different realms but
|
||||||
# having same name can be administered independently.
|
# having same name can be administered independently.
|
||||||
realm_1 = do_create_realm('test_realm', 'test_realm')
|
realm_1 = do_create_realm('test_realm', 'test_realm')
|
||||||
emoji_author_1 = do_create_user('abc@example.com',
|
emoji_author_1 = do_create_user(
|
||||||
password='abc',
|
'abc@example.com',
|
||||||
realm=realm_1,
|
password='abc',
|
||||||
full_name='abc',
|
realm=realm_1,
|
||||||
short_name='abc')
|
full_name='abc',
|
||||||
|
)
|
||||||
self.create_test_emoji('test_emoji', emoji_author_1)
|
self.create_test_emoji('test_emoji', emoji_author_1)
|
||||||
|
|
||||||
emoji_author_2 = self.example_user('othello')
|
emoji_author_2 = self.example_user('othello')
|
||||||
|
|
|
@ -25,7 +25,6 @@ class TestServiceBotBasics(ZulipTestCase):
|
||||||
password="test",
|
password="test",
|
||||||
realm=get_realm("zulip"),
|
realm=get_realm("zulip"),
|
||||||
full_name="BarBot",
|
full_name="BarBot",
|
||||||
short_name='bb',
|
|
||||||
bot_type=UserProfile.OUTGOING_WEBHOOK_BOT,
|
bot_type=UserProfile.OUTGOING_WEBHOOK_BOT,
|
||||||
bot_owner=self.example_user('cordelia'),
|
bot_owner=self.example_user('cordelia'),
|
||||||
)
|
)
|
||||||
|
@ -170,14 +169,12 @@ class TestServiceBotStateHandler(ZulipTestCase):
|
||||||
password="test",
|
password="test",
|
||||||
realm=get_realm("zulip"),
|
realm=get_realm("zulip"),
|
||||||
full_name="EmbeddedBo1",
|
full_name="EmbeddedBo1",
|
||||||
short_name="embedded-bot-1",
|
|
||||||
bot_type=UserProfile.EMBEDDED_BOT,
|
bot_type=UserProfile.EMBEDDED_BOT,
|
||||||
bot_owner=self.user_profile)
|
bot_owner=self.user_profile)
|
||||||
self.second_bot_profile = do_create_user(email="embedded-bot-2@zulip.com",
|
self.second_bot_profile = do_create_user(email="embedded-bot-2@zulip.com",
|
||||||
password="test",
|
password="test",
|
||||||
realm=get_realm("zulip"),
|
realm=get_realm("zulip"),
|
||||||
full_name="EmbeddedBot2",
|
full_name="EmbeddedBot2",
|
||||||
short_name="embedded-bot-2",
|
|
||||||
bot_type=UserProfile.EMBEDDED_BOT,
|
bot_type=UserProfile.EMBEDDED_BOT,
|
||||||
bot_owner=self.user_profile)
|
bot_owner=self.user_profile)
|
||||||
|
|
||||||
|
@ -397,14 +394,12 @@ class TestServiceBotEventTriggers(ZulipTestCase):
|
||||||
password="test",
|
password="test",
|
||||||
realm=get_realm("zulip"),
|
realm=get_realm("zulip"),
|
||||||
full_name="FooBot",
|
full_name="FooBot",
|
||||||
short_name="foo-bot",
|
|
||||||
bot_type=UserProfile.OUTGOING_WEBHOOK_BOT,
|
bot_type=UserProfile.OUTGOING_WEBHOOK_BOT,
|
||||||
bot_owner=self.user_profile)
|
bot_owner=self.user_profile)
|
||||||
self.second_bot_profile = do_create_user(email="bar-bot@zulip.com",
|
self.second_bot_profile = do_create_user(email="bar-bot@zulip.com",
|
||||||
password="test",
|
password="test",
|
||||||
realm=get_realm("zulip"),
|
realm=get_realm("zulip"),
|
||||||
full_name="BarBot",
|
full_name="BarBot",
|
||||||
short_name="bar-bot",
|
|
||||||
bot_type=UserProfile.OUTGOING_WEBHOOK_BOT,
|
bot_type=UserProfile.OUTGOING_WEBHOOK_BOT,
|
||||||
bot_owner=self.user_profile)
|
bot_owner=self.user_profile)
|
||||||
|
|
||||||
|
|
|
@ -1579,7 +1579,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
|
||||||
'foo@zulip.com',
|
'foo@zulip.com',
|
||||||
'password',
|
'password',
|
||||||
self.user_profile.realm,
|
self.user_profile.realm,
|
||||||
'full name', 'short name',
|
'full name',
|
||||||
prereg_user=prereg_user,
|
prereg_user=prereg_user,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -3392,8 +3392,6 @@ class UserSignUpTest(InviteUserBase):
|
||||||
user_profile = UserProfile.objects.get(delivery_email=email)
|
user_profile = UserProfile.objects.get(delivery_email=email)
|
||||||
# Name comes from form which was set by LDAP.
|
# Name comes from form which was set by LDAP.
|
||||||
self.assertEqual(user_profile.full_name, full_name)
|
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',
|
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',
|
||||||
'zproject.backends.ZulipDummyBackend'))
|
'zproject.backends.ZulipDummyBackend'))
|
||||||
|
@ -3435,8 +3433,6 @@ class UserSignUpTest(InviteUserBase):
|
||||||
user_profile = UserProfile.objects.get(delivery_email=email)
|
user_profile = UserProfile.objects.get(delivery_email=email)
|
||||||
# Name comes from form which was set by LDAP.
|
# Name comes from form which was set by LDAP.
|
||||||
self.assertEqual(user_profile.full_name, "First Last")
|
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',
|
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',
|
||||||
'zproject.backends.ZulipDummyBackend'))
|
'zproject.backends.ZulipDummyBackend'))
|
||||||
|
@ -3472,7 +3468,6 @@ class UserSignUpTest(InviteUserBase):
|
||||||
user_profile = UserProfile.objects.get(delivery_email=email)
|
user_profile = UserProfile.objects.get(delivery_email=email)
|
||||||
# Name comes from form which was set by LDAP.
|
# Name comes from form which was set by LDAP.
|
||||||
self.assertEqual(user_profile.full_name, full_name)
|
self.assertEqual(user_profile.full_name, full_name)
|
||||||
self.assertEqual(user_profile.short_name, 'shortname')
|
|
||||||
|
|
||||||
# Test custom profile fields are properly synced.
|
# Test custom profile fields are properly synced.
|
||||||
phone_number_field = CustomProfileField.objects.get(realm=user_profile.realm, name='Phone number')
|
phone_number_field = CustomProfileField.objects.get(realm=user_profile.realm, name='Phone number')
|
||||||
|
|
|
@ -356,7 +356,6 @@ class SlackImporter(ZulipTestCase):
|
||||||
self.assertEqual(zerver_userprofile[3]['email'], 'matt.perry@foreignteam.slack.com')
|
self.assertEqual(zerver_userprofile[3]['email'], 'matt.perry@foreignteam.slack.com')
|
||||||
self.assertEqual(zerver_userprofile[3]['realm'], 1)
|
self.assertEqual(zerver_userprofile[3]['realm'], 1)
|
||||||
self.assertEqual(zerver_userprofile[3]['full_name'], 'Matt Perry')
|
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_mirror_dummy'], True)
|
||||||
self.assertEqual(zerver_userprofile[3]['is_api_super_user'], False)
|
self.assertEqual(zerver_userprofile[3]['is_api_super_user'], False)
|
||||||
|
|
||||||
|
|
|
@ -824,7 +824,6 @@ class AdminCreateUserTest(ZulipTestCase):
|
||||||
# Romeo is a newly registered user
|
# Romeo is a newly registered user
|
||||||
new_user = get_user_by_delivery_email('romeo@zulip.net', get_realm('zulip'))
|
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.full_name, 'Romeo Montague')
|
||||||
self.assertEqual(new_user.short_name, 'deprecated')
|
|
||||||
|
|
||||||
# Make sure the recipient field is set correctly.
|
# Make sure the recipient field is set correctly.
|
||||||
self.assertEqual(new_user.recipient, Recipient.objects.get(type=Recipient.PERSONAL,
|
self.assertEqual(new_user.recipient, Recipient.objects.get(type=Recipient.PERSONAL,
|
||||||
|
@ -1442,7 +1441,6 @@ class RecipientInfoTest(ZulipTestCase):
|
||||||
password='',
|
password='',
|
||||||
realm=realm,
|
realm=realm,
|
||||||
full_name='',
|
full_name='',
|
||||||
short_name='',
|
|
||||||
bot_type=UserProfile.EMBEDDED_BOT,
|
bot_type=UserProfile.EMBEDDED_BOT,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1462,7 +1460,6 @@ class RecipientInfoTest(ZulipTestCase):
|
||||||
password='',
|
password='',
|
||||||
realm=realm,
|
realm=realm,
|
||||||
full_name='',
|
full_name='',
|
||||||
short_name='',
|
|
||||||
bot_type=UserProfile.DEFAULT_BOT,
|
bot_type=UserProfile.DEFAULT_BOT,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,6 @@ from zerver.models import (
|
||||||
Realm,
|
Realm,
|
||||||
Stream,
|
Stream,
|
||||||
UserProfile,
|
UserProfile,
|
||||||
email_to_username,
|
|
||||||
get_default_stream_groups,
|
get_default_stream_groups,
|
||||||
get_realm,
|
get_realm,
|
||||||
get_source_profile,
|
get_source_profile,
|
||||||
|
@ -286,7 +285,6 @@ def accounts_register(request: HttpRequest) -> HttpResponse:
|
||||||
assert(realm is not None)
|
assert(realm is not None)
|
||||||
|
|
||||||
full_name = form.cleaned_data['full_name']
|
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_group_names = request.POST.getlist('default_stream_group')
|
||||||
default_stream_groups = lookup_default_stream_groups(default_stream_group_names, realm)
|
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.
|
# make it respect invited_as_admin / is_realm_admin.
|
||||||
|
|
||||||
if user_profile is None:
|
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,
|
prereg_user=prereg_user,
|
||||||
role=role,
|
role=role,
|
||||||
tos_version=settings.TOS_VERSION,
|
tos_version=settings.TOS_VERSION,
|
||||||
|
|
|
@ -382,7 +382,6 @@ def add_bot_backend(
|
||||||
|
|
||||||
bot_profile = do_create_user(email=email, password=None,
|
bot_profile = do_create_user(email=email, password=None,
|
||||||
realm=user_profile.realm, full_name=full_name,
|
realm=user_profile.realm, full_name=full_name,
|
||||||
short_name=short_name,
|
|
||||||
bot_type=bot_type,
|
bot_type=bot_type,
|
||||||
bot_owner=user_profile,
|
bot_owner=user_profile,
|
||||||
avatar_source=avatar_source,
|
avatar_source=avatar_source,
|
||||||
|
@ -522,9 +521,7 @@ def create_user_backend(
|
||||||
if not check_password_strength(password):
|
if not check_password_strength(password):
|
||||||
return json_error(PASSWORD_TOO_WEAK_ERROR)
|
return json_error(PASSWORD_TOO_WEAK_ERROR)
|
||||||
|
|
||||||
short_name = 'deprecated'
|
do_create_user(email, password, realm, full_name, acting_user=user_profile)
|
||||||
|
|
||||||
do_create_user(email, password, realm, full_name, short_name, acting_user=user_profile)
|
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
def get_profile_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
def get_profile_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
||||||
|
|
|
@ -45,11 +45,11 @@ From image editing program:
|
||||||
stream = ensure_stream(realm, 'zulip features', acting_user=None)
|
stream = ensure_stream(realm, 'zulip features', acting_user=None)
|
||||||
|
|
||||||
UserProfile.objects.filter(email__contains='stage').delete()
|
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')
|
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')
|
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)
|
bot_type=UserProfile.DEFAULT_BOT, acting_user=None)
|
||||||
self.set_avatar(twitter_bot, 'static/images/features/twitter.png')
|
self.set_avatar(twitter_bot, 'static/images/features/twitter.png')
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,14 @@ class Command(ZulipBaseCommand):
|
||||||
|
|
||||||
name = '{:02}-user'.format(
|
name = '{:02}-user'.format(
|
||||||
UserProfile.objects.filter(email__contains='user@').count())
|
UserProfile.objects.filter(email__contains='user@').count())
|
||||||
user = do_create_user(f'{name}@{string_id}.zulip.com',
|
user = do_create_user(
|
||||||
'password', realm, name, name, role=UserProfile.ROLE_REALM_ADMINISTRATOR, acting_user=None)
|
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
|
assert realm.signup_notifications_stream is not None
|
||||||
bulk_add_subscriptions([realm.signup_notifications_stream], [user])
|
bulk_add_subscriptions([realm.signup_notifications_stream], [user])
|
||||||
|
|
||||||
|
|
|
@ -30,4 +30,4 @@ and will otherwise fall back to the zulip realm."""
|
||||||
domain = realm.string_id + '.zulip.com'
|
domain = realm.string_id + '.zulip.com'
|
||||||
|
|
||||||
name = '{:02}-user'.format(UserProfile.objects.filter(email__contains='user@').count())
|
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)
|
||||||
|
|
|
@ -749,7 +749,7 @@ class ZulipLDAPAuthBackend(ZulipLDAPAuthBackendBase):
|
||||||
# the LDAP flow.
|
# the LDAP flow.
|
||||||
opts['default_stream_groups'] = []
|
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_avatar_from_ldap(user_profile, ldap_user)
|
||||||
self.sync_custom_profile_fields_from_ldap(user_profile, ldap_user)
|
self.sync_custom_profile_fields_from_ldap(user_profile, ldap_user)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue