From 51f5701879b1c2cdbe45dcc60df259c59fc852ab Mon Sep 17 00:00:00 2001 From: Vishnu KS Date: Tue, 18 Feb 2020 16:59:13 +0530 Subject: [PATCH] export: Canonicalize the email of cross realm bot to default value. Fixes #13496 --- zerver/lib/export.py | 26 ++++++++++++++++++-------- zerver/lib/import_realm.py | 4 ---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/zerver/lib/export.py b/zerver/lib/export.py index 42b1dfdffe..6ba0c06192 100644 --- a/zerver/lib/export.py +++ b/zerver/lib/export.py @@ -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, )) diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.py index 870ea4fb6e..34bcd29784 100644 --- a/zerver/lib/import_realm.py +++ b/zerver/lib/import_realm.py @@ -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)