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.

stream-settings: Disable privacy element and topic creation setting.

Sahil Batra2ff1c5827917
diff --git a/web/src/settings_components.ts b/web/src/settings_components.ts
index a445fe4704b..159c6684ba8 100644
--- a/web/src/settings_components.ts
+++ b/web/src/settings_components.ts
@@ -1802,10 +1802,12 @@ export function create_stream_group_setting_widget({
$pill_container,
setting_name,
sub,
+ pill_update_callback,
}: {
$pill_container: JQuery;
setting_name: StreamPermissionGroupSetting;
sub?: StreamSubscription;
+ pill_update_callback?: () => void;
}): GroupSettingPillContainer {
const pill_widget = group_setting_pill.create_pills($pill_container, setting_name, "stream");
const opts: {
@@ -1828,12 +1830,21 @@ export function create_stream_group_setting_widget({
const $subsection = $pill_container.closest(".settings-subsection-parent");
pill_widget.onTextInputHook(() => {
+ if (pill_update_callback !== undefined) {
+ pill_update_callback();
+ }
save_discard_stream_settings_widget_status_handler($subsection, sub);
});
pill_widget.onPillCreate(() => {
+ if (pill_update_callback !== undefined) {
+ pill_update_callback();
+ }
save_discard_stream_settings_widget_status_handler($subsection, sub);
});
pill_widget.onPillRemove(() => {
+ if (pill_update_callback !== undefined) {
+ pill_update_callback();
+ }
save_discard_stream_settings_widget_status_handler($subsection, sub);
});
} else {
diff --git a/web/src/stream_create.ts b/web/src/stream_create.ts
index d3b5678a2de..f50f61ffd01 100644
--- a/web/src/stream_create.ts
+++ b/web/src/stream_create.ts
@@ -537,6 +537,7 @@ export function show_new_stream_modal(): void {
stream_ui_updates.update_can_subscribe_group_label($("#stream-creation"));
stream_ui_updates.update_default_stream_option_state($("#stream-creation"));
stream_ui_updates.update_history_public_to_subscribers_state($("#stream-creation"));
+ stream_ui_updates.update_can_create_topic_group_setting_state($("#stream-creation"));
clear_error_display();
}
@@ -554,6 +555,16 @@ function set_up_group_setting_widgets(): void {
group_setting_widgets[setting_name],
);
}
+
+ // Enable or disable protected history stream privacy option when
+ // can_create_topic_group setting is updated.
+ const can_create_topic_group_widget = group_setting_widgets["can_create_topic_group"]!;
+ can_create_topic_group_widget.onPillCreate(() => {
+ stream_ui_updates.update_history_public_to_subscribers_state($("#stream-creation"));
+ });
+ can_create_topic_group_widget.onPillRemove(() => {
+ stream_ui_updates.update_history_public_to_subscribers_state($("#stream-creation"));
+ });
}
export function set_up_handlers(): void {
@@ -639,6 +650,10 @@ export function set_up_handlers(): void {
}
});
+ $container.on("input", "#id_new_history_public_to_subscribers", () => {
+ stream_ui_updates.update_can_create_topic_group_setting_state($("#stream-creation"));
+ });
+
set_up_group_setting_widgets();
settings_components.enable_opening_typeahead_on_clicking_label($container);
folder_widget = stream_settings_components.set_up_folder_dropdown_widget();
diff --git a/web/src/stream_edit.ts b/web/src/stream_edit.ts
index 3a3d42f95c6..7810f711787 100644
--- a/web/src/stream_edit.ts
+++ b/web/src/stream_edit.ts
@@ -48,6 +48,7 @@ import * as stream_settings_containers from "./stream_settings_containers.ts";
import * as stream_settings_data from "./stream_settings_data.ts";
import type {SettingsSubscription} from "./stream_settings_data.ts";
import {
+ type StreamPermissionGroupSetting,
stream_permission_group_settings_schema,
stream_properties_schema,
stream_specific_notification_settings_schema,
@@ -317,11 +318,24 @@ export function stream_settings(sub: StreamSubscription): StreamSetting[] {
function setup_group_setting_widgets(sub: StreamSubscription): void {
for (const setting_name of Object.keys(realm.server_supported_permission_settings.stream)) {
- settings_components.create_stream_group_setting_widget({
+ const opts: {
+ $pill_container: JQuery;
+ setting_name: StreamPermissionGroupSetting;
+ sub?: StreamSubscription;
+ pill_update_callback?: () => void;
+ } = {
$pill_container: $("#id_" + setting_name),
setting_name: stream_permission_group_settings_schema.parse(setting_name),
sub,
- });
+ };
+ if (setting_name === "can_create_topic_group") {
+ opts.pill_update_callback = () => {
+ stream_ui_updates.update_history_public_to_subscribers_on_can_create_topic_group_change(
+ sub,
+ );
+ };
+ }
+ settings_components.create_stream_group_setting_widget(opts);
}
}
@@ -478,8 +492,8 @@ export function show_settings_for(node: HTMLElement): void {
show_subscription_settings(sub);
settings_org.set_message_retention_setting_dropdown(sub);
set_up_channel_privacy_dropdown_widget(undefined, sub);
- stream_ui_updates.enable_or_disable_permission_settings_in_edit_panel(sub);
setup_group_setting_widgets(slim_sub);
+ stream_ui_updates.enable_or_disable_permission_settings_in_edit_panel(sub);
stream_ui_updates.update_can_subscribe_group_label($edit_container);
stream_settings_components.set_up_folder_dropdown_widget(sub);
stream_ui_updates.set_folder_dropdown_visibility($("#stream_settings"));
@@ -992,6 +1006,12 @@ export function initialize(): void {
$subsection,
sub,
);
+ if ($subsection.attr("id") === "channel-subscription-permissions") {
+ assert(sub !== undefined);
+ stream_ui_updates.update_can_create_topic_group_on_history_public_to_subscribers_change(
+ sub,
+ );
+ }
return true;
},
);
@@ -1056,6 +1076,12 @@ export function initialize(): void {
stream_ui_updates.update_history_public_to_subscribers_state($edit_container);
stream_ui_updates.update_default_stream_option_state($edit_container);
stream_ui_updates.update_can_subscribe_group_label($edit_container);
+ stream_ui_updates.update_can_create_topic_group_setting_state($edit_container);
+ }
+
+ if ($subsection.attr("id") === "channel-messaging-permissions") {
+ const $edit_container = stream_settings_containers.get_edit_container(sub);
+ stream_ui_updates.update_history_public_to_subscribers_state($edit_container);
}
},
);
diff --git a/web/src/stream_events.ts b/web/src/stream_events.ts
index d72d3090da0..9129b959903 100644
--- a/web/src/stream_events.ts
+++ b/web/src/stream_events.ts
@@ -123,6 +123,12 @@ export function update_property<P extends keyof UpdatableStreamProperties>(
// rerender the entire message feed.
message_live_update.rerender_messages_view();
}
+ if (property === "can_create_topic_group") {
+ stream_ui_updates.update_history_public_to_subscribers_state(
+ $("#stream_settings"),
+ sub,
+ );
+ }
user_group_edit.update_stream_setting_in_permissions_panel(
stream_permission_group_settings_schema.parse(property),
group_setting_value_schema.parse(value),
diff --git a/web/src/stream_ui_updates.ts b/web/src/stream_ui_updates.ts
index fe2bad48114..f73d6f2b756 100644
--- a/web/src/stream_ui_updates.ts
+++ b/web/src/stream_ui_updates.ts
@@ -23,6 +23,7 @@ import * as stream_settings_containers from "./stream_settings_containers.ts";
import type {SettingsSubscription} from "./stream_settings_data.ts";
import * as sub_store from "./sub_store.ts";
import type {StreamSubscription} from "./sub_store.ts";
+import * as user_groups from "./user_groups.ts";
import * as util from "./util.ts";
export function row_for_stream_id(stream_id: number): JQuery {
@@ -60,24 +61,55 @@ export function set_show_available(value: boolean): void {
show_available = value;
}
-export function update_history_public_to_subscribers_state($container: JQuery): void {
+export function update_history_public_to_subscribers_state(
+ $container: JQuery,
+ sub?: StreamSubscription,
+): void {
const is_stream_creation = $container.attr("id") === "stream-creation";
+ if (!is_stream_creation && sub !== undefined && !hash_parser.is_editing_stream(sub.stream_id)) {
+ return;
+ }
let stream_privacy_widget;
+ let can_create_topic_group_widget;
if (is_stream_creation) {
stream_privacy_widget = stream_settings_components.channel_creation_privacy_widget!;
+ can_create_topic_group_widget =
+ stream_settings_components.get_group_setting_widget_for_new_stream(
+ "can_create_topic_group",
+ )!;
} else {
stream_privacy_widget =
settings_components.get_widget_for_dropdown_list_settings("channel_privacy")!;
+ can_create_topic_group_widget =
+ settings_components.get_group_setting_widget("can_create_topic_group")!;
}
const is_invite_only = stream_privacy_widget.value() === "invite-only";
+ const everyone_group = user_groups.get_user_group_from_name("role:everyone")!;
+ const everyone_can_create_topics =
+ settings_components.get_group_setting_widget_value(can_create_topic_group_widget) ===
+ everyone_group.id;
+
const $history_public_to_subscribers_container = $container.find(
".history-public-to-subscribers",
);
- $history_public_to_subscribers_container.find("input").prop("disabled", !is_invite_only);
- $history_public_to_subscribers_container.toggleClass("control-label-disabled", !is_invite_only);
+ $history_public_to_subscribers_container
+ .find("input")
+ .prop("disabled", !is_invite_only || !everyone_can_create_topics);
+ $history_public_to_subscribers_container.toggleClass(
+ "control-label-disabled",
+ !is_invite_only || !everyone_can_create_topics,
+ );
+
+ // Tooltip is shown only if the checkbox is disabled due to topic creation permission
+ // and not when it is disabled because channel privacy is not set to private.
+ $history_public_to_subscribers_container.toggleClass(
+ "protected_history_with_new_topics_permission_tooltip",
+ is_invite_only && !everyone_can_create_topics,
+ );
+
if (!is_invite_only) {
// For public and web-public streams, history_public_to_subscribers should
// always be true.
@@ -85,6 +117,55 @@ export function update_history_public_to_subscribers_state($container: JQuery):
}
}
+export function update_history_public_to_subscribers_on_can_create_topic_group_change(
+ sub: StreamSubscription,
+): void {
+ // This function is only used to enable/disable the history_public_to_subscribers
+ // checkbox when can_create_topic_group setting element is changed for an existing
+ // channel.
+ // This is different from update_history_public_to_subscribers_state above because
+ // the history_public_to_subscribers checkbox is enabled only if sub.can_create_topic_group
+ // is set to everyone, i.e. we do not enable the checkbox immediately after the
+ // can_create_topic_group setting element is set to everyone group for a channel
+ // where everyone could not create new topics originally.
+
+ const stream_privacy_widget =
+ settings_components.get_widget_for_dropdown_list_settings("channel_privacy")!;
+ if (stream_privacy_widget.value() !== "invite-only") {
+ // If the history_public_to_subscribers checkbox is already disabled
+ // due to stream not being private, we just return.
+ return;
+ }
+
+ const can_create_topic_group_widget =
+ settings_components.get_group_setting_widget("can_create_topic_group")!;
+ const everyone_group = user_groups.get_user_group_from_name("role:everyone")!;
+ const everyone_can_create_topics =
+ settings_components.get_group_setting_widget_value(can_create_topic_group_widget) ===
+ everyone_group.id;
+
+ const $history_public_to_subscribers_container = $("#stream_settings").find(
+ ".history-public-to-subscribers",
+ );
+
+ if (!everyone_can_create_topics) {
+ $history_public_to_subscribers_container.find("input").prop("disabled", true);
+ $history_public_to_subscribers_container.addClass("control-label-disabled");
+ $history_public_to_subscribers_container.addClass(
+ "protected_history_with_new_topics_permission_tooltip",
+ );
+ return;
+ }
+
+ if (sub.can_create_topic_group === everyone_group.id) {
+ $history_public_to_subscribers_container.find("input").prop("disabled", false);
+ $history_public_to_subscribers_container.removeClass("control-label-disabled");
+ $history_public_to_subscribers_container.removeClass(
+ "protected_history_with_new_topics_permission_tooltip",
+ );
+ }
+}
+
export function initialize_cant_subscribe_popover(): void {
const $button_wrapper = $(".settings .stream_settings_header .sub_unsub_button_wrapper");
settings_components.initialize_disable_button_hint_popover($button_wrapper, undefined);
@@ -331,6 +412,7 @@ export function enable_or_disable_permission_settings_in_edit_panel(
update_default_stream_option_state($("#stream_settings"));
update_history_public_to_subscribers_state($("#stream_settings"));
+ update_can_create_topic_group_setting_state($("#stream_settings"));
const disable_message_retention_setting =
!realm.zulip_plan_is_not_limited || !current_user.is_owner;
@@ -580,3 +662,53 @@ export function update_folder_dropdown_visibility(): void {
set_folder_dropdown_visibility($("#stream_settings"));
}
}
+
+export function update_can_create_topic_group_setting_state($container: JQuery): void {
+ const is_history_public = $container.find(".history_public_to_subscribers").is(":checked");
+
+ let $setting_element = $("#id_can_create_topic_group");
+ if (hash_parser.is_create_new_stream_narrow()) {
+ $setting_element = $("#id_new_can_create_topic_group");
+ }
+ if (is_history_public) {
+ settings_components.enable_group_permission_setting($setting_element);
+ } else {
+ settings_components.disable_group_permission_setting($setting_element);
+ }
+ $setting_element
+ .closest(".input-group")
+ .toggleClass("can_create_topic_group_disabled_tooltip", !is_history_public);
+}
+
+export function update_can_create_topic_group_on_history_public_to_subscribers_change(
+ sub: StreamSubscription,
+): void {
+ // This function is only used to enable/disable the can_create_topic_group setting
+ // element when history_public_to_subscribers checkbox is changed for an existing
+ // channel.
+ // This is different from update_can_create_topic_group_setting_state above because
+ // the can_create_topic_group setting element is enabled only if
+ // sub.history_public_to_subscribers is true, i.e. we do not enable the element
+ // immediately after the input is checked for a channel whose history is private
+ // originally.
+
+ const is_history_public = $("#stream_settings")
+ .find(".history_public_to_subscribers")
+ .is(":checked");
+ const $can_create_topic_group_elem = $("#id_can_create_topic_group");
+
+ if (!is_history_public) {
+ settings_components.disable_group_permission_setting($can_create_topic_group_elem);
+ $can_create_topic_group_elem
+ .closest(".input-group")
+ .addClass("can_create_topic_group_disabled_tooltip");
+ return;
+ }
+
+ if (sub.history_public_to_subscribers) {
+ settings_components.enable_group_permission_setting($can_create_topic_group_elem);
+ $can_create_topic_group_elem
+ .closest(".input-group")
+ .removeClass("can_create_topic_group_disabled_tooltip");
+ }
+}
diff --git a/web/src/tippyjs.ts b/web/src/tippyjs.ts
index 577c6bb12c3..707815f2de0 100644
--- a/web/src/tippyjs.ts
+++ b/web/src/tippyjs.ts
@@ -439,6 +439,30 @@ export function initialize(): void {
},
});
+ tippy.delegate("body", {
+ target: ".history-public-to-subscribers.protected_history_with_new_topics_permission_tooltip",
+ content: $t({
+ defaultMessage:
+ "This setting can be changed only in channels where everyone including guests can start new topics.",
+ }),
+ appendTo: () => document.body,
+ onHidden(instance) {
+ instance.destroy();
+ },
+ });
+
+ tippy.delegate("body", {
+ target: ".can_create_topic_group_container.can_create_topic_group_disabled_tooltip",
+ content: $t({
+ defaultMessage:
+ "This setting can be changed only in channels where subscribers can view messages sent before they joined.",
+ }),
+ appendTo: () => document.body,
+ onHidden(instance) {
+ instance.destroy();
+ },
+ });
+
tippy.delegate("body", {
target: ".default-stream.default_stream_private_tooltip",
content: $t({
diff --git a/web/templates/settings/group_setting_value_pill_input.hbs b/web/templates/settings/group_setting_value_pill_input.hbs
index 4134ae7970c..f592e24b4a7 100644
--- a/web/templates/settings/group_setting_value_pill_input.hbs
+++ b/web/templates/settings/group_setting_value_pill_input.hbs
@@ -1,4 +1,4 @@
-<div class="input-group">
+<div class="input-group {{setting_name}}_container">
{{!-- We are using snake case for one of the classes since setting_name
is always in snake case and it would be weird to have the resultant id
be a mix of two types of cases. --}}
diff --git a/web/tests/stream_events.test.cjs b/web/tests/stream_events.test.cjs
index fc565e1888f..32c7665ce8b 100644
--- a/web/tests/stream_events.test.cjs
+++ b/web/tests/stream_events.test.cjs
@@ -50,6 +50,7 @@ mock_esm("../src/user_settings", {
},
});
+const stream_ui_updates = mock_esm("../src/stream_ui_updates");
const user_group_edit = mock_esm("../src/user_group_edit");
const user_profile = mock_esm("../src/user_profile");
@@ -312,8 +313,15 @@ test("update_property", ({override}) => {
can_add_subscribers: false,
...sub,
}));
+ const update_add_subscriptions_elements_stub = make_stub();
+ override(
+ stream_ui_updates,
+ "update_add_subscriptions_elements",
+ update_add_subscriptions_elements_stub.f,
+ );
stream_events.update_property(stream_id, "can_administer_channel_group", 3);
assert.equal(stub.num_calls, 1);
+ assert.equal(update_add_subscriptions_elements_stub.num_calls, 1);
const args = stub.get_args("setting_name", "sub", "val");
assert.equal(args.setting_name, "can_administer_channel_group");
assert.equal(args.sub.stream_id, stream_id);
@@ -333,6 +341,21 @@ test("update_property", ({override}) => {
assert.equal(args.val, 3);
}
+ // Test stream can_create_topic_group change event
+ {
+ const stub = make_stub();
+ override(stream_settings_ui, "update_stream_permission_group_setting", stub.f);
+ const update_history_public_to_subscribers_state_stub = make_stub();
+ override(
+ stream_ui_updates,
+ "update_history_public_to_subscribers_state",
+ update_history_public_to_subscribers_state_stub.f,
+ );
+ stream_events.update_property(stream_id, "can_create_topic_group", 3);
+ assert.equal(stub.num_calls, 1);
+ assert.equal(update_history_public_to_subscribers_state_stub.num_calls, 1);
+ }
+
// Test stream can_subscribe_group change event
{
const stub = make_stub();