mirror of
https://github.com/unraid/api.git
synced 2026-05-03 13:40:36 -05:00
18 lines
715 B
TypeScript
18 lines
715 B
TypeScript
/*!
|
|
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
|
|
* Written by: Alexis Tyler
|
|
*/
|
|
|
|
import { ac } from '../../permissions';
|
|
|
|
/**
|
|
* Get permissions from an {@link https://onury.io/accesscontrol/?api=ac#AccessControl | AccessControl} role.
|
|
* @param role The {@link https://onury.io/accesscontrol/?api=ac#AccessControl | AccessControl} role to be looked up.
|
|
*/
|
|
export const getPermissions = (role: string): Record<string, unknown> => {
|
|
const grants: Record<string, unknown> = ac.getGrants();
|
|
const { $extend, ...roles } = grants[role] ?? {};
|
|
const inheritedRoles = Array.isArray($extend) ? $extend.map(role => getPermissions(role))[0] : {};
|
|
return Object.assign({}, roles, inheritedRoles);
|
|
};
|