Skip to content

Commit 11f3e06

Browse files
committed
style: add tsdocs to getPermissionMetadata and buildPermissionMatrix
1 parent 5ceb49f commit 11f3e06

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

  • src/authz-module/libraries-manager

src/authz-module/libraries-manager/utils.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ import { actionKeys } from '@src/authz-module/components/RoleCard/constants';
33
import actionMessages from '../components/RoleCard/messages';
44
import { PermissionMetadata, ResourceMetadata, Role } from 'types';
55

6+
/**
7+
* Derives the localized label and action key for a given permission.
8+
*
9+
* This function attempts to extract a known `actionKey` from the permission's key,
10+
* and uses that to construct an internationalized label using `intl.formatMessage`.
11+
* If a label is already defined in the permission metadata, that is returned as-is.
12+
*
13+
* Special handling is applied for action keys like `'tag'` and `'team'`, which are
14+
* normalized to `'manage'` and given a custom resource string for translation.
15+
*
16+
* @param permission - The permission metadata, typically containing a key and optional label.
17+
* @param intl - The `IntlShape` object used to generate localized labels.
18+
*
19+
* @returns An object containing:
20+
* - `label`: The human-readable, localized label for the permission.
21+
* - `actionKey`: A string representing icon to be displayed (e.g., `'Read'`, `'Edit'`), or `undefined` if not matched.
22+
*/
623
function getPermissionMetadata(
724
permission: PermissionMetadata,
825
intl: IntlShape,
@@ -21,7 +38,6 @@ function getPermissionMetadata(
2138
return { label, actionKey };
2239
}
2340

24-
2541
const buildPermissionsByRoleMatrix = ({
2642
rolePermissions,
2743
permissions,
@@ -72,6 +88,20 @@ type PermissionMatrix = {
7288
}[];
7389
}[];
7490

91+
/**
92+
* Builds a permission matrix from the given roles, permissions, and resources.
93+
*
94+
* The matrix groups permissions under their respective resources and maps
95+
* each permission to which roles have access to it.
96+
*
97+
* @param roles - List of roles, each containing a list of granted permission keys.
98+
* @param permissions - Metadata describing each permission, including its associated resource.
99+
* @param resources - List of resource metadata used to group permissions.
100+
* @param intl - The internationalization object used to localize permission labels.
101+
*
102+
* @returns A permission matrix grouped by resource, with role mappings per permission.
103+
*/
104+
75105
export function buildPermissionMatrix(
76106
roles: Role[],
77107
permissions: PermissionMetadata[],

0 commit comments

Comments
 (0)