3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-18 23:09:59 +00:00
zeppelin/backend/src/plugins/SelfGrantableRoles/util/findMatchingRoles.ts

15 lines
471 B
TypeScript

import { TSelfGrantableRoleEntry } from "../types";
export function findMatchingRoles(roleNames, entries: TSelfGrantableRoleEntry[]): string[] {
const aliasToRoleId = entries.reduce((map, entry) => {
for (const [roleId, aliases] of Object.entries(entry.roles)) {
for (const alias of aliases) {
map.set(alias, roleId);
}
}
return map;
}, new Map());
return roleNames.map(roleName => aliasToRoleId.get(roleName)).filter(Boolean);
}