From cba766f66f936a6bf0562cac2799d8221b89be58 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Tue, 10 Nov 2020 18:37:41 +0530 Subject: [PATCH] do_make_stream_web_public: Update all affected fields. Convert this function that absolutely makes a stream web public. We already have do_change_stream_invite_only to convert streams to public and private streams. We also update all the fields that should be set when a stream is made web public. --- zerver/lib/actions.py | 8 +++++--- zerver/tests/test_archive.py | 10 +++++----- zerver/tests/test_reactions.py | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 3bb5892f83..e6c182d3f5 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -4569,9 +4569,11 @@ def do_change_stream_invite_only( send_event(stream.realm, event, can_access_stream_user_ids(stream)) -def do_change_stream_web_public(stream: Stream, is_web_public: bool) -> None: - stream.is_web_public = is_web_public - stream.save(update_fields=["is_web_public"]) +def do_make_stream_web_public(stream: Stream) -> None: + stream.is_web_public = True + stream.invite_only = False + stream.history_public_to_subscribers = True + stream.save(update_fields=["invite_only", "history_public_to_subscribers", "is_web_public"]) def do_change_stream_post_policy(stream: Stream, stream_post_policy: int) -> None: diff --git a/zerver/tests/test_archive.py b/zerver/tests/test_archive.py index 3f6393ac33..a6037ec866 100644 --- a/zerver/tests/test_archive.py +++ b/zerver/tests/test_archive.py @@ -1,8 +1,8 @@ from django.http import HttpResponse from zerver.lib.actions import ( - do_change_stream_web_public, do_deactivate_stream, + do_make_stream_web_public, get_web_public_streams, get_web_public_subs, ) @@ -26,7 +26,7 @@ class GlobalPublicStreamTest(ZulipTestCase): def test_non_existant_topic(self) -> None: test_stream = self.make_stream("Test public archives") - do_change_stream_web_public(test_stream, True) + do_make_stream_web_public(test_stream) result = self.client_get( "/archive/streams/" + str(test_stream.id) + "/topics/nonexistenttopic", ) @@ -34,7 +34,7 @@ class GlobalPublicStreamTest(ZulipTestCase): def test_web_public_stream_topic(self) -> None: test_stream = self.make_stream("Test public archives") - do_change_stream_web_public(test_stream, True) + do_make_stream_web_public(test_stream) def send_msg_and_get_result(msg: str) -> HttpResponse: self.send_stream_message( @@ -67,7 +67,7 @@ class GlobalPublicStreamTest(ZulipTestCase): # Now add a second public stream test_stream = self.make_stream("Test public archives") - do_change_stream_web_public(test_stream, True) + do_make_stream_web_public(test_stream) public_streams = get_web_public_streams(realm) self.assert_length(public_streams, 2) info = get_web_public_subs(realm) @@ -111,7 +111,7 @@ class WebPublicTopicHistoryTest(ZulipTestCase): def test_web_public_stream(self) -> None: test_stream = self.make_stream("Test public archives") - do_change_stream_web_public(test_stream, True) + do_make_stream_web_public(test_stream) self.send_stream_message( self.example_user("iago"), diff --git a/zerver/tests/test_reactions.py b/zerver/tests/test_reactions.py index 777af3ef88..8126873c17 100644 --- a/zerver/tests/test_reactions.py +++ b/zerver/tests/test_reactions.py @@ -4,7 +4,7 @@ from unittest import mock import orjson from django.http import HttpResponse -from zerver.lib.actions import do_change_stream_invite_only, do_change_stream_web_public +from zerver.lib.actions import do_change_stream_invite_only, do_make_stream_web_public from zerver.lib.cache import cache_get, to_dict_cache_key_id from zerver.lib.emoji import emoji_name_to_emoji_code from zerver.lib.message import extract_message_dict @@ -560,7 +560,7 @@ class ReactionEventTest(ZulipTestCase): self.assert_json_success(remove) # Make stream web_public as well. - do_change_stream_web_public(stream, True) + do_make_stream_web_public(stream) # For is_web_public streams, events even on old messages # should go to all subscribers, including guests like polonius. events = []