mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
chore(core): Use dynamic role resolution for access control (#19400)
This commit is contained in:
@@ -49,6 +49,32 @@ export async function createCustomRoleWithScopes(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a custom role with specific scope slugs (using existing permission system scopes)
|
||||
*/
|
||||
export async function createCustomRoleWithScopeSlugs(
|
||||
scopeSlugs: string[],
|
||||
overrides: Partial<Role> = {},
|
||||
): Promise<Role> {
|
||||
const scopeRepository = Container.get(ScopeRepository);
|
||||
|
||||
// Find existing scopes by their slugs
|
||||
const scopes = await scopeRepository.findByList(scopeSlugs);
|
||||
|
||||
if (scopes.length !== scopeSlugs.length) {
|
||||
const missingScopes = scopeSlugs.filter((slug) => !scopes.some((scope) => scope.slug === slug));
|
||||
throw new Error(
|
||||
`Could not find all scopes. Expected ${scopeSlugs.length}, found ${scopes.length}, missing: ${missingScopes.join(', ')}`,
|
||||
);
|
||||
}
|
||||
|
||||
return await createRole({
|
||||
scopes,
|
||||
systemRole: false,
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test scope with given parameters
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user