mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(editor): Move editor-ui and design-system to frontend dir (no-changelog) (#13564)
This commit is contained in:
32
packages/frontend/editor-ui/src/permissions.ts
Normal file
32
packages/frontend/editor-ui/src/permissions.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { Scope } from '@n8n/permissions';
|
||||
import { RESOURCES } from '@n8n/permissions';
|
||||
|
||||
type ExtractScopePrefixSuffix<T> = T extends `${infer Prefix}:${infer Suffix}`
|
||||
? [Prefix, Suffix]
|
||||
: never;
|
||||
type ActionBooleans<T extends readonly string[]> = {
|
||||
[K in T[number]]?: boolean;
|
||||
};
|
||||
export type PermissionsRecord = {
|
||||
[K in keyof typeof RESOURCES]: ActionBooleans<(typeof RESOURCES)[K]>;
|
||||
};
|
||||
|
||||
export const getResourcePermissions = (resourceScopes: Scope[] = []): PermissionsRecord =>
|
||||
Object.keys(RESOURCES).reduce(
|
||||
(permissions, key) => ({
|
||||
...permissions,
|
||||
[key]: resourceScopes.reduce((resourcePermissions, scope) => {
|
||||
const [prefix, suffix] = scope.split(':') as ExtractScopePrefixSuffix<Scope>;
|
||||
|
||||
if (prefix === key) {
|
||||
return {
|
||||
...resourcePermissions,
|
||||
[suffix]: true,
|
||||
};
|
||||
}
|
||||
|
||||
return resourcePermissions;
|
||||
}, {}),
|
||||
}),
|
||||
{} as PermissionsRecord,
|
||||
);
|
||||
Reference in New Issue
Block a user