From 797438b0f7c3702bfff77b4d04cadd54d06ab9da Mon Sep 17 00:00:00 2001 From: Shubham Padia Date: Mon, 14 Oct 2024 11:40:32 +0000 Subject: [PATCH] user_groups: Allow setting and changing can_leave_group setting. Fixes #31951. --- web/src/settings_components.ts | 8 +++++++- web/src/user_group_create.ts | 14 +++++++++++++- web/src/user_group_edit.js | 7 +++++++ .../user_group_settings/group_permissions.hbs | 10 ++++++++++ .../user_group_creation_form.hbs | 4 +++- .../user_group_settings/user_group_settings.hbs | 8 +++++++- 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/web/src/settings_components.ts b/web/src/settings_components.ts index 479c0029c8..befababdb3 100644 --- a/web/src/settings_components.ts +++ b/web/src/settings_components.ts @@ -920,6 +920,7 @@ export function check_group_property_changed(elem: HTMLElement, group: UserGroup switch (property_name) { case "can_add_members_group": case "can_join_group": + case "can_leave_group": case "can_manage_group": { const pill_widget = get_group_setting_widget(property_name); assert(pill_widget !== null); @@ -1409,6 +1410,7 @@ export function initialize_disable_btn_hint_popover( export const group_setting_widget_map = new Map([ ["can_add_members_group", null], ["can_join_group", null], + ["can_leave_group", null], ["can_manage_group", null], ]); @@ -1450,7 +1452,11 @@ export function set_group_setting_widget_value( } } -type group_setting_name = "can_manage_group" | "can_join_group" | "can_add_members_group"; +type group_setting_name = + | "can_add_members_group" + | "can_join_group" + | "can_leave_group" + | "can_manage_group"; export function create_group_setting_widget({ $pill_container, diff --git a/web/src/user_group_create.ts b/web/src/user_group_create.ts index ff2f94e99a..aac65ad878 100644 --- a/web/src/user_group_create.ts +++ b/web/src/user_group_create.ts @@ -29,8 +29,9 @@ export function get_name(): string | undefined { } let can_add_members_group_widget: GroupSettingPillContainer | undefined; -let can_manage_group_widget: GroupSettingPillContainer | undefined; let can_join_group_widget: GroupSettingPillContainer | undefined; +let can_leave_group_widget: GroupSettingPillContainer | undefined; +let can_manage_group_widget: GroupSettingPillContainer | undefined; class UserGroupMembershipError { report_no_members_to_user_group(): void { @@ -168,6 +169,10 @@ function create_user_group(): void { const can_join_group = settings_components.get_group_setting_widget_value(can_join_group_widget); + assert(can_leave_group_widget !== undefined); + const can_leave_group = + settings_components.get_group_setting_widget_value(can_leave_group_widget); + assert(settings_components.new_group_can_mention_group_widget !== null); const can_mention_group_value = settings_components.new_group_can_mention_group_widget.value(); assert(can_mention_group_value !== undefined); @@ -182,6 +187,7 @@ function create_user_group(): void { members: JSON.stringify(user_ids), can_add_members_group: JSON.stringify(can_add_members_group), can_join_group: JSON.stringify(can_join_group), + can_leave_group: JSON.stringify(can_leave_group), can_mention_group, can_manage_group: JSON.stringify(can_manage_group), }; @@ -274,5 +280,11 @@ export function set_up_handlers(): void { setting_type: "group", }); + can_leave_group_widget = settings_components.create_group_setting_widget({ + $pill_container: $container.find(".can-leave-group-container .pill-container"), + setting_name: "can_leave_group", + setting_type: "group", + }); + user_group_components.setup_permissions_dropdown("can_mention_group", undefined, true); } diff --git a/web/src/user_group_edit.js b/web/src/user_group_edit.js index 2daee7c5b0..40381cecfe 100644 --- a/web/src/user_group_edit.js +++ b/web/src/user_group_edit.js @@ -190,6 +190,13 @@ function show_general_settings(group) { setting_type: "group", group, }); + + settings_components.create_group_setting_widget({ + $pill_container: $edit_container.find(".can-leave-group-container .pill-container"), + setting_name: "can_leave_group", + setting_type: "group", + group, + }); update_general_panel_ui(group); if (!page_params.development_environment) { diff --git a/web/templates/user_group_settings/group_permissions.hbs b/web/templates/user_group_settings/group_permissions.hbs index 25c32cf153..945aaf2051 100644 --- a/web/templates/user_group_settings/group_permissions.hbs +++ b/web/templates/user_group_settings/group_permissions.hbs @@ -23,6 +23,16 @@ +
+ +
+
+ {{~! Squash whitespace so that placeholder is displayed when empty. ~}} +
+
+
+
diff --git a/web/templates/user_group_settings/user_group_creation_form.hbs b/web/templates/user_group_settings/user_group_creation_form.hbs index 94dfa13855..2cec196496 100644 --- a/web/templates/user_group_settings/user_group_creation_form.hbs +++ b/web/templates/user_group_settings/user_group_creation_form.hbs @@ -31,7 +31,9 @@ {{> group_permissions can_add_members_group_widget_name="new_group_can_add_members_group" can_join_group_widget_name="new_group_can_join_group" - can_mention_group_widget_name="new_group_can_mention_group" can_manage_group_widget_name="new_group_can_manage_group" + can_leave_group_widget_name="new_group_can_leave_group" + can_mention_group_widget_name="new_group_can_mention_group" + can_manage_group_widget_name="new_group_can_manage_group" }}
diff --git a/web/templates/user_group_settings/user_group_settings.hbs b/web/templates/user_group_settings/user_group_settings.hbs index a478e1ce58..d3693d0322 100644 --- a/web/templates/user_group_settings/user_group_settings.hbs +++ b/web/templates/user_group_settings/user_group_settings.hbs @@ -41,7 +41,13 @@ {{> ../settings/settings_save_discard_widget section_name="group-permissions" }}
- {{> group_permissions can_add_members_group_widget_name="can_add_members_group" can_join_group_widget_name="can_join_group" can_mention_group_widget_name="can_mention_group" can_manage_group_widget_name="can_manage_group"}} + {{> group_permissions + can_add_members_group_widget_name="can_add_members_group" + can_join_group_widget_name="can_join_group" + can_leave_group_widget_name="can_leave_group" + can_mention_group_widget_name="can_mention_group" + can_manage_group_widget_name="can_manage_group" + }}