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:
@@ -13,7 +13,7 @@ const LOGISTICS_PREFIX = `${REPORT_GROUP.LOGISTICS_REPORT}__`;
|
||||
export const salesOrderReport: ReportConfigEntity = {
|
||||
groupName: REPORT_GROUP.SALES_REPORT,
|
||||
uniqueName: `${SALES_PREFIX}sales_order`,
|
||||
privilegeKey: 'SALES.REPORT',
|
||||
privilegeKey: 'ADMIN.SALES.REPORT',
|
||||
label: 'Report Sales Order',
|
||||
tableSchema: `sales_orders main
|
||||
JOIN customers cust ON cust.id = main.customer_id
|
||||
@@ -138,7 +138,7 @@ export const salesOrderReport: ReportConfigEntity = {
|
||||
export const salesRequestReport: ReportConfigEntity = {
|
||||
groupName: REPORT_GROUP.SALES_REPORT,
|
||||
uniqueName: `${SALES_PREFIX}sales_request`,
|
||||
privilegeKey: 'SALES.REPORT',
|
||||
privilegeKey: 'ADMIN.SALES.REPORT',
|
||||
label: 'Report Request Order',
|
||||
tableSchema: `sales_requests main
|
||||
JOIN customers cust ON cust.id = main.customer_id
|
||||
@@ -250,7 +250,7 @@ export const salesRequestReport: ReportConfigEntity = {
|
||||
export const salesInvoiceReport: ReportConfigEntity = {
|
||||
groupName: REPORT_GROUP.SALES_REPORT,
|
||||
uniqueName: `${SALES_PREFIX}sales_invoice`,
|
||||
privilegeKey: 'SALES.REPORT',
|
||||
privilegeKey: 'ADMIN.SALES.REPORT',
|
||||
label: 'Report Invoice',
|
||||
tableSchema: `sales_invoices main
|
||||
JOIN customers cust ON cust.id = main.customer_id
|
||||
@@ -365,7 +365,7 @@ export const salesInvoiceReport: ReportConfigEntity = {
|
||||
export const salesPaymentReport: ReportConfigEntity = {
|
||||
groupName: REPORT_GROUP.SALES_REPORT,
|
||||
uniqueName: `${SALES_PREFIX}sales_payment`,
|
||||
privilegeKey: 'SALES.REPORT',
|
||||
privilegeKey: 'ADMIN.SALES.REPORT',
|
||||
label: 'Report Payment',
|
||||
tableSchema: `sales_payments main
|
||||
JOIN sales_payment_invoices spi ON spi.sales_payment_id = main.id
|
||||
@@ -476,7 +476,7 @@ export const salesPaymentReport: ReportConfigEntity = {
|
||||
export const visitPlanReport: ReportConfigEntity = {
|
||||
groupName: REPORT_GROUP.SALES_REPORT,
|
||||
uniqueName: `${SALES_PREFIX}visit_plan`,
|
||||
privilegeKey: 'SALES.REPORT',
|
||||
privilegeKey: 'ADMIN.SALES.REPORT',
|
||||
label: 'Report Visit Plan',
|
||||
tableSchema: `plans main
|
||||
JOIN employees emp ON emp.id = main.employee_id
|
||||
|
||||
Reference in New Issue
Block a user