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:
@@ -0,0 +1,14 @@
|
||||
/** Dotted uppercase module levels: MODULE / MODULE.RESOURCE / MODULE.RESOURCE.SUB */
|
||||
export const PRIVILEGE_KEY_CODE_PATTERN =
|
||||
/^[A-Z][A-Z0-9_]*(\.[A-Z][A-Z0-9_]*)*$/;
|
||||
|
||||
export function isValidPrivilegeKeyCode(code: string): boolean {
|
||||
return typeof code === 'string' && PRIVILEGE_KEY_CODE_PATTERN.test(code);
|
||||
}
|
||||
|
||||
export function assertPrivilegeKeyCode(code: string): string {
|
||||
if (!isValidPrivilegeKeyCode(code)) {
|
||||
throw new TypeError('Invalid privilege key code');
|
||||
}
|
||||
return code;
|
||||
}
|
||||
Reference in New Issue
Block a user