streams: Allow editing subscriptions in archived channels.

Since this does impact the ability to access the channel's content, it
makes sense to permit changing subscriptions, just like other
permissions settings on the archived channel.
This commit is contained in:
Tim Abbott
2025-03-07 16:54:32 -08:00
parent 5b2bd07612
commit c58f14b159
3 changed files with 35 additions and 10 deletions

View File

@@ -500,7 +500,7 @@ def access_stream_for_send_message(
else:
raise JsonableError(_("User not authorized for this query"))
# Deactivated streams are not accessible.
# You cannot send mesasges to archived channels
if stream.deactivated:
if archived_channel_notice:
return
@@ -1262,9 +1262,7 @@ def filter_stream_authorization_for_adding_subscribers(
)
unauthorized_streams = [
stream
for stream in streams
if stream.deactivated or stream.id not in content_access_stream_ids
stream for stream in streams if stream.id not in content_access_stream_ids
]
unauthorized_stream_ids = {stream.id for stream in unauthorized_streams}

View File

@@ -313,7 +313,7 @@ def bulk_get_streams(realm: Realm, stream_names: set[str]) -> dict[str, Any]:
"upper(zerver_stream.name::text) IN (SELECT upper(name) FROM unnest(%s) AS name)"
)
return (
get_active_streams(realm)
get_all_streams(realm, include_archived_channels=True)
.select_related("can_send_message_group", "can_send_message_group__named_user_group")
.extra(where=[where_clause], params=(list(stream_names),)) # noqa: S610
)

View File

@@ -3350,7 +3350,7 @@ class StreamAdminTest(ZulipTestCase):
return stream
def archive_stream(self, stream: Stream) -> None:
def archive_stream(self, stream: Stream, *, expect_can_subscribe: bool = True) -> None:
"""
Archive the stream and assess the result.
"""
@@ -3399,11 +3399,38 @@ class StreamAdminTest(ZulipTestCase):
streams = [s["name"] for s in self.assert_json_success(result)["streams"]]
self.assertIn(deactivated_stream_name, streams)
# You can't subscribe to archived stream.
# You can still subscribe to archived stream, if you have content access.
hamlet = self.example_user("hamlet")
result = self.subscribe_via_post(
self.example_user("hamlet"), [deactivated_stream_name], allow_fail=True
hamlet,
[deactivated_stream_name],
allow_fail=not expect_can_subscribe,
)
self.assert_json_error(result, f"Unable to access channel ({deactivated_stream_name}).")
if expect_can_subscribe:
self.assert_json_success(result)
else:
self.assert_json_error(result, "Unable to access channel (privstream).")
# now grant content access
setting_group_member_dict = UserGroupMembersDict(
direct_members=[hamlet.id], direct_subgroups=[]
)
do_change_stream_group_based_setting(
stream, "can_subscribe_group", setting_group_member_dict, acting_user=hamlet
)
result = self.subscribe_via_post(hamlet, [deactivated_stream_name])
self.assert_json_success(result)
# You can still unsubscribe from an archived stream.
result = self.client_delete(
"/json/users/me/subscriptions",
{
"subscriptions": orjson.dumps([deactivated_stream_name]).decode(),
"principals": orjson.dumps([hamlet.id]).decode(),
},
)
self.assert_json_success(result)
# You cannot re-archive the stream
with self.capture_send_event_calls(expected_num_events=0) as events:
@@ -3458,7 +3485,7 @@ class StreamAdminTest(ZulipTestCase):
priv_stream = self.set_up_stream_for_archiving(
"privstream", subscribed=False, invite_only=True
)
self.archive_stream(priv_stream)
self.archive_stream(priv_stream, expect_can_subscribe=False)
def attempt_unsubscribe_of_principal(
self,