mirror of https://github.com/zulip/zulip.git
streams: Raise error when making public stream with private history.
We raise error when we try to change a public stream (except for zephyr mirror realms) to be public with protected history, as we do not support such streams yet. Previously, in such case we changed nothing and a notification was sent to the "stream events" topic with message being "stream is changed from public to public" and was weird. Note that this commit only handles the case when both is_private and history_public_to_subscribers parameters are passed to API and commit not covers the case when only "history_public_to_subscribers" with value False is passed to API, since we currently ignore requests which has only history_public_to_subscribers parameter with not None and not is_private and is_web_public. We would do this in further commits when we add support for accepting only history_public_to_subscribers parameter.
This commit is contained in:
parent
6a860c74d6
commit
6ccfebac56
|
@ -1018,6 +1018,11 @@ class StreamAdminTest(ZulipTestCase):
|
||||||
self.assertTrue(attachment.is_web_public)
|
self.assertTrue(attachment.is_web_public)
|
||||||
|
|
||||||
def test_try_make_stream_public_with_private_history(self) -> None:
|
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 today
|
||||||
user_profile = self.example_user("hamlet")
|
user_profile = self.example_user("hamlet")
|
||||||
self.login_user(user_profile)
|
self.login_user(user_profile)
|
||||||
realm = user_profile.realm
|
realm = user_profile.realm
|
||||||
|
@ -1030,30 +1035,7 @@ class StreamAdminTest(ZulipTestCase):
|
||||||
}
|
}
|
||||||
stream_id = self.subscribe(user_profile, "public_stream").id
|
stream_id = self.subscribe(user_profile, "public_stream").id
|
||||||
result = self.client_patch(f"/json/streams/{stream_id}", params)
|
result = self.client_patch(f"/json/streams/{stream_id}", params)
|
||||||
self.assert_json_success(result)
|
self.assert_json_error(result, "Invalid parameters")
|
||||||
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)
|
|
||||||
|
|
||||||
def test_subscriber_ids_with_stream_history_access(self) -> None:
|
def test_subscriber_ids_with_stream_history_access(self) -> None:
|
||||||
hamlet = self.example_user("hamlet")
|
hamlet = self.example_user("hamlet")
|
||||||
|
|
|
@ -318,6 +318,13 @@ def update_stream_backend(
|
||||||
if is_private and stream.id in default_stream_ids:
|
if is_private and stream.id in default_stream_ids:
|
||||||
raise JsonableError(_("Default streams cannot be made private."))
|
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:
|
if is_web_public:
|
||||||
# Enforce restrictions on creating web-public streams.
|
# Enforce restrictions on creating web-public streams.
|
||||||
if not user_profile.realm.web_public_streams_enabled():
|
if not user_profile.realm.web_public_streams_enabled():
|
||||||
|
|
Loading…
Reference in New Issue