feat(roles): add Enabled/Disabled Permissions count columns

New SCHEMA-DEVIATION: role-permission-count-columns — the Roles list
only shows Description, so seeing how broad or restrictive a role is
required opening it and counting permissions by hand.

Generalized DynamicList's existing alias-count handling (previously
hardcoded to the single `aliasCount` -> `aliases` mapping) into
COUNT_COLUMN_SOURCES, a table of synthetic "*Count" column names to the
real set/objectList property they count. account-alias-count-column
now runs through the same generic path with no behavior change;
role-permission-count-columns (enabledPermissionCount/
disabledPermissionCount -> enabledPermissions/disabledPermissions) is
the second consumer, added with zero new DynamicList.tsx branching.

Verified against the live dev server: correct counts for both seeded
custom roles (Support Agent: 3/0, Read-only Auditor: 1/0) and the
built-in roles (System Administrator: 452/0, User: 244/0, etc.).
Confirmed no regression on Accounts' existing Aliases column/sort.
This commit is contained in:
Steven RYDELL
2026-08-01 22:23:48 +02:00
parent 9cd21a2d34
commit 503cae465f
4 changed files with 85 additions and 13 deletions
+36
View File
@@ -0,0 +1,36 @@
/*
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
import type { Schema } from '@/types/schema';
/**
* SCHEMA-DEVIATION: role-permission-count-columns (see SCHEMA_DEVIATIONS.md)
*
* The Roles list only shows Description, hiding how many permissions a
* role actually grants or explicitly revokes without opening it. Adds two
* synthetic columns — DynamicList's generic count-column handling
* resolves them from the real `enabledPermissions`/`disabledPermissions`
* set properties and renders their entry counts.
*/
export function withRoleListColumns(schema: Schema): Schema {
const list = schema.lists['x:Role'];
if (!list) return schema;
return {
...schema,
lists: {
...schema.lists,
'x:Role': {
...list,
columns: [
...list.columns,
{ name: 'enabledPermissionCount', label: 'Enabled Permissions' },
{ name: 'disabledPermissionCount', label: 'Disabled Permissions' },
],
},
},
};
}