Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
streams: Add stream_to_dict method.
Sahil Batra8c9ad30411fa
diff --git a/zerver/actions/streams.py b/zerver/actions/streams.pyindex fd66606e276..1a6861fd65c 100644--- a/zerver/actions/streams.py+++ b/zerver/actions/streams.py@@ -44,6 +44,7 @@ from zerver.lib.streams import (get_stream_permission_policy_name,render_stream_description,send_stream_creation_event,+ stream_to_dict,)from zerver.lib.subscription_info import get_subscribers_queryfrom zerver.lib.types import APISubscriptionDict@@ -117,7 +118,7 @@ def do_deactivate_stream(stream: Stream, *, acting_user: Optional[UserProfile])for group in default_stream_groups_for_stream:do_remove_streams_from_default_stream_group(stream.realm, group, [stream])- stream_dict = stream.to_dict()+ stream_dict = stream_to_dict(stream)stream_dict.update(dict(name=old_name, invite_only=was_invite_only))event = dict(type="stream", op="delete", streams=[stream_dict])send_event_on_commit(stream.realm, event, affected_user_ids)@@ -354,7 +355,7 @@ def send_subscription_add_events(stream = sub_info.streamstream_info = stream_info_dict[stream.id]subscription = sub_info.sub- stream_dict = stream.to_dict()+ stream_dict = stream_to_dict(stream)# This is verbose as we cannot unpack existing TypedDict# to initialize another TypedDict while making mypy happy.# https://github.com/python/mypy/issues/5382diff --git a/zerver/lib/streams.py b/zerver/lib/streams.pyindex 522f4cffed7..67e4fb3e6f7 100644--- a/zerver/lib/streams.py+++ b/zerver/lib/streams.py@@ -17,6 +17,7 @@ from zerver.lib.stream_subscription import (get_subscribed_stream_ids_for_user,)from zerver.lib.string_validation import check_stream_name+from zerver.lib.timestamp import datetime_to_timestampfrom zerver.lib.types import APIStreamDictfrom zerver.lib.user_groups import is_user_in_groupfrom zerver.models import (@@ -111,7 +112,7 @@ def render_stream_description(text: str, realm: Realm) -> str:def send_stream_creation_event(realm: Realm, stream: Stream, user_ids: List[int]) -> None:- event = dict(type="stream", op="create", streams=[stream.to_dict()])+ event = dict(type="stream", op="create", streams=[stream_to_dict(stream)])send_event(realm, event, user_ids)@@ -825,6 +826,24 @@ def get_occupied_streams(realm: Realm) -> QuerySet[Stream]:return occupied_streams+def stream_to_dict(stream: Stream) -> APIStreamDict:+ return APIStreamDict(+ can_remove_subscribers_group=stream.can_remove_subscribers_group_id,+ date_created=datetime_to_timestamp(stream.date_created),+ description=stream.description,+ first_message_id=stream.first_message_id,+ history_public_to_subscribers=stream.history_public_to_subscribers,+ invite_only=stream.invite_only,+ is_web_public=stream.is_web_public,+ message_retention_days=stream.message_retention_days,+ name=stream.name,+ rendered_description=stream.rendered_description,+ stream_id=stream.id,+ stream_post_policy=stream.stream_post_policy,+ is_announcement_only=stream.stream_post_policy == Stream.STREAM_POST_POLICY_ADMINS,+ )++def get_web_public_streams(realm: Realm) -> List[APIStreamDict]: # nocoveragequery = get_web_public_streams_queryset(realm)streams = Stream.get_client_data(query)diff --git a/zerver/views/streams.py b/zerver/views/streams.pyindex df23804cd04..839917ceb26 100644--- a/zerver/views/streams.py+++ b/zerver/views/streams.py@@ -70,6 +70,7 @@ from zerver.lib.streams import (filter_stream_authorization,get_stream_permission_policy_name,list_to_streams,+ stream_to_dict,)from zerver.lib.string_validation import check_stream_namefrom zerver.lib.subscription_info import gather_subscriptions@@ -873,7 +874,7 @@ def get_stream_backend(stream_id: int,) -> HttpResponse:(stream, sub) = access_stream_by_id(user_profile, stream_id, allow_realm_admin=True)- return json_success(request, data={"stream": stream.to_dict()})+ return json_success(request, data={"stream": stream_to_dict(stream)})@has_request_variables