mirror of
https://github.com/dadosfera/maestro.git
synced 2026-08-31 19:58:21 +00:00
feat(auth): return permissions/roles/modules from /auth/me (all branches)
This commit is contained in:
@@ -494,7 +494,10 @@ export class AuthController {
|
||||
id: api_key.customer_id,
|
||||
name: api_key.customer_name,
|
||||
tier: api_key.customer_tier,
|
||||
}
|
||||
},
|
||||
permissions: [],
|
||||
roles: [],
|
||||
modules: [],
|
||||
};
|
||||
|
||||
return res.status(200).json(userDto);
|
||||
|
||||
@@ -35,6 +35,7 @@ import { BulkEditResponse, UserDTO } from './dtos/login';
|
||||
import jwt, { JwtPayload } from 'jsonwebtoken';
|
||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
||||
import { Request, Response } from 'express';
|
||||
import { deriveOrchestIdentity } from './orchest-identity';
|
||||
|
||||
type AuthSession = {
|
||||
accessToken?: string;
|
||||
@@ -447,6 +448,7 @@ export class AuthClientService implements OnModuleInit {
|
||||
name: payload.customer_name,
|
||||
tier: payload.customer_tier,
|
||||
},
|
||||
...deriveOrchestIdentity(payload.permissions),
|
||||
};
|
||||
|
||||
return userDto;
|
||||
|
||||
@@ -152,5 +152,8 @@ export type UserDTO = {
|
||||
id: string,
|
||||
name: string,
|
||||
tier: string,
|
||||
}
|
||||
},
|
||||
permissions: string[],
|
||||
roles: string[],
|
||||
modules: string[],
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { deriveOrchestIdentity } from './orchest-identity';
|
||||
|
||||
// The three getMe branches must all yield the three fields. This test
|
||||
// pins the SHAPE contract without loading the DUC gRPC client.
|
||||
describe('/auth/me field contract', () => {
|
||||
it('cookie/refresh path derives from payload permissions', () => {
|
||||
const enriched = {
|
||||
id: 'u', name: 'n', email: 'e',
|
||||
customer: { id: 'c', name: 'cust', tier: 't' },
|
||||
...deriveOrchestIdentity(['users:admin', 'intelligence:open']),
|
||||
};
|
||||
expect(enriched.roles).toContain('super-admin');
|
||||
expect(enriched.modules).toContain('intelligence');
|
||||
expect(enriched.permissions).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('api-key branch is empty for all three fields', () => {
|
||||
const apiKeyDto = {
|
||||
id: 'u', name: 'n', email: 'n',
|
||||
customer: { id: 'c', name: 'cust', tier: 't' },
|
||||
permissions: [] as string[], roles: [] as string[], modules: [] as string[],
|
||||
};
|
||||
expect(apiKeyDto.permissions).toEqual([]);
|
||||
expect(apiKeyDto.roles).toEqual([]);
|
||||
expect(apiKeyDto.modules).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user