Migrate SelfGrantableRoles to new Plugin structure

This commit is contained in:
Dark 2020-07-27 00:08:01 +02:00
parent 140ba84544
commit 763bdd0b19
10 changed files with 418 additions and 0 deletions

View file

@ -0,0 +1,15 @@
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);
}