feat(editor): Add routing middleware, permission checks, RBAC store, RBAC component (#7702)

Github issue / Community forum post (link here to close automatically):

---------

Co-authored-by: Csaba Tuncsik <csaba@n8n.io>
This commit is contained in:
Alex Grozav
2023-11-23 13:22:47 +02:00
committed by GitHub
parent fdb2c18ecc
commit 67a88914f2
62 changed files with 1935 additions and 646 deletions

View File

@@ -0,0 +1,25 @@
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 });
}
};