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
+71
View File
@@ -0,0 +1,71 @@
import { DateTime } from '../../common/value-objects/date-time/date-time';
import { Status } from '../../common/value-objects/status/status';
import type { PrivilegeAction } from './privilege-action';
export type PrivilegeDetail = {
readonly id: string;
readonly privilegeKeyId: string;
readonly keyCode: string;
readonly keyLabel: string;
readonly sortOrder: number;
readonly action: PrivilegeAction;
readonly value: boolean;
};
export type Privilege = {
readonly id: string;
readonly name: string;
readonly code: string;
readonly status: Status;
readonly createdAt: DateTime;
readonly updatedAt: DateTime;
readonly createdBy: string;
readonly updatedBy: string;
};
export type PrivilegeWithDetails = Privilege & {
readonly details: readonly PrivilegeDetail[];
};
export type PrivilegeDetailInput = {
readonly privilegeKeyId: string;
readonly action: PrivilegeAction;
readonly value: boolean;
};
export type CreatePrivilegeInput = {
readonly name: string;
readonly code: string;
readonly status?: Status;
readonly details?: readonly PrivilegeDetailInput[];
readonly userId: string;
};
export type UpdatePrivilegeInput = {
readonly name?: string;
readonly code?: string;
readonly details?: readonly PrivilegeDetailInput[];
readonly userId: string;
};
export type PrivilegeKey = {
readonly id: string;
readonly code: string;
readonly label: string;
readonly sortOrder: number;
};
export type ListPrivilegesFilters = {
readonly name?: string;
readonly code?: string;
readonly status?: string;
readonly search?: string;
readonly limit: number;
readonly offset: number;
};
export type ListPrivilegeKeysFilters = {
readonly search?: string;
readonly limit: number;
readonly offset: number;
};