Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
unarchive: Add support for unarchiving archived channels.
whilstsomebody2780360b00d2
diff --git a/api_docs/changelog.md b/api_docs/changelog.mdindex a664deceaea..95a83c57c9f 100644--- a/api_docs/changelog.md+++ b/api_docs/changelog.md@@ -20,6 +20,12 @@ format used by the Zulip server that they are interacting with.## Changes in Zulip 11.0+**Feature level 388**++* [`PATCH /streams/{stream_id}`](/api/update-stream): Added+ `is_archived` parameter to support unarchiving previously archived+ channels.+**Feature level 387*** [`GET /users`](/api/get-users): This endpoint no longer requiresdiff --git a/version.py b/version.pyindex 0a8e6552173..ccee79a279b 100644--- a/version.py+++ b/version.py@@ -34,7 +34,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"# new level means in api_docs/changelog.md, as well as "**Changes**"# entries in the endpoint's documentation in `zulip.yaml`.-API_FEATURE_LEVEL = 387+API_FEATURE_LEVEL = 388# Bump the minor PROVISION_VERSION to indicate that folks should provision# only when going from an old version of the code to a newer version. Bumpdiff --git a/web/shared/icons/unarchive.svg b/web/shared/icons/unarchive.svgnew file mode 100644index 00000000000..eec81fe46b9--- /dev/null+++ b/web/shared/icons/unarchive.svg@@ -0,0 +1,4 @@+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="#000000">+ <path+ d="M 1.4545455,0.72727285 C 0.6613071,0.72727285 0,1.3885799 0,2.1818183 v 2.1818182 c 0,0.7932384 0.6613071,1.4545454 1.4545455,1.4545454 v 7.2727271 c 0,1.196371 0.9854475,2.181818 2.1818181,2.181818 h 1.4545455 c 0.4016616,0 0.7272727,-0.325611 0.7272727,-0.727272 0,-0.401662 -0.3256111,-0.727273 -0.7272727,-0.727273 H 3.6363636 c -0.4102759,0 -0.7272727,-0.316997 -0.7272727,-0.727273 V 5.8181819 H 13.090909 v 7.2727271 c 0,0.410276 -0.316997,0.727273 -0.727273,0.727273 h -1.454545 c -0.401662,0 -0.727273,0.325611 -0.727273,0.727273 0,0.401661 0.325611,0.727272 0.727273,0.727272 h 1.454545 c 1.196371,0 2.181819,-0.985447 2.181819,-2.181818 V 5.8181819 C 15.338693,5.8181819 16,5.1568749 16,4.3636365 V 2.1818183 C 16,1.3885799 15.338693,0.72727285 14.545455,0.72727285 Z m 0,1.45454545 H 14.545455 V 4.3636365 H 13.818182 2.1818182 1.4545455 Z M 8,7.2727271 c -0.192873,2.9e-5 -0.377837,0.07667 -0.514204,0.213069 l -2.1818187,2.181818 c -0.2839442,0.284005 -0.2839442,0.7444029 0,1.0284089 0.2840051,0.283944 0.7444037,0.283944 1.0284087,0 L 7.272727,9.7556821 v 4.7897729 c 0,0.401661 0.325611,0.727272 0.727273,0.727272 0.401662,0 0.727273,-0.325611 0.727273,-0.727272 V 9.7556821 l 0.940341,0.9403409 c 0.284005,0.283944 0.744403,0.283944 1.028409,0 0.283944,-0.284006 0.283944,-0.7444039 0,-1.0284089 L 8.514204,7.4857961 C 8.377837,7.3493991 8.192873,7.2727561 8,7.2727271 Z"/>+</svg>diff --git a/web/src/stream_data.ts b/web/src/stream_data.tsindex a11f29fd589..edd7911679c 100644--- a/web/src/stream_data.ts+++ b/web/src/stream_data.ts@@ -310,6 +310,15 @@ export function mark_archived(stream_id: number): void {sub.is_archived = true;}+export function mark_unarchived(stream_id: number): void {+ const sub = get_sub_by_id(stream_id);+ if (sub === undefined) {+ blueslip.warn("Failed to unarchive stream " + stream_id.toString());+ return;+ }+ sub.is_archived = false;+}+export function delete_sub(stream_id: number): void {if (!stream_info.get(stream_id)) {blueslip.warn("Failed to archive stream " + stream_id.toString());@@ -603,7 +612,7 @@ export function rewire_has_content_access(value: typeof has_content_access): voihas_content_access = value;}-function can_administer_channel(sub: StreamSubscription): boolean {+export function can_administer_channel(sub: StreamSubscription): boolean {// Note that most callers should use wrappers like// can_change_permissions_requiring_content_access, since actions// that can grant access to message content require content accessdiff --git a/web/src/stream_edit.ts b/web/src/stream_edit.tsindex 7614b0c0424..88dde4c4481 100644--- a/web/src/stream_edit.ts+++ b/web/src/stream_edit.ts@@ -5,6 +5,7 @@ import type * as tippy from "tippy.js";import {z} from "zod";import render_settings_deactivation_stream_modal from "../templates/confirm_dialog/confirm_deactivate_stream.hbs";+import render_settings_reactivation_stream_modal from "../templates/confirm_dialog/confirm_reactivate_stream.hbs";import render_inline_decorated_channel_name from "../templates/inline_decorated_channel_name.hbs";import render_change_stream_info_modal from "../templates/stream_settings/change_stream_info_modal.hbs";import render_confirm_stream_privacy_change_modal from "../templates/stream_settings/confirm_stream_privacy_change_modal.hbs";@@ -284,6 +285,7 @@ export function show_settings_for(node: HTMLElement): void {$edit_container.addClass("show");+ stream_ui_updates.update_settings_button_for_archive_and_unarchive(sub);show_subscription_settings(sub);settings_org.set_message_retention_setting_dropdown(sub);stream_ui_updates.enable_or_disable_permission_settings_in_edit_panel(sub);@@ -747,6 +749,41 @@ export function initialize(): void {$(".dialog_submit_button").attr("data-stream-id", stream_id);});+ $("#channels_overlay_container").on("click", ".reactivate", function (this: HTMLElement, e) {+ e.preventDefault();+ e.stopPropagation();+ const stream_id = get_stream_id(this);+ function do_unarchive_stream(): void {+ channel.patch({+ url: `/json/streams/${stream_id}`,+ data: {is_archived: false},+ error(xhr) {+ ui_report.error(+ $t_html({defaultMessage: "Failed"}),+ xhr,+ $(".stream_change_property_info"),+ );+ },+ });+ }++ const stream = sub_store.get(stream_id);+ const stream_name_with_privacy_symbol_html = render_inline_decorated_channel_name({stream});+ const html_body = render_settings_reactivation_stream_modal();++ confirm_dialog.launch({+ html_heading: $t_html(+ {defaultMessage: "Unarchive <z-link></z-link>?"},+ {"z-link": () => stream_name_with_privacy_symbol_html},+ ),+ id: "unarchive-stream-modal",+ html_body,+ on_click: do_unarchive_stream,+ });++ $(".dialog_submit_button").attr("data-stream-id", stream_id);+ });+$("#channels_overlay_container").on("click", ".stream-row", function (this: HTMLElement, e) {e.preventDefault();e.stopPropagation();diff --git a/web/src/stream_events.ts b/web/src/stream_events.tsindex b1b036284c2..4939fab76b1 100644--- a/web/src/stream_events.ts+++ b/web/src/stream_events.ts@@ -187,24 +187,27 @@ export function update_property<P extends keyof UpdatableStreamProperties>(stream_list.update_streams_sidebar();},is_archived(value) {- if (!value) {- // We currently do not live-update when unarchiving stream.- return;- }const is_subscribed = sub.subscribed;const is_narrowed_to_stream = narrow_state.narrowed_to_stream_id(stream_id);- stream_data.mark_archived(stream_id);- stream_settings_ui.update_settings_for_archived(sub);- message_view_header.maybe_rerender_title_area_for_stream(stream_id);- if (is_subscribed) {- stream_list.remove_sidebar_row(stream_id);- if (stream_id === compose_state.selected_recipient_id) {- compose_state.set_selected_recipient_id("");- compose_recipient.on_compose_select_recipient_update();+ if (!value) {+ stream_data.mark_unarchived(sub.stream_id);+ if (is_subscribed) {+ stream_list.add_sidebar_row(sub);+ }+ } else {+ stream_data.mark_archived(stream_id);+ if (is_subscribed) {+ stream_list.remove_sidebar_row(stream_id);+ if (stream_id === compose_state.selected_recipient_id) {+ compose_state.set_selected_recipient_id("");+ compose_recipient.on_compose_select_recipient_update();+ }}+ stream_data.remove_default_stream(stream_id);+ settings_streams.update_default_streams_table();}- settings_streams.update_default_streams_table();- stream_data.remove_default_stream(stream_id);+ stream_settings_ui.update_settings_for_archived_and_unarchived(sub);+ message_view_header.maybe_rerender_title_area_for_stream(stream_id);if (is_narrowed_to_stream) {assert(message_lists.current !== undefined);message_lists.current.update_trailing_bookend(true);diff --git a/web/src/stream_settings_ui.ts b/web/src/stream_settings_ui.tsindex b36d114ba97..512cf6805f0 100644--- a/web/src/stream_settings_ui.ts+++ b/web/src/stream_settings_ui.ts@@ -361,25 +361,29 @@ export function update_settings_for_subscribed(slim_sub: StreamSubscription): voupdate_empty_left_panel_message();}-export function update_settings_for_archived(slim_sub: StreamSubscription): void {+export function update_settings_for_archived_and_unarchived(slim_sub: StreamSubscription): void {if (!overlays.streams_open()) {return;}const sub = stream_settings_data.get_sub_for_settings(slim_sub);update_left_panel_row(sub);++ const has_archived_channels = stream_data.get_archived_subs().length > 0;+ if (has_archived_channels) {+ $(".stream_settings_filter_container").removeClass("hide_filter");+ } else {+ $(".stream_settings_filter_container").addClass("hide_filter");+ stream_settings_components.set_filter_dropdown_value(+ stream_settings_data.FILTERS.NON_ARCHIVED_CHANNELS,+ );+ }redraw_left_panel();- $(".stream_settings_filter_container").removeClass("hide_filter");const active_data = stream_settings_components.get_active_data();if (active_data.id === sub.stream_id) {- const $archive_button = $(".stream_settings_header .deactivate");-- if ($archive_button.length > 0) {- $archive_button.remove();- }-stream_settings_components.set_right_panel_title(sub);+ stream_ui_updates.update_settings_button_for_archive_and_unarchive(sub);stream_ui_updates.update_toggler_for_sub(sub);stream_ui_updates.enable_or_disable_permission_settings_in_edit_panel(sub);stream_ui_updates.update_stream_privacy_icon_in_settings(sub);diff --git a/web/src/stream_ui_updates.ts b/web/src/stream_ui_updates.tsindex 1661170c4c7..1c831340a89 100644--- a/web/src/stream_ui_updates.ts+++ b/web/src/stream_ui_updates.ts@@ -224,6 +224,34 @@ export function update_settings_button_for_sub(sub: StreamSubscription): void {}}+export function update_settings_button_for_archive_and_unarchive(sub: StreamSubscription): void {+ if (!hash_parser.is_editing_stream(sub.stream_id)) {+ return;+ }++ // This is for the Archive/Unarchive button in the right panel.+ const $archive_button = $(+ `.stream_settings_header[data-stream-id='${CSS.escape(sub.stream_id.toString())}'] .deactivate`,+ );+ const $unarchive_button = $(+ `.stream_settings_header[data-stream-id='${CSS.escape(sub.stream_id.toString())}'] .reactivate`,+ );++ if (!stream_data.can_administer_channel(sub)) {+ $archive_button.hide();+ $unarchive_button.hide();+ return;+ }++ if (sub.is_archived) {+ $archive_button.hide();+ $unarchive_button.show();+ } else {+ $unarchive_button.hide();+ $archive_button.show();+ }+}+export function update_regular_sub_settings(sub: StreamSubscription): void {// These are in the right panel.if (!hash_parser.is_editing_stream(sub.stream_id)) {diff --git a/web/styles/subscriptions.css b/web/styles/subscriptions.cssindex 0031ba5a085..c1ae13891dd 100644--- a/web/styles/subscriptions.css+++ b/web/styles/subscriptions.css@@ -1090,7 +1090,8 @@ h4.user_group_setting_subsection_title {width: 1em;}- .deactivate {+ .deactivate,+ .reactivate {margin-right: 3px;text-decoration: none;}diff --git a/web/templates/confirm_dialog/confirm_reactivate_stream.hbs b/web/templates/confirm_dialog/confirm_reactivate_stream.hbsnew file mode 100644index 00000000000..bcf2221e642--- /dev/null+++ b/web/templates/confirm_dialog/confirm_reactivate_stream.hbs@@ -0,0 +1,10 @@+<p>+ {{#tr}}Unarchiving this channel will:{{/tr}}+</p>+<p>+ <ul>+ <li>{{#tr}}Make it appear in the left sidebar for all subscribers.{{/tr}}</li>+ <li>{{#tr}}Allow sending new messages to this channel.{{/tr}}</li>+ <li>{{#tr}}Allow messages in this channel to be edited, deleted, or moved.{{/tr}}</li>+ </ul>+</p>diff --git a/web/templates/stream_settings/stream_settings.hbs b/web/templates/stream_settings/stream_settings.hbsindex 7215455c858..9b8658b7f4d 100644--- a/web/templates/stream_settings/stream_settings.hbs+++ b/web/templates/stream_settings/stream_settings.hbs@@ -28,14 +28,18 @@id="preview-stream-button"hidden=(not should_display_preview_button)}}- {{#if can_archive_stream}}{{> ../components/icon_buttonicon="archive"intent="danger"custom_classes="tippy-zulip-delayed-tooltip deactivate"data-tippy-content=(t 'Archive channel')}}- {{/if}}+ {{> ../components/icon_button+ icon="unarchive"+ intent="success"+ custom_classes="tippy-zulip-delayed-tooltip reactivate"+ data-tippy-content=(t 'Unarchive channel')+ }}</div>{{/with}}</div>diff --git a/web/tests/stream_data.test.cjs b/web/tests/stream_data.test.cjsindex 7bf511a162b..6f5df1d6491 100644--- a/web/tests/stream_data.test.cjs+++ b/web/tests/stream_data.test.cjs@@ -946,6 +946,29 @@ test("mark_archived", () => {stream_data.mark_archived(99999);});+test("mark_unarchived", () => {+ const canada = {+ stream_id: 101,+ name: "Canada",+ is_archived: true,+ subscribed: true,+ };++ stream_data.add_sub(canada);+ assert.ok(stream_data.is_stream_archived(canada.stream_id));+ assert.ok(stream_data.is_subscribed(canada.stream_id));++ stream_data.mark_unarchived(canada.stream_id);+ assert.ok(!stream_data.is_stream_archived(canada.stream_id));+ assert.ok(stream_data.is_subscribed(canada.stream_id));+ const sub = stream_data.get_sub("Canada");+ assert.equal(sub.stream_id, canada.stream_id);+ assert.equal(sub.is_archived, false);++ blueslip.expect("warn", "Failed to unarchive stream 99999");+ stream_data.mark_unarchived(99999);+});+test("notifications", ({override}) => {const india = {stream_id: 102,diff --git a/web/tests/stream_events.test.cjs b/web/tests/stream_events.test.cjsindex 0b8948a03ab..1ab1b0fec42 100644--- a/web/tests/stream_events.test.cjs+++ b/web/tests/stream_events.test.cjs@@ -335,7 +335,7 @@ test("update_property", ({override}) => {stream_data.subscribe_myself(sub);const stub = make_stub();- override(stream_settings_ui, "update_settings_for_archived", stub.f);+ override(stream_settings_ui, "update_settings_for_archived_and_unarchived", stub.f);override(settings_streams, "update_default_streams_table", noop);override(message_live_update, "rerender_messages_view", noop);@@ -364,9 +364,34 @@ test("update_property", ({override}) => {assert.equal(removed_sidebar_rows, 1);}- // We do not live update unarchiving stream, but we test this for coverage.+ // Test unarchiving stream{+ const stub = make_stub();+ override(stream_settings_ui, "update_settings_for_archived_and_unarchived", stub.f);+ override(message_live_update, "rerender_messages_view", noop);++ let bookend_updates = 0;+ override(message_lists.current, "update_trailing_bookend", () => {+ bookend_updates += 1;+ });++ let added_sidebar_rows = 0;+ override(stream_list, "add_sidebar_row", () => {+ added_sidebar_rows += 1;+ });++ compose_state.set_stream_id(stream_id);++ // Unarchive the streamstream_events.update_property(stream_id, "is_archived", false);+ assert.ok(!stream_data.is_stream_archived(stream_id));+ assert.ok(stream_data.is_subscribed(stream_id));++ const args = stub.get_args("sub");+ assert.equal(args.sub.stream_id, stream_id);++ assert.equal(bookend_updates, 1);+ assert.equal(added_sidebar_rows, 1);}// Test deprecated properties for coverage.diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 6679c3e4c92..6100e845d85 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -21237,6 +21237,16 @@ paths:example: falsemessage_retention_days:$ref: "#/components/schemas/MessageRetentionDays"+ is_archived:+ description: |+ A boolean indicating whether the channel is+ [archived](/help/archive-a-channel) or+ unarchived. Currently only allows unarchiving+ previously archived channels.++ **Changes**: New in Zulip 11.0 (feature level 388).+ type: boolean+ example: truecan_add_subscribers_group:allOf:- description: |diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex f0dfc4d3bc4..5960e0f8ca3 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -2193,19 +2193,24 @@ class StreamAdminTest(ZulipTestCase):self.assertNotIn(self.example_user("polonius").id, notified_user_ids)def test_unarchive_stream(self) -> None:- hamlet = self.example_user("hamlet")+ iago = self.example_user("iago")cordelia = self.example_user("cordelia")+ self.login_user(iago)stream = self.make_stream("new_stream", is_web_public=True)was_invite_only = stream.invite_onlywas_web_public = stream.is_web_publicwas_history_public = stream.history_public_to_subscribers- self.subscribe(hamlet, stream.name)+ self.subscribe(iago, stream.name)self.subscribe(cordelia, stream.name)do_deactivate_stream(stream, acting_user=None)++ data = {}+ data["is_archived"] = "false"with self.capture_send_event_calls(expected_num_events=3) as events:- do_unarchive_stream(stream, new_name="new_stream", acting_user=None)+ result = self.api_patch(iago, f"/json/streams/{stream.id}", info=data)+ self.assert_json_success(result)# Clients will get this event only if they support# archived_channels client capability.@@ -2239,7 +2244,7 @@ class StreamAdminTest(ZulipTestCase):self.assertEqual(stream.history_public_to_subscribers, was_history_public)self.assertEqual(- {hamlet.id, cordelia.id},+ {iago.id, cordelia.id},{sub.user_profile_idfor sub in get_active_subscriptions_for_stream_id(@@ -2248,6 +2253,71 @@ class StreamAdminTest(ZulipTestCase):},)+ def test_permissions_and_archiving_behavior(self) -> None:+ """+ Test permissions for archiving and unarchiving streams, and ensure users without+ the necessary permissions cannot archive or unarchive a stream.+ """+ desdemona = self.example_user("desdemona")+ iago = self.example_user("iago")++ self.login_user(desdemona)+ stream = self.make_stream("test_stream", invite_only=False)+ self.subscribe(iago, stream.name)++ do_deactivate_stream(stream, acting_user=None)+ stream.refresh_from_db()+ self.assertTrue(stream.deactivated)++ data = {}+ data["is_archived"] = "false"+ result = self.api_patch(desdemona, f"/json/streams/{stream.id}", info=data)+ self.assert_json_success(result)+ stream.refresh_from_db()+ self.assertFalse(stream.deactivated)++ cordelia = self.example_user("cordelia")+ self.login_user(cordelia)++ stream1 = self.make_stream("test_stream_1", invite_only=False)+ self.subscribe(iago, stream1.name)++ do_deactivate_stream(stream1, acting_user=None)+ stream1.refresh_from_db()+ self.assertTrue(stream1.deactivated)++ result = self.api_patch(cordelia, f"/json/streams/{stream1.id}", info=data)+ self.assert_json_error(result, "You do not have permission to administer this channel.")++ do_change_stream_group_based_setting(+ stream1,+ "can_administer_channel_group",+ UserGroupMembersData(direct_members=[cordelia.id], direct_subgroups=[]),+ acting_user=desdemona,+ )++ result = self.api_patch(cordelia, f"/json/streams/{stream1.id}", info=data)+ self.assert_json_success(result)++ stream1.refresh_from_db()+ self.assertFalse(stream1.deactivated)++ def test_is_archived_true_does_not_archive_stream(self) -> None:+ """+ Ensure that passing `is_archived` as True does not archive the stream.+ """+ iago = self.example_user("iago")+ self.login_user(iago)+ stream = self.make_stream("test_stream", invite_only=False)+ self.subscribe(iago, stream.name)++ result = self.client_patch(+ f"/json/streams/{stream.id}", {"is_archived": orjson.dumps(True).decode()}+ )+ self.assert_json_success(result)+ stream.refresh_from_db()+ self.assertFalse(stream.deactivated)+def test_deactivate_stream_backend_requires_existing_stream(self) -> None:user_profile = self.example_user("hamlet")self.login_user(user_profile)diff --git a/zerver/views/streams.py b/zerver/views/streams.pyindex e398981aed6..867c7925ad0 100644--- a/zerver/views/streams.py+++ b/zerver/views/streams.py@@ -38,6 +38,7 @@ from zerver.actions.streams import (do_change_subscription_property,do_deactivate_stream,do_rename_stream,+ do_unarchive_stream,get_subscriber_ids,)from zerver.actions.user_topics import bulk_do_set_user_topic_visibility_policy@@ -269,6 +270,7 @@ def update_stream_backend(is_web_public: Json[bool] | None = None,new_name: str | None = None,message_retention_days: Json[str] | Json[int] | None = None,+ is_archived: Json[bool] | None = None,can_add_subscribers_group: Json[GroupSettingChangeRequest] | None = None,can_administer_channel_group: Json[GroupSettingChangeRequest] | None = None,can_send_message_group: Json[GroupSettingChangeRequest] | None = None,@@ -396,6 +398,9 @@ def update_stream_backend(stream, user_profile, new_message_retention_days_value)+ if is_archived is not None and not is_archived:+ do_unarchive_stream(stream, stream.name, acting_user=None)+if description is not None:if "\n" in description:# We don't allow newline characters in stream descriptions.