mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +00:00
Github issue / Community forum post (link here to close automatically): --------- Co-authored-by: Csaba Tuncsik <csaba@n8n.io>
26 lines
764 B
TypeScript
26 lines
764 B
TypeScript
import type { RouterMiddleware } from '@/types/router';
|
|
import { VIEWS } from '@/constants';
|
|
import {
|
|
inferProjectIdFromRoute,
|
|
inferResourceIdFromRoute,
|
|
inferResourceTypeFromRoute,
|
|
} from '@/utils/rbacUtils';
|
|
import type { RBACPermissionOptions } from '@/types/rbac';
|
|
import { hasScope } from '@/rbac/checks';
|
|
|
|
export const rbacMiddleware: RouterMiddleware<RBACPermissionOptions> = async (
|
|
to,
|
|
from,
|
|
next,
|
|
{ scope, options },
|
|
) => {
|
|
const projectId = inferProjectIdFromRoute(to);
|
|
const resourceType = inferResourceTypeFromRoute(to);
|
|
const resourceId = resourceType ? inferResourceIdFromRoute(to) : undefined;
|
|
|
|
const valid = hasScope({ scope, projectId, resourceType, resourceId, options });
|
|
if (!valid) {
|
|
return next({ name: VIEWS.HOMEPAGE });
|
|
}
|
|
};
|