Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

streams: Require content access to change channel privacy.

Tim Abbott5b2bd0761213
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py
index 799d2d17fe3..d89541a03c4 100644
--- a/zerver/tests/test_subs.py
+++ b/zerver/tests/test_subs.py
@@ -919,7 +919,7 @@ class StreamAdminTest(ZulipTestCase):
}
stream_id = get_stream("private_stream_1", user_profile.realm).id
result = self.client_patch(f"/json/streams/{stream_id}", params)
- self.assert_json_error(result, "Invalid channel ID")
+ self.assert_json_error(result, "Channel content access is required.")
stream = self.subscribe(user_profile, "private_stream_1")
self.assertFalse(stream.is_in_zephyr_realm)
@@ -2319,7 +2319,7 @@ class StreamAdminTest(ZulipTestCase):
"is_private": orjson.dumps(True).decode(),
},
)
- self.assert_json_error(result, "Invalid channel ID")
+ self.assert_json_error(result, "Channel content access is required.")
def test_non_admin_cannot_access_unsub_private_stream(self) -> None:
iago = self.example_user("iago")
@@ -2911,7 +2911,7 @@ class StreamAdminTest(ZulipTestCase):
params,
)
if setting_name in Stream.stream_permission_group_settings_requiring_content_access:
- self.assert_json_error(result, "Invalid channel ID")
+ self.assert_json_error(result, "Channel content access is required.")
else:
self.assert_json_success(result)
stream = get_stream("stream_name2", realm)
@@ -2937,7 +2937,7 @@ class StreamAdminTest(ZulipTestCase):
params,
)
if setting_name in Stream.stream_permission_group_settings_requiring_content_access:
- self.assert_json_error(result, "Invalid channel ID")
+ self.assert_json_error(result, "Channel content access is required.")
do_change_stream_group_based_setting(
stream,
"can_add_subscribers_group",
diff --git a/zerver/views/streams.py b/zerver/views/streams.py
index 2aa0ab3be39..c4b39015e82 100644
--- a/zerver/views/streams.py
+++ b/zerver/views/streams.py
@@ -280,6 +280,7 @@ def update_stream_backend(
(stream, sub) = access_stream_for_delete_or_update_requiring_metadata_access(
user_profile, stream_id
)
+ user_group_membership_details = UserGroupMembershipDetails(user_recursive_group_ids=None)
# Validate that the proposed state for permissions settings is permitted.
if is_private is not None:
@@ -335,11 +336,16 @@ def update_stream_backend(
if not proposed_is_private and user_profile.realm.moderation_request_channel == stream:
raise JsonableError(_("Moderation request channel must be private."))
- if is_private is not None:
- # We require even channel administrators to be actually
- # subscribed to make a private stream public, via this
- # stricted access_stream check.
- access_stream_by_id(user_profile, stream_id)
+ if is_private is not None and not user_has_content_access(
+ user_profile,
+ stream,
+ user_group_membership_details,
+ is_subscribed=sub is not None,
+ ):
+ raise JsonableError(_("Channel content access is required."))
+ # In addition to channel administration permissions, changing
+ # public/private status for channels requires content access
+ # to the channel.
# Enforce restrictions on creating web-public streams. Since these
# checks are only required when changing a stream to be
@@ -419,9 +425,6 @@ def update_stream_backend(
if validate_group_setting_value_change(
current_setting_api_value, new_setting_value, expected_current_setting_value
):
- user_group_membership_details = UserGroupMembershipDetails(
- user_recursive_group_ids=None
- )
if (
setting_name in Stream.stream_permission_group_settings_requiring_content_access
and not user_has_content_access(
@@ -431,7 +434,8 @@ def update_stream_backend(
is_subscribed=sub is not None,
)
):
- raise JsonableError(_("Invalid channel ID"))
+ raise JsonableError(_("Channel content access is required."))
+
with transaction.atomic(durable=True):
user_group_api_value_for_setting = access_user_group_api_value_for_setting(
new_setting_value,