mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 13:12:14 +08:00

* handle null or empty group and displayName properties on roles * fix display name bug for fixed roles with a period
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import { Role } from 'app/types';
|
|
|
|
export const isNotDelegatable = (role: Role) => {
|
|
return role.delegatable !== undefined && !role.delegatable;
|
|
};
|
|
|
|
// addDisplayNameForFixedRole provides a fallback name for fixed roles
|
|
// this is "incase" a fixed role is introduced but without a displayname set
|
|
// example: currently this would give:
|
|
// fixed:datasources:name -> datasources name
|
|
// fixed:datasources:admin -> datasources admin
|
|
// fixed:support.bundles:writer -> support bundles writer
|
|
export const addDisplayNameForFixedRole = (role: Role) => {
|
|
const fixedRolePrefix = 'fixed:';
|
|
if (!role.displayName && role.name.startsWith(fixedRolePrefix)) {
|
|
let newRoleName = '';
|
|
let rNameWithoutFixedPrefix = role.name.replace(fixedRolePrefix, '');
|
|
newRoleName = rNameWithoutFixedPrefix.replace(/[:\\.]/g, ' ');
|
|
role.displayName = newRoleName;
|
|
}
|
|
return role;
|
|
};
|
|
|
|
// Adds a display name for use when the list of roles is filtered
|
|
// If either group or displayName are undefined, we fall back (see RoleMenuOption.tsx)
|
|
export const addFilteredDisplayName = (role: Role) => {
|
|
if (role.group && role.displayName) {
|
|
role.filteredDisplayName = role.group + ':' + role.displayName;
|
|
}
|
|
return role;
|
|
};
|