streams: Disable inline URL preview when rendering stream descriptions.

We want to use the baseline features of bugdown, but not fancy things
like inline URL previews, since the whole structure of stream
descriptions is to have a single-line thing supporting some
formatting.

The migration part of this change fixes a bug encountered by some
organizations upgrading from older versions of Zulip.
This commit is contained in:
Tim Abbott
2019-02-28 17:00:40 -08:00
parent d6c09eac51
commit de65a04ae0
5 changed files with 17 additions and 5 deletions

View File

@@ -1751,7 +1751,7 @@ def create_stream_if_needed(realm: Realm,
)
if created:
stream.rendered_description = bugdown_convert(stream.description)
stream.rendered_description = bugdown_convert(stream.description, no_previews=True)
stream.save(update_fields=["rendered_description"])
Recipient.objects.create(type_id=stream.id, type=Recipient.STREAM)
if stream.is_public():
@@ -3505,7 +3505,7 @@ def do_rename_stream(stream: Stream,
def do_change_stream_description(stream: Stream, new_description: str) -> None:
stream.description = new_description
stream.rendered_description = bugdown_convert(new_description)
stream.rendered_description = bugdown_convert(new_description, no_previews=True)
stream.save(update_fields=['description', 'rendered_description'])
event = dict(

View File

@@ -80,7 +80,7 @@ def bulk_create_streams(realm: Realm,
realm=realm,
name=name,
description=options["description"],
rendered_description=bugdown_convert(options["description"]),
rendered_description=bugdown_convert(options["description"], no_previews=True),
invite_only=options.get("invite_only", False),
is_announcement_only=options.get("is_announcement_only", False),
history_public_to_subscribers=options["history_public_to_subscribers"],

View File

@@ -746,7 +746,8 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int=1) -> Realm
for stream in data['zerver_stream']:
if 'rendered_description' in stream:
continue
stream["rendered_description"] = bugdown_convert(stream["description"])
stream["rendered_description"] = bugdown_convert(stream["description"],
no_previews=True)
bulk_import_model(data, Stream)
realm.notifications_stream_id = notifications_stream_id

View File

@@ -12,7 +12,8 @@ def render_all_stream_descriptions(apps: StateApps, schema_editor: DatabaseSchem
Stream = apps.get_model('zerver', 'Stream')
all_streams = Stream.objects.exclude(description='')
for stream in all_streams:
stream.rendered_description = bugdown_convert(stream.description)
stream.rendered_description = bugdown_convert(stream.description,
no_previews=True)
stream.save(update_fields=["rendered_description"])

View File

@@ -708,6 +708,16 @@ class StreamAdminTest(ZulipTestCase):
stream = get_stream('stream_name1', realm)
self.assertEqual(stream.description, 'a multi line description')
# Verify that we don't render inline URL previews in this code path.
with self.settings(INLINE_URL_EMBED_PREVIEW=True):
result = self.client_patch('/json/streams/%d' % (stream_id,),
{'description': ujson.dumps('See https://zulipchat.com/team')})
self.assert_json_success(result)
stream = get_stream('stream_name1', realm)
self.assertEqual(stream.rendered_description,
'<p>See <a href="https://zulipchat.com/team" target="_blank" '
'title="https://zulipchat.com/team">https://zulipchat.com/team</a></p>')
def test_change_stream_description_requires_realm_admin(self) -> None:
user_profile = self.example_user('hamlet')
email = user_profile.email