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.
This commit is contained in:
Sahil Batra
2025-07-12 13:37:14 +05:30
committed by Tim Abbott
parent b5fc39044e
commit 7b66eb838e
2 changed files with 45 additions and 2 deletions

View File

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

View File

@@ -1,8 +1,22 @@
<div class="cannot-deactivate-group-banner main-view-banner error">
<p class="banner-text">
{{t "To deactivate this group, you must first remove all permissions assigned to it."}}
{{#if group_used_for_permissions}}
{{t "To deactivate this group, you must first remove all permissions assigned to it."}}
{{else}}
{{#tr}}
To deactivate this group, you must first remove it from all other groups. This group is currently a subgroup of: <z-supergroup-names></z-supergroup-names>.
{{#*inline "z-supergroup-names"}}
{{#each supergroups}}
<a class="view-group-members" data-group-id="{{group_id}}" href="{{settings_url}}">{{group_name}}</a>
{{~#unless @last}}, {{/unless~}}
{{/each}}
{{/inline}}
{{/tr}}
{{/if}}
</p>
{{#if group_used_for_permissions}}
<button class="permissions-button main-view-banner-action-button">
{{t "View permissions"}}
</button>
{{/if}}
</div>