do_make_stream_web_public: Send update to client.

Send update event to client after a stream is made web public.

This has been documented in the API documentation since feature level
73; previously the value was always false.
This commit is contained in:
Aman Agrawal
2020-11-10 18:41:19 +05:30
committed by Tim Abbott
parent 5138652810
commit 233d250eff
3 changed files with 39 additions and 4 deletions

View File

@@ -4822,6 +4822,21 @@ def do_make_stream_web_public(stream: Stream) -> None:
stream.history_public_to_subscribers = True
stream.save(update_fields=["invite_only", "history_public_to_subscribers", "is_web_public"])
# We reuse "invite_only" stream update API route here because
# both are similar events and similar UI updates will be required
# by the client to update this property for the user.
event = dict(
op="update",
type="stream",
property="invite_only",
value=False,
history_public_to_subscribers=True,
is_web_public=True,
stream_id=stream.id,
name=stream.name,
)
send_event(stream.realm, event, can_access_stream_user_ids(stream))
def do_change_stream_permission(
stream: Stream,

View File

@@ -887,6 +887,12 @@ def apply_event(
obj[event["property"]] = event["value"]
if event["property"] == "description":
obj["rendered_description"] = event["rendered_description"]
if event.get("history_public_to_subscribers") is not None:
obj["history_public_to_subscribers"] = event[
"history_public_to_subscribers"
]
if event.get("is_web_public") is not None:
obj["is_web_public"] = event["is_web_public"]
# Also update the pure streams data
if "streams" in state:
for stream in state["streams"]:
@@ -896,6 +902,13 @@ def apply_event(
stream[prop] = event["value"]
if prop == "description":
stream["rendered_description"] = event["rendered_description"]
if event.get("history_public_to_subscribers") is not None:
stream["history_public_to_subscribers"] = event[
"history_public_to_subscribers"
]
if event.get("is_web_public") is not None:
stream["is_web_public"] = event["is_web_public"]
elif event["type"] == "default_streams":
state["realm_default_streams"] = event["default_streams"]
elif event["type"] == "default_stream_groups":

View File

@@ -42,8 +42,8 @@ from zerver.lib.actions import (
do_change_plan_type,
do_change_realm_domain,
do_change_stream_description,
do_change_stream_invite_only,
do_change_stream_message_retention_days,
do_change_stream_permission,
do_change_stream_post_policy,
do_change_subscription_property,
do_change_user_delivery_email,
@@ -2416,9 +2416,16 @@ class SubscribeActionTest(BaseAction):
events = self.verify_action(action, include_subscribers=include_subscribers)
check_stream_update("events[0]", events[0])
# Update stream privacy
action = lambda: do_change_stream_invite_only(
stream, True, history_public_to_subscribers=True
# Update stream privacy - make stream web public
action = lambda: do_change_stream_permission(
stream, invite_only=False, history_public_to_subscribers=True, is_web_public=True
)
events = self.verify_action(action, include_subscribers=include_subscribers)
check_stream_update("events[0]", events[0])
# Update stream privacy - make stream private
action = lambda: do_change_stream_permission(
stream, invite_only=True, history_public_to_subscribers=True, is_web_public=False
)
events = self.verify_action(action, include_subscribers=include_subscribers)
check_stream_update("events[0]", events[0])