Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
streams: Prevent already-deactivated streams from being deactivated.
Alex Vandivera2ed0302cefc
diff --git a/zerver/actions/streams.py b/zerver/actions/streams.pyindex ba19eba8fe4..451e7bb04e4 100644--- a/zerver/actions/streams.py+++ b/zerver/actions/streams.py@@ -25,6 +25,7 @@ from zerver.lib.cache import (to_dict_cache_key_id,)from zerver.lib.email_mirror_helpers import encode_email_address+from zerver.lib.exceptions import JsonableErrorfrom zerver.lib.mention import silent_mention_syntax_for_userfrom zerver.lib.message import get_last_message_idfrom zerver.lib.queue import queue_json_publish@@ -70,6 +71,10 @@ from zerver.tornado.django_api import send_eventdef do_deactivate_stream(stream: Stream, log: bool = True, *, acting_user: Optional[UserProfile]) -> None:+ # If the stream is already deactivated, this is a no-op+ if stream.deactivated is True:+ raise JsonableError(_("Stream is already deactivated"))+# We want to mark all messages in the to-be-deactivated stream as# read for all users; otherwise they will pollute queries like# "Get the user's first unread message". Since this can be andiff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex d995c4e774c..4cb751a21af 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -2293,6 +2293,11 @@ class StreamAdminTest(ZulipTestCase):)self.assert_json_error(result, f"Unable to access stream ({deactivated_stream_name}).")+ # You cannot re-archive the stream+ with self.capture_send_event_calls(expected_num_events=0) as events:+ result = self.client_delete("/json/streams/" + str(stream_id))+ self.assert_json_error(result, "Stream is already deactivated")+def test_you_must_be_realm_admin(self) -> None:"""You must be on the realm to create a stream.@@ -2327,14 +2332,17 @@ class StreamAdminTest(ZulipTestCase):stream = self.set_up_stream_for_archiving("newstream", invite_only=True)self.archive_stream(stream)- def test_archive_streams_youre_not_on(self) -> None:+ def test_archive_stream_youre_not_on(self) -> None:"""- Administrators can delete public streams they aren't on, including- private streams in their realm.+ Administrators can delete public streams they aren't on"""pub_stream = self.set_up_stream_for_archiving("pubstream", subscribed=False)self.archive_stream(pub_stream)+ def test_archive_invite_only_stream_youre_not_on(self) -> None:+ """+ Administrators can delete invite-only streams they aren't on+ """priv_stream = self.set_up_stream_for_archiving("privstream", subscribed=False, invite_only=True)