Add privilege management system with related migrations and guards

- Introduced a new `PrivilegesModule` to manage user privileges and access control.
- Added `RequirePrivilege` decorator to enforce privilege checks on controller handlers.
- Implemented `PrivilegesGuard` to handle authorization based on user privileges.
- Created database migrations for `privileges`, `privilege_keys`, and `privilege_details` tables.
- Updated user model to include `is_superadmin` field for enhanced access control.
- Added unit tests for the new privileges functionality and guards to ensure correct behavior.
This commit is contained in:
shancheas
2026-08-24 11:31:13 +07:00
parent 0550cbe764
commit 07550b3167
51 changed files with 3731 additions and 27 deletions
+13
View File
@@ -5,6 +5,8 @@ import { AppController } from '../../app.controller';
import { AppService } from '../../app.service';
import { AuthController } from '../../modules/auth/auth.controller';
import { AuthService } from '../../modules/auth/auth.service';
import { PrivilegesService } from '../../modules/privileges/privileges.service';
import { UsersService } from '../../modules/users/users.service';
import {
createOpenApiDocument,
isSwaggerEnabled,
@@ -56,6 +58,17 @@ describe('createOpenApiDocument', () => {
revoke: jest.fn(),
},
},
{
provide: UsersService,
useValue: { findById: jest.fn() },
},
{
provide: PrivilegesService,
useValue: {
findPrivilegeSummary: jest.fn(),
getPermissionsMap: jest.fn(),
},
},
],
}).compile();