markdown: Fix stream description with topic permalink not rendered.

Previously, when description for a channel -- either during its
creating or when we change its description contained a topic
permalink (through #-mention), then it was not rendered. This
is because of lack of authorization to access the channel.

This is fixed by passing the acting_user through the methods
which update or add the description, so that permissions
of the acting_user could be used to determine whether to
render the #-mention in stream description or not.
This commit is contained in:
roanster007
2025-02-13 00:38:12 +05:30
committed by Tim Abbott
parent 4789de2e96
commit c562503089
3 changed files with 81 additions and 4 deletions

View File

@@ -128,10 +128,14 @@ def get_default_value_for_history_public_to_subscribers(
return history_public_to_subscribers
def render_stream_description(text: str, realm: Realm) -> str:
def render_stream_description(
text: str, realm: Realm, *, acting_user: UserProfile | None = None
) -> str:
from zerver.lib.markdown import markdown_convert
return markdown_convert(text, message_realm=realm, no_previews=True).rendered_content
return markdown_convert(
text, message_realm=realm, no_previews=True, acting_user=acting_user
).rendered_content
def send_stream_creation_event(
@@ -258,7 +262,9 @@ 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, realm)
stream.rendered_description = render_stream_description(
stream_description, realm, acting_user=acting_user
)
stream.save(update_fields=["recipient", "rendered_description"])
event_time = timezone_now()