From 7b66eb838ea033f3402bf14b71a8ce6c0ba37417 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Sat, 12 Jul 2025 13:37:14 +0530 Subject: [PATCH] groups-ui: Update error shown when group cannot be deactivated. This commit updates error banner shown when group is only used as subgroups and not as permission. If group is used as a permission, then we mention that in the error banner and have a button to go to "Permissions" panel. We show the same banner even when group is used as a subgroup as well. But when group is only used as subgroups, we just show a message containing names of all the supergroups. --- web/src/user_group_edit.ts | 31 ++++++++++++++++++- .../cannot_deactivate_group_banner.hbs | 16 +++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/web/src/user_group_edit.ts b/web/src/user_group_edit.ts index 59a708fbfc..46108dafbd 100644 --- a/web/src/user_group_edit.ts +++ b/web/src/user_group_edit.ts @@ -2033,11 +2033,40 @@ export function initialize(): void { parsed.success && parsed.data.code === "CANNOT_DEACTIVATE_GROUP_IN_USE" ) { + const subgroup_objections = parsed.data.objections.filter( + (objection) => objection.type === "subgroup", + ); + let group_used_for_permissions = true; + let supergroups; + if (subgroup_objections.length === parsed.data.objections.length) { + // If the user group is only used as subgroups and not in + // any of the permission, then we show a different error + // message. + const supergroup_ids = z + .array(z.number()) + .parse(subgroup_objections[0]!.supergroup_ids); + supergroups = supergroup_ids.map((group_id) => { + const group = user_groups.get_user_group_from_id(group_id); + const group_name = user_groups.get_display_group_name( + group.name, + ); + return { + group_id, + group_name, + settings_url: hash_util.group_edit_url(group, "members"), + }; + }); + group_used_for_permissions = false; + } $("#deactivation-confirm-modal .dialog_submit_button").prop( "disabled", true, ); - const rendered_error_banner = render_cannot_deactivate_group_banner(); + const rendered_error_banner = render_cannot_deactivate_group_banner({ + group_used_for_permissions, + supergroups, + }); + $("#dialog_error") .html(rendered_error_banner) .addClass("alert-error") diff --git a/web/templates/user_group_settings/cannot_deactivate_group_banner.hbs b/web/templates/user_group_settings/cannot_deactivate_group_banner.hbs index f9438452fc..40880df606 100644 --- a/web/templates/user_group_settings/cannot_deactivate_group_banner.hbs +++ b/web/templates/user_group_settings/cannot_deactivate_group_banner.hbs @@ -1,8 +1,22 @@
+ {{#if group_used_for_permissions}} + {{/if}}