Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

groups-ui: Update error shown when group cannot be deactivated.

Sahil Batra7b66eb838ea0
diff --git a/web/src/user_group_edit.ts b/web/src/user_group_edit.ts
index 59a708fbfc0..46108dafbde 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 f9438452fc2..40880df606e 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 @@
<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>