export: Canonicalize the email of cross realm bot to default value.

Fixes #13496
This commit is contained in:
Vishnu KS 2020-02-18 16:59:13 +05:30 committed by Tim Abbott
parent fd2d642f95
commit 51f5701879
2 changed files with 18 additions and 12 deletions

View File

@ -832,18 +832,28 @@ def fetch_user_profile_cross_realm(response: TableData, config: Config, context:
realm = context['realm']
response['zerver_userprofile_crossrealm'] = []
bot_name_to_default_email = {
"NOTIFICATION_BOT": "notification-bot@zulip.com",
"EMAIL_GATEWAY_BOT": "emailgateway@zulip.com",
"WELCOME_BOT": "welcome-bot@zulip.com",
}
if realm.string_id == settings.SYSTEM_BOT_REALM:
return
for bot_user in [
get_system_bot(settings.NOTIFICATION_BOT),
get_system_bot(settings.EMAIL_GATEWAY_BOT),
get_system_bot(settings.WELCOME_BOT),
]:
recipient_id = Recipient.objects.get(type_id=bot_user.id, type=Recipient.PERSONAL).id
for bot in settings.INTERNAL_BOTS:
bot_name = bot["var_name"]
if bot_name not in bot_name_to_default_email:
continue
bot_email = bot["email_template"] % (settings.INTERNAL_BOT_DOMAIN,)
bot_default_email = bot_name_to_default_email[bot_name]
bot_user_id = get_system_bot(bot_email).id
recipient_id = Recipient.objects.get(type_id=bot_user_id, type=Recipient.PERSONAL).id
response['zerver_userprofile_crossrealm'].append(dict(
email=bot_user.email,
id=bot_user.id,
email=bot_default_email,
id=bot_user_id,
recipient_id=recipient_id,
))

View File

@ -825,10 +825,6 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int=1) -> Realm
# Remap the user IDs for notification_bot and friends to their
# appropriate IDs on this server
for item in data['zerver_userprofile_crossrealm']:
if item['email'].startswith("emailgateway@"):
# The email gateway bot's email is customized to a
# different domain on some servers.
item['email'] = settings.EMAIL_GATEWAY_BOT
logging.info("Adding to ID map: %s %s" % (item['id'], get_system_bot(item['email']).id))
new_user_id = get_system_bot(item['email']).id
update_id_map(table='user_profile', old_id=item['id'], new_id=new_user_id)