import: Replace data-stream-id in rendered_content.

See the data-user-id commit for details.
This commit is contained in:
Vishnu Ks 2019-05-28 11:06:48 +00:00 committed by Tim Abbott
parent cb5b3f347b
commit ce1d6044db
2 changed files with 20 additions and 0 deletions

View File

@ -253,6 +253,15 @@ def fix_message_rendered_content(realm: Realm,
if old_user_id in user_id_map:
mention["data-user-id"] = str(user_id_map[old_user_id])
message['rendered_content'] = str(soup)
stream_mentions = soup.findAll("a", {"class": "stream"})
if len(stream_mentions) != 0:
stream_id_map = ID_MAP["stream"]
for mention in stream_mentions:
old_stream_id = int(mention["data-stream-id"])
if old_stream_id in stream_id_map:
mention["data-stream-id"] = str(stream_id_map[old_stream_id])
message['rendered_content'] = str(soup)
continue
message_object = FakeMessage()

View File

@ -655,6 +655,9 @@ class ImportExportTest(ZulipTestCase):
user_mention_message = '@**King Hamlet** Hello'
self.send_stream_message(self.example_email("iago"), "Verona", user_mention_message)
stream_mention_message = 'Subscribe to #**Denmark**'
self.send_stream_message(self.example_email("hamlet"), "Verona", stream_mention_message)
# data to test import of hotspots
sample_user = self.example_user('hamlet')
@ -896,6 +899,14 @@ class ImportExportTest(ZulipTestCase):
assert_realm_values(get_user_mention)
def get_stream_mention(r: Realm) -> Set[Any]:
mentioned_stream = get_stream(u'Denmark', r)
data_stream_id = 'data-stream-id="{}"'.format(mentioned_stream.id)
mention_message = get_stream_messages(r).get(rendered_content__contains=data_stream_id)
return mention_message.content
assert_realm_values(get_stream_mention)
def test_import_files_from_local(self) -> None:
realm = Realm.objects.get(string_id='zulip')