mirror of https://github.com/zulip/zulip.git
settings: Use new pills UI for DM permission settings.
We now use pills UI for direct_message_initiator_group and direct_message_permission_group setting.
This commit is contained in:
parent
5fbc46f82c
commit
dce229ba17
|
@ -273,10 +273,6 @@ export function build_page() {
|
|||
|
||||
tippy.default($("#realm_can_access_all_users_group_widget_container")[0], opts);
|
||||
}
|
||||
|
||||
settings_org.check_disable_direct_message_initiator_group_dropdown(
|
||||
realm.realm_direct_message_permission_group,
|
||||
);
|
||||
}
|
||||
|
||||
export function launch(section, user_settings_tab) {
|
||||
|
|
|
@ -259,7 +259,7 @@ function get_options_for_recipient_widget(): Option[] {
|
|||
name: $t({defaultMessage: "Direct message"}),
|
||||
};
|
||||
|
||||
if (!user_groups.is_empty_group(realm.realm_direct_message_permission_group)) {
|
||||
if (!user_groups.is_setting_group_empty(realm.realm_direct_message_permission_group)) {
|
||||
options.unshift(direct_messages_option);
|
||||
} else {
|
||||
options.push(direct_messages_option);
|
||||
|
|
|
@ -114,7 +114,7 @@ export function needs_subscribe_warning(user_id: number, stream_id: number): boo
|
|||
|
||||
export function check_dm_permissions_and_get_error_string(user_ids_string: string): string {
|
||||
if (!people.user_can_direct_message(user_ids_string)) {
|
||||
if (user_groups.is_empty_group(realm.realm_direct_message_permission_group)) {
|
||||
if (user_groups.is_setting_group_empty(realm.realm_direct_message_permission_group)) {
|
||||
return $t({
|
||||
defaultMessage: "Direct messages are disabled in this organization.",
|
||||
});
|
||||
|
|
|
@ -17,7 +17,7 @@ import * as settings_data from "./settings_data";
|
|||
import type {StateData, profile_datum_schema, user_schema} from "./state_data";
|
||||
import {current_user, realm} from "./state_data";
|
||||
import * as timerender from "./timerender";
|
||||
import {is_user_in_group} from "./user_groups";
|
||||
import {is_user_in_setting_group} from "./user_groups";
|
||||
import {user_settings} from "./user_settings";
|
||||
import * as util from "./util";
|
||||
|
||||
|
@ -767,9 +767,8 @@ export function should_add_guest_user_indicator(user_id: number): boolean {
|
|||
}
|
||||
|
||||
export function user_can_initiate_direct_message_thread(recipient_ids_string: string): boolean {
|
||||
const direct_message_initiator_group_id = realm.realm_direct_message_initiator_group;
|
||||
const recipient_ids = user_ids_string_to_ids_array(recipient_ids_string);
|
||||
if (is_user_in_group(direct_message_initiator_group_id, my_user_id)) {
|
||||
if (is_user_in_setting_group(realm.realm_direct_message_initiator_group, my_user_id)) {
|
||||
return true;
|
||||
}
|
||||
for (const recipient of recipient_ids) {
|
||||
|
@ -781,9 +780,8 @@ export function user_can_initiate_direct_message_thread(recipient_ids_string: st
|
|||
}
|
||||
|
||||
export function user_can_direct_message(recipient_ids_string: string): boolean {
|
||||
const direct_message_permission_group_id = realm.realm_direct_message_permission_group;
|
||||
const recipient_ids = user_ids_string_to_ids_array(recipient_ids_string);
|
||||
if (is_user_in_group(direct_message_permission_group_id, my_user_id)) {
|
||||
if (is_user_in_setting_group(realm.realm_direct_message_permission_group, my_user_id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -792,7 +790,7 @@ export function user_can_direct_message(recipient_ids_string: string): boolean {
|
|||
if (is_valid_bot_user(recipient_id) || recipient_id === my_user_id) {
|
||||
continue;
|
||||
}
|
||||
if (is_user_in_group(direct_message_permission_group_id, recipient_id)) {
|
||||
if (is_user_in_setting_group(realm.realm_direct_message_permission_group, recipient_id)) {
|
||||
return true;
|
||||
}
|
||||
other_human_recipients_exist = true;
|
||||
|
|
|
@ -321,9 +321,7 @@ export function dispatch_normal_event(event) {
|
|||
key === "direct_message_initiator_group" ||
|
||||
key === "direct_message_permission_group"
|
||||
) {
|
||||
settings_org.check_disable_direct_message_initiator_group_dropdown(
|
||||
realm.realm_direct_message_permission_group,
|
||||
);
|
||||
settings_org.check_disable_direct_message_initiator_group_widget();
|
||||
compose_closed_ui.update_buttons_for_private();
|
||||
compose_recipient.check_posting_policy_for_compose_box();
|
||||
}
|
||||
|
|
|
@ -484,8 +484,6 @@ const dropdown_widget_map = new Map<string, DropdownWidget | null>([
|
|||
["realm_can_delete_own_message_group", null],
|
||||
["realm_can_move_messages_between_channels_group", null],
|
||||
["realm_can_move_messages_between_topics_group", null],
|
||||
["realm_direct_message_initiator_group", null],
|
||||
["realm_direct_message_permission_group", null],
|
||||
]);
|
||||
|
||||
export function get_widget_for_dropdown_list_settings(
|
||||
|
@ -803,15 +801,15 @@ export function check_realm_settings_property_changed(elem: HTMLElement): boolea
|
|||
case "realm_can_delete_own_message_group":
|
||||
case "realm_can_move_messages_between_channels_group":
|
||||
case "realm_can_move_messages_between_topics_group":
|
||||
case "realm_direct_message_initiator_group":
|
||||
case "realm_direct_message_permission_group":
|
||||
proposed_val = get_dropdown_list_widget_setting_value($elem);
|
||||
break;
|
||||
case "realm_can_create_groups":
|
||||
case "realm_can_create_public_channel_group":
|
||||
case "realm_can_create_private_channel_group":
|
||||
case "realm_can_manage_all_groups":
|
||||
case "realm_create_multiuse_invite_group": {
|
||||
case "realm_create_multiuse_invite_group":
|
||||
case "realm_direct_message_initiator_group":
|
||||
case "realm_direct_message_permission_group": {
|
||||
const pill_widget = get_group_setting_widget(property_name);
|
||||
assert(pill_widget !== null);
|
||||
proposed_val = get_group_setting_widget_value(pill_widget);
|
||||
|
@ -1476,6 +1474,8 @@ export const group_setting_widget_map = new Map<string, GroupSettingPillContaine
|
|||
["realm_can_create_private_channel_group", null],
|
||||
["realm_can_manage_all_groups", null],
|
||||
["realm_create_multiuse_invite_group", null],
|
||||
["realm_direct_message_initiator_group", null],
|
||||
["realm_direct_message_permission_group", null],
|
||||
]);
|
||||
|
||||
export function get_group_setting_widget(setting_name: string): GroupSettingPillContainer | null {
|
||||
|
@ -1581,13 +1581,17 @@ type realm_group_setting_name =
|
|||
| "can_create_public_channel_group"
|
||||
| "can_create_private_channel_group"
|
||||
| "can_manage_all_groups"
|
||||
| "create_multiuse_invite_group";
|
||||
| "create_multiuse_invite_group"
|
||||
| "direct_message_initiator_group"
|
||||
| "direct_message_permission_group";
|
||||
export function create_realm_group_setting_widget({
|
||||
$pill_container,
|
||||
setting_name,
|
||||
pill_update_callback,
|
||||
}: {
|
||||
$pill_container: JQuery;
|
||||
setting_name: realm_group_setting_name;
|
||||
pill_update_callback?: () => void;
|
||||
}): void {
|
||||
const pill_widget = group_setting_pill.create_pills($pill_container, setting_name, "realm");
|
||||
const opts: {
|
||||
|
@ -1612,9 +1616,15 @@ export function create_realm_group_setting_widget({
|
|||
".settings-subsection-parent",
|
||||
);
|
||||
pill_widget.onPillCreate(() => {
|
||||
if (pill_update_callback !== undefined) {
|
||||
pill_update_callback();
|
||||
}
|
||||
save_discard_realm_settings_widget_status_handler($save_discard_widget_container);
|
||||
});
|
||||
pill_widget.onPillRemove(() => {
|
||||
if (pill_update_callback !== undefined) {
|
||||
pill_update_callback();
|
||||
}
|
||||
save_discard_realm_settings_widget_status_handler($save_discard_widget_container);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -438,11 +438,35 @@ function set_create_web_public_stream_dropdown_visibility(): void {
|
|||
);
|
||||
}
|
||||
|
||||
export function check_disable_direct_message_initiator_group_dropdown(current_value: number): void {
|
||||
if (user_groups.is_empty_group(current_value)) {
|
||||
$("#realm_direct_message_initiator_group_widget").prop("disabled", true);
|
||||
} else {
|
||||
$("#realm_direct_message_initiator_group_widget").prop("disabled", false);
|
||||
export function check_disable_direct_message_initiator_group_widget(): void {
|
||||
const direct_message_permission_group_widget = settings_components.get_group_setting_widget(
|
||||
"realm_direct_message_permission_group",
|
||||
);
|
||||
if (direct_message_permission_group_widget === null) {
|
||||
// direct_message_permission_group_widget can be null if
|
||||
// the settings overlay is not opened yet.
|
||||
return;
|
||||
}
|
||||
assert(direct_message_permission_group_widget !== null);
|
||||
const direct_message_permission_value = settings_components.get_group_setting_widget_value(
|
||||
direct_message_permission_group_widget,
|
||||
);
|
||||
if (user_groups.is_setting_group_empty(direct_message_permission_value)) {
|
||||
$("#id_realm_direct_message_initiator_group").find(".input").prop("contenteditable", false);
|
||||
$("#id_realm_direct_message_initiator_group")
|
||||
.closest(".input-group")
|
||||
.addClass("group_setting_disabled");
|
||||
settings_components.disable_opening_typeahead_on_clicking_label(
|
||||
$("#id_realm_direct_message_initiator_group").closest(".input-group"),
|
||||
);
|
||||
} else if (current_user.is_admin) {
|
||||
$("#id_realm_direct_message_initiator_group").find(".input").prop("contenteditable", true);
|
||||
$("#id_realm_direct_message_initiator_group")
|
||||
.closest(".input-group")
|
||||
.removeClass("group_setting_disabled");
|
||||
settings_components.enable_opening_typeahead_on_clicking_label(
|
||||
$("#id_realm_direct_message_initiator_group").closest(".input-group"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -559,9 +583,7 @@ function update_dependent_subsettings(property_name: string): void {
|
|||
set_create_web_public_stream_dropdown_visibility();
|
||||
break;
|
||||
case "realm_direct_message_permission_group":
|
||||
check_disable_direct_message_initiator_group_dropdown(
|
||||
realm.realm_direct_message_permission_group,
|
||||
);
|
||||
check_disable_direct_message_initiator_group_widget();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -583,8 +605,6 @@ export function discard_realm_property_element_changes(elem: HTMLElement): void
|
|||
case "realm_signup_announcements_stream_id":
|
||||
case "realm_zulip_update_announcements_stream_id":
|
||||
case "realm_default_code_block_language":
|
||||
case "realm_direct_message_initiator_group":
|
||||
case "realm_direct_message_permission_group":
|
||||
case "realm_can_add_custom_emoji_group":
|
||||
case "realm_can_access_all_users_group":
|
||||
case "realm_can_create_web_public_channel_group":
|
||||
|
@ -602,7 +622,9 @@ export function discard_realm_property_element_changes(elem: HTMLElement): void
|
|||
case "realm_can_create_public_channel_group":
|
||||
case "realm_can_create_private_channel_group":
|
||||
case "realm_can_manage_all_groups":
|
||||
case "realm_create_multiuse_invite_group": {
|
||||
case "realm_create_multiuse_invite_group":
|
||||
case "realm_direct_message_initiator_group":
|
||||
case "realm_direct_message_permission_group": {
|
||||
const pill_widget = settings_components.get_group_setting_widget(property_name);
|
||||
assert(pill_widget !== null);
|
||||
settings_components.set_group_setting_widget_value(
|
||||
|
@ -963,6 +985,8 @@ export function set_up_dropdown_widget_for_realm_group_settings(): void {
|
|||
"can_create_private_channel_group",
|
||||
"can_manage_all_groups",
|
||||
"create_multiuse_invite_group",
|
||||
"direct_message_initiator_group",
|
||||
"direct_message_permission_group",
|
||||
]);
|
||||
for (const setting_name of realm_group_permission_settings) {
|
||||
if (settings_using_pills_ui.has(setting_name)) {
|
||||
|
@ -974,16 +998,6 @@ export function set_up_dropdown_widget_for_realm_group_settings(): void {
|
|||
| ((current_value: string | number | undefined) => void)
|
||||
| undefined;
|
||||
switch (setting_name) {
|
||||
case "direct_message_permission_group": {
|
||||
dropdown_list_item_click_callback = (
|
||||
current_value: string | number | undefined,
|
||||
): void => {
|
||||
assert(typeof current_value === "number");
|
||||
check_disable_direct_message_initiator_group_dropdown(current_value);
|
||||
};
|
||||
|
||||
break;
|
||||
}
|
||||
case "can_delete_any_message_group":
|
||||
case "can_delete_own_message_group": {
|
||||
dropdown_list_item_click_callback =
|
||||
|
@ -1193,8 +1207,18 @@ function initialize_group_setting_widgets(): void {
|
|||
$pill_container: $("#id_realm_can_manage_all_groups"),
|
||||
setting_name: "can_manage_all_groups",
|
||||
});
|
||||
settings_components.create_realm_group_setting_widget({
|
||||
$pill_container: $("#id_realm_direct_message_initiator_group"),
|
||||
setting_name: "direct_message_initiator_group",
|
||||
});
|
||||
settings_components.create_realm_group_setting_widget({
|
||||
$pill_container: $("#id_realm_direct_message_permission_group"),
|
||||
setting_name: "direct_message_permission_group",
|
||||
pill_update_callback: check_disable_direct_message_initiator_group_widget,
|
||||
});
|
||||
|
||||
enable_or_disable_group_permission_settings();
|
||||
check_disable_direct_message_initiator_group_widget();
|
||||
}
|
||||
|
||||
export function build_page(): void {
|
||||
|
|
|
@ -313,8 +313,8 @@ export const realm_schema = z.object({
|
|||
realm_description: z.string(),
|
||||
realm_digest_emails_enabled: z.boolean(),
|
||||
realm_digest_weekday: z.number(),
|
||||
realm_direct_message_initiator_group: z.number(),
|
||||
realm_direct_message_permission_group: z.number(),
|
||||
realm_direct_message_initiator_group: group_setting_value_schema,
|
||||
realm_direct_message_permission_group: group_setting_value_schema,
|
||||
realm_disallow_disposable_email_addresses: z.boolean(),
|
||||
realm_domains: z.array(
|
||||
z.object({
|
||||
|
|
|
@ -266,6 +266,24 @@ export function is_empty_group(user_group_id: number): boolean {
|
|||
return true;
|
||||
}
|
||||
|
||||
export function is_setting_group_empty(setting_group: GroupSettingValue): boolean {
|
||||
if (typeof setting_group === "number") {
|
||||
return is_empty_group(setting_group);
|
||||
}
|
||||
|
||||
if (setting_group.direct_members.length > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const subgroup_id of setting_group.direct_subgroups) {
|
||||
if (!is_empty_group(subgroup_id)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function get_user_groups_of_user(user_id: number): UserGroup[] {
|
||||
const user_groups_realm = get_realm_user_groups();
|
||||
const groups_of_user = user_groups_realm.filter((group) =>
|
||||
|
|
|
@ -113,15 +113,14 @@
|
|||
</h3>
|
||||
{{> settings_save_discard_widget section_name="direct-message-permissions" }}
|
||||
</div>
|
||||
{{> ../dropdown_widget_with_label
|
||||
widget_name="realm_direct_message_permission_group"
|
||||
label=(t 'Who can authorize a direct message conversation')
|
||||
value_type="number" }}
|
||||
|
||||
{{> ../dropdown_widget_with_label
|
||||
widget_name="realm_direct_message_initiator_group"
|
||||
label=(t 'Who can start a direct message conversation')
|
||||
value_type="number" }}
|
||||
{{> group_setting_value_pill_input
|
||||
setting_name="realm_direct_message_permission_group"
|
||||
label=(t 'Who can authorize a direct message conversation')}}
|
||||
|
||||
{{> group_setting_value_pill_input
|
||||
setting_name="realm_direct_message_initiator_group"
|
||||
label=(t 'Who can start a direct message conversation')}}
|
||||
</div>
|
||||
|
||||
<div id="org-msg-editing" class="settings-subsection-parent">
|
||||
|
|
|
@ -466,7 +466,7 @@ run_test("realm settings", ({override}) => {
|
|||
override(current_user, "is_admin", true);
|
||||
override(realm, "realm_date_created", new Date("2023-01-01Z"));
|
||||
|
||||
override(settings_org, "check_disable_direct_message_initiator_group_dropdown", noop);
|
||||
override(settings_org, "check_disable_direct_message_initiator_group_widget", noop);
|
||||
override(settings_org, "sync_realm_settings", noop);
|
||||
override(settings_bots, "update_bot_permissions_ui", noop);
|
||||
override(settings_emoji, "update_custom_emoji_ui", noop);
|
||||
|
|
Loading…
Reference in New Issue