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,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;
|
||||
};
|
||||
Reference in New Issue
Block a user