mirror of
https://github.com/dadosfera/maestro.git
synced 2026-08-31 19:58:21 +00:00
feat(auth): pure helper deriving Orchest identity from permissions
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { deriveOrchestIdentity } from './orchest-identity';
|
||||
|
||||
describe('deriveOrchestIdentity', () => {
|
||||
it('passes permissions through verbatim', () => {
|
||||
expect(deriveOrchestIdentity(['intelligence:open']).permissions).toEqual([
|
||||
'intelligence:open',
|
||||
]);
|
||||
});
|
||||
|
||||
it('marks super-admin from users:admin', () => {
|
||||
expect(deriveOrchestIdentity(['users:admin']).roles).toContain('super-admin');
|
||||
});
|
||||
|
||||
it('omits super-admin when users:admin absent', () => {
|
||||
expect(deriveOrchestIdentity(['intelligence:open']).roles).not.toContain(
|
||||
'super-admin',
|
||||
);
|
||||
});
|
||||
|
||||
it('maps intelligence:open and process:open to module keys', () => {
|
||||
const { modules } = deriveOrchestIdentity(['intelligence:open', 'process:open']);
|
||||
expect(modules.sort()).toEqual(['intelligence', 'process']);
|
||||
});
|
||||
|
||||
it('ignores non-module permissions in modules', () => {
|
||||
expect(deriveOrchestIdentity(['users:admin']).modules).toEqual([]);
|
||||
});
|
||||
|
||||
it('handles undefined/empty permissions', () => {
|
||||
expect(deriveOrchestIdentity(undefined)).toEqual({
|
||||
permissions: [],
|
||||
roles: [],
|
||||
modules: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
// Claim → semantic strings. Seqid knowledge stays here, beside the enum
|
||||
// that owns it (users:admin=34, intelligence:open=31, process:open=43).
|
||||
const ADMIN_CLAIM = 'users:admin';
|
||||
const MODULE_CLAIMS: Record<string, string> = {
|
||||
'intelligence:open': 'intelligence',
|
||||
'process:open': 'process',
|
||||
};
|
||||
|
||||
export type OrchestIdentityFields = {
|
||||
permissions: string[];
|
||||
roles: string[];
|
||||
modules: string[];
|
||||
};
|
||||
|
||||
export function deriveOrchestIdentity(
|
||||
permissions: string[] | undefined,
|
||||
): OrchestIdentityFields {
|
||||
const perms = permissions ?? [];
|
||||
const roles: string[] = [];
|
||||
if (perms.includes(ADMIN_CLAIM)) {
|
||||
roles.push('super-admin');
|
||||
}
|
||||
const modules = Object.entries(MODULE_CLAIMS)
|
||||
.filter(([claim]) => perms.includes(claim))
|
||||
.map(([, key]) => key);
|
||||
return { permissions: perms, roles, modules };
|
||||
}
|
||||
Reference in New Issue
Block a user