mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 18:41:14 +00:00
feat: Add initial scope checks via decorators (#7737)
This commit is contained in:
14
packages/cli/src/decorators/Scopes.ts
Normal file
14
packages/cli/src/decorators/Scopes.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { Scope } from '@n8n/permissions';
|
||||
import type { ScopeMetadata } from './types';
|
||||
import { CONTROLLER_REQUIRED_SCOPES } from './constants';
|
||||
|
||||
export const RequireGlobalScope = (scope: Scope | Scope[]) => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
return (target: Function | object, handlerName?: string) => {
|
||||
const controllerClass = handlerName ? target.constructor : target;
|
||||
const scopes = (Reflect.getMetadata(CONTROLLER_REQUIRED_SCOPES, controllerClass) ??
|
||||
[]) as ScopeMetadata;
|
||||
scopes[handlerName ?? '*'] = Array.isArray(scope) ? scope : [scope];
|
||||
Reflect.defineMetadata(CONTROLLER_REQUIRED_SCOPES, scopes, controllerClass);
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user