Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
streams: Raise error when making public stream with private history.
Sahil Batra6ccfebac564c
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex 6bd8dc79053..6477c1313c9 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -1018,6 +1018,11 @@ class StreamAdminTest(ZulipTestCase):self.assertTrue(attachment.is_web_public)def test_try_make_stream_public_with_private_history(self) -> None:+ # We only support public streams with private history if+ # is_zephyr_mirror_realm, and don't allow changing stream+ # permissions in such realms. So changing the+ # history_public_to_subscribers property of a public stream is+ # not possible in Zulip todayuser_profile = self.example_user("hamlet")self.login_user(user_profile)realm = user_profile.realm@@ -1030,30 +1035,7 @@ class StreamAdminTest(ZulipTestCase):}stream_id = self.subscribe(user_profile, "public_stream").idresult = self.client_patch(f"/json/streams/{stream_id}", params)- self.assert_json_success(result)- stream = get_stream("public_stream", realm)- self.assertFalse(stream.invite_only)- self.assertTrue(stream.history_public_to_subscribers)-- messages = get_topic_messages(user_profile, stream, "stream events")- self.assert_length(messages, 1)-- # This test verifies the (weird) outcome for a transition that- # is not currently possible. For background, we only support- # public streams with private history if- # is_zephyr_mirror_realm, and don't allow changing stream- # permissions in such realms. So changing the- # history_public_to_subscribers property of a public stream is- # not possible in Zulip today; this test covers that situation- # and will produce the odd/wrong output of "Public to Public".- #- # This test should be corrected if we add support for such a- # stream configuration transition.- expected_notification = (- f"@_**King Hamlet|{user_profile.id}** changed the [access permissions](/help/stream-permissions) "- "for this stream from **Public** to **Public**."- )- self.assertEqual(messages[0].content, expected_notification)+ self.assert_json_error(result, "Invalid parameters")def test_subscriber_ids_with_stream_history_access(self) -> None:hamlet = self.example_user("hamlet")diff --git a/zerver/views/streams.py b/zerver/views/streams.pyindex 351af47d2d5..3a3c931870d 100644--- a/zerver/views/streams.py+++ b/zerver/views/streams.py@@ -318,6 +318,13 @@ def update_stream_backend(if is_private and stream.id in default_stream_ids:raise JsonableError(_("Default streams cannot be made private."))+ if (+ not is_private+ and history_public_to_subscribers is False+ and not stream.realm.is_zephyr_mirror_realm+ ):+ raise JsonableError(_("Invalid parameters"))+if is_web_public:# Enforce restrictions on creating web-public streams.if not user_profile.realm.web_public_streams_enabled():