Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
channels: Prevent `moderation_request_channel` to be public.
PieterCKdd306e8d8065
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 889d1e52e3d..2c649157aad 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -20166,6 +20166,17 @@ paths:description: |An example JSON response for when invalid combination of channel permissionparameters are passed:+ - allOf:+ - $ref: "#/components/schemas/CodedError"+ - example:+ {+ "code": "BAD_REQUEST",+ "msg": "A moderation request channel cannot be public.",+ "result": "error",+ }+ description: |+ An example JSON response for when trying to set moderation request channel to+ be public:/streams/{stream_id}/email_address:get:operationId: get-stream-email-addressdiff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex 2d8577ff910..05c7ae95555 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -850,6 +850,16 @@ class StreamAdminTest(ZulipTestCase):}self.assertEqual(invite_only_log.extra_data, expected_extra_data)+ private_stream = self.make_stream("private_stream", realm=realm, invite_only=True)+ realm.moderation_request_channel = private_stream+ realm.save()+ params = {+ "is_private": orjson.dumps(False).decode(),+ }+ result = self.client_patch(f"/json/streams/{private_stream.id}", params)+ self.assert_json_error(result, "Moderation request channel must be private.")+ self.assertTrue(private_stream.invite_only)+do_change_user_role(user_profile, UserProfile.ROLE_MEMBER, acting_user=None)params = {"is_private": orjson.dumps(False).decode(),diff --git a/zerver/views/streams.py b/zerver/views/streams.pyindex fb71402a98b..764f2cf88cc 100644--- a/zerver/views/streams.py+++ b/zerver/views/streams.py@@ -324,6 +324,10 @@ def update_stream_backend(if proposed_is_private and proposed_is_default_stream:raise JsonableError(_("A default channel cannot be private."))+ # Ensure that a moderation request channel isn't set to public.+ if not proposed_is_private and user_profile.realm.get_moderation_request_channel() == stream:+ raise JsonableError(_("Moderation request channel must be private."))+if is_private is not None:# We require even realm administrators to be actually# subscribed to make a private stream public, via this