Refactor privilege management to support hierarchical privilege keys
- Updated privilege key structure to use a 3- or 4-part dotted hierarchy (e.g., `GROUP.PARENT.MODULE`). - Modified the `RequirePrivilege` decorator to accept multiple keys, allowing for OR logic in privilege checks. - Enhanced `PrivilegesGuard` to validate against multiple privilege keys, improving access control logic. - Created migration scripts to update existing privilege keys in the database to the new format. - Updated related services, controllers, and tests to accommodate the new privilege key structure and validation logic.
This commit is contained in:
@@ -115,8 +115,8 @@ describe('Privileges (e2e)', () => {
|
||||
|
||||
expect(res.body.data).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ code: 'PRIVILEGES' }),
|
||||
expect.objectContaining({ code: 'USERS' }),
|
||||
expect.objectContaining({ code: 'ADMIN.SETTINGS.USER.PRIVILEGES' }),
|
||||
expect.objectContaining({ code: 'ADMIN.SETTINGS.USER.USERS' }),
|
||||
]),
|
||||
);
|
||||
expect(res.body.meta).toMatchObject({
|
||||
@@ -131,7 +131,7 @@ describe('Privileges (e2e)', () => {
|
||||
.expect(200);
|
||||
const privilegesKey = (
|
||||
keysRes.body.data as { id: string; code: string }[]
|
||||
).find((k) => k.code === 'PRIVILEGES');
|
||||
).find((k) => k.code === 'ADMIN.SETTINGS.USER.PRIVILEGES');
|
||||
expect(privilegesKey).toBeDefined();
|
||||
|
||||
const created = await request(app.getHttpServer())
|
||||
@@ -156,7 +156,7 @@ describe('Privileges (e2e)', () => {
|
||||
createdBy: adminUserId,
|
||||
details: [
|
||||
expect.objectContaining({
|
||||
keyCode: 'PRIVILEGES',
|
||||
keyCode: 'ADMIN.SETTINGS.USER.PRIVILEGES',
|
||||
action: 'view',
|
||||
value: true,
|
||||
}),
|
||||
@@ -202,7 +202,7 @@ describe('Privileges (e2e)', () => {
|
||||
expect(me.body.privilege).toMatchObject({
|
||||
id: adminPrivilegeId,
|
||||
});
|
||||
expect(me.body.permissions.PRIVILEGES.view).toBe(true);
|
||||
expect(me.body.permissions['ADMIN.SETTINGS.USER.PRIVILEGES'].view).toBe(true);
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.patch(`/users/${otherUserId}/privilege`)
|
||||
|
||||
Reference in New Issue
Block a user