user_groups: Allow setting and changing can_leave_group setting.

Fixes #31951.
This commit is contained in:
Shubham Padia 2024-10-14 11:40:32 +00:00 committed by Tim Abbott
parent 1862c3b333
commit 797438b0f7
6 changed files with 47 additions and 4 deletions

View File

@ -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<string, GroupSettingPillContainer | null>([
["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,

View File

@ -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);
}

View File

@ -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) {

View File

@ -23,6 +23,16 @@
</div>
</div>
<div class="input-group can-leave-group-container">
<label>{{t "Who can leave this group" }}</label>
<div class="pill-container person_picker prop-element" id="id_{{can_leave_group_widget_name}}" data-setting-widget-type="group-setting-type">
<div class="input" contenteditable="true"
data-placeholder="{{t 'Add roles, groups or users' }}">
{{~! Squash whitespace so that placeholder is displayed when empty. ~}}
</div>
</div>
</div>
<div class="input-group can-add-members-group-container">
<label>{{t "Who can add members to this group" }}</label>
<div class="pill-container person_picker prop-element" id="id_{{can_add_members_group_widget_name}}" data-setting-widget-type="group-setting-type">

View File

@ -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"
}}
</div>
</section>

View File

@ -41,7 +41,13 @@
{{> ../settings/settings_save_discard_widget section_name="group-permissions" }}
</div>
{{> 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"
}}
</div>
<div class="group_detail_box">