mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +00:00
15 lines
674 B
TypeScript
15 lines
674 B
TypeScript
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);
|
|
};
|
|
};
|