mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 19:31:58 +00:00
management commands: Fix incorrect use of user_profile.email.
All of these management commands should be interacting with .delivery_email; this results in buggy behavior with EMAIL_ADDRESS_VISIBILITY_ADMINS.
This commit is contained in:
@@ -33,4 +33,4 @@ class Command(ZulipBaseCommand):
|
|||||||
was_there_already = user_profile.id in {tup[0].id for tup in already_subscribed}
|
was_there_already = user_profile.id in {tup[0].id for tup in already_subscribed}
|
||||||
print("%s %s to %s" % (
|
print("%s %s to %s" % (
|
||||||
"Already subscribed" if was_there_already else "Subscribed",
|
"Already subscribed" if was_there_already else "Subscribed",
|
||||||
user_profile.email, stream_name))
|
user_profile.delivery_email, stream_name))
|
||||||
|
|||||||
@@ -24,14 +24,14 @@ class Command(ZulipBaseCommand):
|
|||||||
user_profile = self.get_user(options['email'], realm)
|
user_profile = self.get_user(options['email'], realm)
|
||||||
|
|
||||||
print("Deactivating %s (%s) - %s" % (user_profile.full_name,
|
print("Deactivating %s (%s) - %s" % (user_profile.full_name,
|
||||||
user_profile.email,
|
user_profile.delivery_email,
|
||||||
user_profile.realm.string_id))
|
user_profile.realm.string_id))
|
||||||
print("%s has the following active sessions:" % (user_profile.email,))
|
print("%s has the following active sessions:" % (user_profile.delivery_email,))
|
||||||
for session in user_sessions(user_profile):
|
for session in user_sessions(user_profile):
|
||||||
print(session.expire_date, session.get_decoded())
|
print(session.expire_date, session.get_decoded())
|
||||||
print("")
|
print("")
|
||||||
print("%s has %s active bots that will also be deactivated." % (
|
print("%s has %s active bots that will also be deactivated." % (
|
||||||
user_profile.email,
|
user_profile.delivery_email,
|
||||||
UserProfile.objects.filter(
|
UserProfile.objects.filter(
|
||||||
is_bot=True, is_active=True, bot_owner=user_profile
|
is_bot=True, is_active=True, bot_owner=user_profile
|
||||||
).count()
|
).count()
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class Command(ZulipBaseCommand):
|
|||||||
if os.path.exists(output_dir):
|
if os.path.exists(output_dir):
|
||||||
shutil.rmtree(output_dir)
|
shutil.rmtree(output_dir)
|
||||||
os.makedirs(output_dir)
|
os.makedirs(output_dir)
|
||||||
print("Exporting user %s" % (user_profile.email,))
|
print("Exporting user %s" % (user_profile.delivery_email,))
|
||||||
do_export_user(user_profile, output_dir)
|
do_export_user(user_profile, output_dir)
|
||||||
print("Finished exporting to %s; tarring" % (output_dir,))
|
print("Finished exporting to %s; tarring" % (output_dir,))
|
||||||
tarball_path = output_dir.rstrip('/') + '.tar.gz'
|
tarball_path = output_dir.rstrip('/') + '.tar.gz'
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ class Command(ZulipBaseCommand):
|
|||||||
|
|
||||||
for user_profile in user_profiles:
|
for user_profile in user_profiles:
|
||||||
if user_profile in not_subscribed_users:
|
if user_profile in not_subscribed_users:
|
||||||
print("%s was not subscribed" % (user_profile.email,))
|
print("%s was not subscribed" % (user_profile.delivery_email,))
|
||||||
else:
|
else:
|
||||||
print("Removed %s from %s" % (user_profile.email, stream_name))
|
print("Removed %s from %s" % (user_profile.delivery_email, stream_name))
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class Command(ZulipBaseCommand):
|
|||||||
"""
|
"""
|
||||||
for user_profile in users:
|
for user_profile in users:
|
||||||
context = {
|
context = {
|
||||||
'email': user_profile.email,
|
'email': user_profile.delivery_email,
|
||||||
'reset_url': generate_password_reset_url(user_profile, default_token_generator),
|
'reset_url': generate_password_reset_url(user_profile, default_token_generator),
|
||||||
'realm_uri': user_profile.realm.uri,
|
'realm_uri': user_profile.realm.uri,
|
||||||
'realm_name': user_profile.realm.name,
|
'realm_name': user_profile.realm.name,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class Command(ZulipBaseCommand):
|
|||||||
if users:
|
if users:
|
||||||
print('Admins:\n')
|
print('Admins:\n')
|
||||||
for user in users:
|
for user in users:
|
||||||
print(' %s (%s)' % (user.email, user.full_name))
|
print(' %s (%s)' % (user.delivery_email, user.full_name))
|
||||||
else:
|
else:
|
||||||
print('There are no admins for this realm!')
|
print('There are no admins for this realm!')
|
||||||
|
|
||||||
|
|||||||
@@ -12,12 +12,13 @@ from zerver.models import Realm, UserProfile
|
|||||||
|
|
||||||
def get_users_from_emails(emails: List[str],
|
def get_users_from_emails(emails: List[str],
|
||||||
filter_kwargs: Dict[str, Realm]) -> List[UserProfile]:
|
filter_kwargs: Dict[str, Realm]) -> List[UserProfile]:
|
||||||
|
# Bug: Ideally, this would be case-insensitive like our other email queries.
|
||||||
users = UserProfile.objects.filter(
|
users = UserProfile.objects.filter(
|
||||||
email__in=emails,
|
delivery_email__in=emails,
|
||||||
**filter_kwargs)
|
**filter_kwargs)
|
||||||
|
|
||||||
if len(users) != len(emails):
|
if len(users) != len(emails):
|
||||||
user_emails_found = {user.email for user in users}
|
user_emails_found = {user.delivery_email for user in users}
|
||||||
user_emails_not_found = '\n'.join(set(emails) - user_emails_found)
|
user_emails_not_found = '\n'.join(set(emails) - user_emails_found)
|
||||||
raise CommandError('Users with the following emails were not found:\n\n%s\n\n'
|
raise CommandError('Users with the following emails were not found:\n\n%s\n\n'
|
||||||
'Check if they are correct.' % (user_emails_not_found,))
|
'Check if they are correct.' % (user_emails_not_found,))
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ def sync_ldap_user_data(user_profiles: List[UserProfile]) -> None:
|
|||||||
try:
|
try:
|
||||||
sync_user_from_ldap(u, logger)
|
sync_user_from_ldap(u, logger)
|
||||||
except ZulipLDAPException as e:
|
except ZulipLDAPException as e:
|
||||||
logger.error("Error attempting to update user %s:" % (u.email,))
|
logger.error("Error attempting to update user %s:" % (u.delivery_email,))
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
logger.info("Finished update.")
|
logger.info("Finished update.")
|
||||||
|
|
||||||
|
|||||||
@@ -26,4 +26,4 @@ class Command(ZulipBaseCommand):
|
|||||||
else:
|
else:
|
||||||
already_disabled_prefix = "(already off) "
|
already_disabled_prefix = "(already off) "
|
||||||
print("%s%s <%s>" % (already_disabled_prefix, user_profile.full_name,
|
print("%s%s <%s>" % (already_disabled_prefix, user_profile.full_name,
|
||||||
user_profile.email))
|
user_profile.delivery_email))
|
||||||
|
|||||||
Reference in New Issue
Block a user