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:
@@ -10,7 +10,7 @@ import type { AuthUser } from '../../../common/auth/auth-user';
|
||||
import type { PrivilegeAction } from '../../privileges/privilege-action';
|
||||
import { PrivilegesService } from '../../privileges/privileges.service';
|
||||
import {
|
||||
fieldPrivilegeKey,
|
||||
fieldPrivilegeKeys,
|
||||
isFieldPurpose,
|
||||
type FieldPurpose,
|
||||
type FieldResource,
|
||||
@@ -78,9 +78,9 @@ export class FieldPrivilegeGuard implements CanActivate {
|
||||
const purposes: FieldPurpose[] = ['sales', 'logistics'];
|
||||
const matches: FieldPurpose[] = [];
|
||||
for (const purpose of purposes) {
|
||||
const ok = await this.privilegesService.checkPermission(
|
||||
const ok = await this.privilegesService.checkAnyPermission(
|
||||
userId,
|
||||
fieldPrivilegeKey(resource, purpose),
|
||||
fieldPrivilegeKeys(resource, purpose),
|
||||
action,
|
||||
);
|
||||
if (ok) {
|
||||
|
||||
Reference in New Issue
Block a user