Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
streams: Allow editing subscriptions in archived channels.
Tim Abbottc58f14b15915
diff --git a/zerver/lib/streams.py b/zerver/lib/streams.pyindex 2a31362d8bc..dc230afa803 100644--- a/zerver/lib/streams.py+++ b/zerver/lib/streams.py@@ -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 channelsif 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}diff --git a/zerver/models/streams.py b/zerver/models/streams.pyindex f212382e2c2..1a47db16fa6 100644--- a/zerver/models/streams.py+++ b/zerver/models/streams.py@@ -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)diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex d89541a03c4..e98b7f90645 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -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 streamwith 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,