mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
markdown: Pass realm down into render_stream_description.
This guarantees that the Realm is always non-None when we hit the codepath is_static_or_current_realm_url via do_change_stream_description, so that we can properly skip rewritting some images. Fixes #19405 Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
committed by
Tim Abbott
parent
d02b1f0ae6
commit
da9ad7c3a7
@@ -172,7 +172,7 @@ def do_update_user_custom_profile_data_if_changed(
|
||||
field_value.value = custom_profile_field_value_string
|
||||
if field_value.field.is_renderable():
|
||||
field_value.rendered_value = render_stream_description(
|
||||
custom_profile_field_value_string
|
||||
custom_profile_field_value_string, user_profile.realm
|
||||
)
|
||||
field_value.save(update_fields=["value", "rendered_value"])
|
||||
else:
|
||||
|
||||
@@ -1190,7 +1190,7 @@ def do_change_stream_description(
|
||||
|
||||
with transaction.atomic():
|
||||
stream.description = new_description
|
||||
stream.rendered_description = render_stream_description(new_description)
|
||||
stream.rendered_description = render_stream_description(new_description, stream.realm)
|
||||
stream.save(update_fields=["description", "rendered_description"])
|
||||
RealmAuditLog.objects.create(
|
||||
realm=stream.realm,
|
||||
|
||||
@@ -190,7 +190,7 @@ def bulk_create_streams(realm: Realm, stream_dict: Dict[str, Dict[str, Any]]) ->
|
||||
realm=realm,
|
||||
name=name,
|
||||
description=options["description"],
|
||||
rendered_description=render_stream_description(options["description"]),
|
||||
rendered_description=render_stream_description(options["description"], realm),
|
||||
invite_only=options.get("invite_only", False),
|
||||
stream_post_policy=options.get(
|
||||
"stream_post_policy", Stream.STREAM_POST_POLICY_EVERYONE
|
||||
|
||||
@@ -993,7 +993,7 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int = 1) -> Rea
|
||||
)
|
||||
# Handle rendering of stream descriptions for import from non-Zulip
|
||||
for stream in data["zerver_stream"]:
|
||||
stream["rendered_description"] = render_stream_description(stream["description"])
|
||||
stream["rendered_description"] = render_stream_description(stream["description"], realm)
|
||||
bulk_import_model(data, Stream)
|
||||
|
||||
realm.notifications_stream_id = notifications_stream_id
|
||||
|
||||
@@ -106,8 +106,8 @@ def get_default_value_for_history_public_to_subscribers(
|
||||
return history_public_to_subscribers
|
||||
|
||||
|
||||
def render_stream_description(text: str) -> str:
|
||||
return markdown_convert(text, no_previews=True).rendered_content
|
||||
def render_stream_description(text: str, realm: Realm) -> str:
|
||||
return markdown_convert(text, message_realm=realm, no_previews=True).rendered_content
|
||||
|
||||
|
||||
def send_stream_creation_event(stream: Stream, user_ids: List[int]) -> None:
|
||||
@@ -155,7 +155,7 @@ def create_stream_if_needed(
|
||||
recipient = Recipient.objects.create(type_id=stream.id, type=Recipient.STREAM)
|
||||
|
||||
stream.recipient = recipient
|
||||
stream.rendered_description = render_stream_description(stream_description)
|
||||
stream.rendered_description = render_stream_description(stream_description, realm)
|
||||
stream.save(update_fields=["recipient", "rendered_description"])
|
||||
|
||||
event_time = timezone_now()
|
||||
|
||||
@@ -12,7 +12,7 @@ def render_all_stream_descriptions(
|
||||
Stream = apps.get_model("zerver", "Stream")
|
||||
all_streams = Stream.objects.exclude(description="")
|
||||
for stream in all_streams:
|
||||
stream.rendered_description = render_stream_description(stream.description)
|
||||
stream.rendered_description = render_stream_description(stream.description, stream.realm)
|
||||
stream.save(update_fields=["rendered_description"])
|
||||
|
||||
|
||||
|
||||
@@ -4223,7 +4223,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
||||
events: List[Mapping[str, Any]] = []
|
||||
flush_per_request_caches()
|
||||
with self.tornado_redirected_to_list(events, expected_num_events=5):
|
||||
with self.assert_database_query_count(37):
|
||||
with self.assert_database_query_count(36):
|
||||
self.common_subscribe_to_streams(
|
||||
self.test_user,
|
||||
streams_to_sub,
|
||||
@@ -5095,7 +5095,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
||||
]
|
||||
|
||||
# Test creating a public stream when realm does not have a notification stream.
|
||||
with self.assert_database_query_count(37):
|
||||
with self.assert_database_query_count(36):
|
||||
self.common_subscribe_to_streams(
|
||||
self.test_user,
|
||||
[new_streams[0]],
|
||||
@@ -5103,7 +5103,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
||||
)
|
||||
|
||||
# Test creating private stream.
|
||||
with self.assert_database_query_count(36):
|
||||
with self.assert_database_query_count(35):
|
||||
self.common_subscribe_to_streams(
|
||||
self.test_user,
|
||||
[new_streams[1]],
|
||||
@@ -5115,7 +5115,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
||||
notifications_stream = get_stream(self.streams[0], self.test_realm)
|
||||
self.test_realm.notifications_stream_id = notifications_stream.id
|
||||
self.test_realm.save()
|
||||
with self.assert_database_query_count(45):
|
||||
with self.assert_database_query_count(44):
|
||||
self.common_subscribe_to_streams(
|
||||
self.test_user,
|
||||
[new_streams[2]],
|
||||
|
||||
Reference in New Issue
Block a user