import: Fix handling of legacy and wildcard mentions.

Our recently-added code for rewriting user IDs on data import didn't
correctly handle wildcard mentions and mentions generated by very old
versions of Zulip (pre data-user-id).
This commit is contained in:
Tim Abbott 2019-06-18 10:35:01 -07:00
parent 2538f84447
commit 649e363ee3
1 changed files with 8 additions and 0 deletions

View File

@ -249,6 +249,14 @@ def fix_message_rendered_content(realm: Realm,
if len(user_mentions) != 0:
user_id_map = ID_MAP["user_profile"]
for mention in user_mentions:
if 'data-user-id' not in mention:
# Legacy mentions don't have a data-user-id
# field; we should just import them
# unmodified.
continue
if mention['data-user-id'] == "*":
# No rewriting is required for wildcard mentions
continue
old_user_id = int(mention["data-user-id"])
if old_user_id in user_id_map:
mention["data-user-id"] = str(user_id_map[old_user_id])