law-common 14.0.10-beta.3 → 14.0.10-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/entities/enums/permission_group_enum.d.ts +24 -0
- package/dist/src/entities/enums/permission_group_enum.js +49 -0
- package/dist/src/entities/flow-configs/base-flow-config.factory.d.ts +8 -0
- package/dist/src/entities/flow-configs/base-flow-config.factory.js +1 -75
- package/dist/src/entities/flow-configs/flow-config.type.d.ts +11 -0
- package/dist/src/entities/flow-configs/work_from_home_flow.config.js +9 -0
- package/dist/src/entities/index.d.ts +1 -0
- package/dist/src/entities/index.js +1 -0
- package/dist/src/entities/interface/field-constraint/permission_field_constraints.interface.js +8 -0
- package/dist/src/entities/interface/permission.entity.interface.d.ts +8 -0
- package/dist/src/entities/model/permission.entity.model.d.ts +12 -0
- package/dist/src/entities/model/permission.entity.model.js +48 -0
- package/dist/src/enums/error.key.enum.d.ts +3 -1
- package/dist/src/enums/error.key.enum.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare enum PermissionGroupEnum {
|
|
2
|
+
CREATE = "CREATE",
|
|
3
|
+
READ = "READ",
|
|
4
|
+
UPDATE = "UPDATE",
|
|
5
|
+
DELETE = "DELETE",
|
|
6
|
+
APPROVAL_FLOW = "APPROVAL_FLOW",
|
|
7
|
+
NAV = "NAV",
|
|
8
|
+
EXPORT = "EXPORT"
|
|
9
|
+
}
|
|
10
|
+
export declare namespace PermissionGroupEnum {
|
|
11
|
+
/**
|
|
12
|
+
* Permission-name token -> group.
|
|
13
|
+
*
|
|
14
|
+
* Order is significant. PermissionEntityModel.derivePermissionGroup resolves the *first*
|
|
15
|
+
* token that matches, so a token listed earlier wins when a name contains two of them
|
|
16
|
+
* (e.g. VENDOR_INVOICE_PAYMENT_PROCESSOR resolves via PROCESSOR, not PAYMENT - both map to
|
|
17
|
+
* UPDATE today, but that is a coincidence rather than a guarantee).
|
|
18
|
+
*
|
|
19
|
+
* Tokens are matched as `_TOKEN_` (interior) or `_TOKEN` (trailing) unless the name starts
|
|
20
|
+
* with them, which derivePermissionGroup checks separately - the `_TOKEN_` matcher cannot
|
|
21
|
+
* see a leading token.
|
|
22
|
+
*/
|
|
23
|
+
const MAPPING: Record<string, PermissionGroupEnum>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PermissionGroupEnum = void 0;
|
|
4
|
+
var PermissionGroupEnum;
|
|
5
|
+
(function (PermissionGroupEnum) {
|
|
6
|
+
PermissionGroupEnum["CREATE"] = "CREATE";
|
|
7
|
+
PermissionGroupEnum["READ"] = "READ";
|
|
8
|
+
PermissionGroupEnum["UPDATE"] = "UPDATE";
|
|
9
|
+
PermissionGroupEnum["DELETE"] = "DELETE";
|
|
10
|
+
PermissionGroupEnum["APPROVAL_FLOW"] = "APPROVAL_FLOW";
|
|
11
|
+
PermissionGroupEnum["NAV"] = "NAV";
|
|
12
|
+
PermissionGroupEnum["EXPORT"] = "EXPORT";
|
|
13
|
+
})(PermissionGroupEnum || (exports.PermissionGroupEnum = PermissionGroupEnum = {}));
|
|
14
|
+
(function (PermissionGroupEnum) {
|
|
15
|
+
/**
|
|
16
|
+
* Permission-name token -> group.
|
|
17
|
+
*
|
|
18
|
+
* Order is significant. PermissionEntityModel.derivePermissionGroup resolves the *first*
|
|
19
|
+
* token that matches, so a token listed earlier wins when a name contains two of them
|
|
20
|
+
* (e.g. VENDOR_INVOICE_PAYMENT_PROCESSOR resolves via PROCESSOR, not PAYMENT - both map to
|
|
21
|
+
* UPDATE today, but that is a coincidence rather than a guarantee).
|
|
22
|
+
*
|
|
23
|
+
* Tokens are matched as `_TOKEN_` (interior) or `_TOKEN` (trailing) unless the name starts
|
|
24
|
+
* with them, which derivePermissionGroup checks separately - the `_TOKEN_` matcher cannot
|
|
25
|
+
* see a leading token.
|
|
26
|
+
*/
|
|
27
|
+
PermissionGroupEnum.MAPPING = {
|
|
28
|
+
CREATE: PermissionGroupEnum.CREATE,
|
|
29
|
+
READ: PermissionGroupEnum.READ,
|
|
30
|
+
UPDATE: PermissionGroupEnum.UPDATE,
|
|
31
|
+
DELETE: PermissionGroupEnum.DELETE,
|
|
32
|
+
APPROVER: PermissionGroupEnum.APPROVAL_FLOW,
|
|
33
|
+
APPROVAL_FLOW: PermissionGroupEnum.APPROVAL_FLOW,
|
|
34
|
+
NAV: PermissionGroupEnum.NAV,
|
|
35
|
+
VIEW: PermissionGroupEnum.READ,
|
|
36
|
+
AMENDMENT: PermissionGroupEnum.UPDATE,
|
|
37
|
+
APPROVE: PermissionGroupEnum.APPROVAL_FLOW,
|
|
38
|
+
ACTIVATE: PermissionGroupEnum.UPDATE,
|
|
39
|
+
DEACTIVATE: PermissionGroupEnum.UPDATE,
|
|
40
|
+
RESTORE: PermissionGroupEnum.UPDATE,
|
|
41
|
+
CREATOR: PermissionGroupEnum.CREATE,
|
|
42
|
+
SEARCH: PermissionGroupEnum.READ,
|
|
43
|
+
PROCESSOR: PermissionGroupEnum.UPDATE,
|
|
44
|
+
PAYMENT: PermissionGroupEnum.UPDATE,
|
|
45
|
+
ESCALATION: PermissionGroupEnum.UPDATE,
|
|
46
|
+
MOVE_PROJECT: PermissionGroupEnum.UPDATE,
|
|
47
|
+
EXPORT: PermissionGroupEnum.EXPORT,
|
|
48
|
+
};
|
|
49
|
+
})(PermissionGroupEnum || (exports.PermissionGroupEnum = PermissionGroupEnum = {}));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PermissionGroupEnum } from "../enums/permission_group_enum";
|
|
1
2
|
/**
|
|
2
3
|
* Generic flow-config factory.
|
|
3
4
|
*
|
|
@@ -80,6 +81,12 @@
|
|
|
80
81
|
export type ActionMapEntry<S extends string> = {
|
|
81
82
|
readonly reachableStatues: readonly S[];
|
|
82
83
|
readonly permissions: string[];
|
|
84
|
+
/**
|
|
85
|
+
* Permission group shared by every permission in `permissions`. Declared once here rather
|
|
86
|
+
* than per call so `createActionConfig` can stamp it onto each (status, action) transition
|
|
87
|
+
* without every call site having to pass it. See `IFlowConfigActionConfig.group`.
|
|
88
|
+
*/
|
|
89
|
+
readonly group?: PermissionGroupEnum;
|
|
83
90
|
};
|
|
84
91
|
/**
|
|
85
92
|
* Full action map: one entry per action value.
|
|
@@ -125,6 +132,7 @@ export declare function createFlowConfigFactory<CTX = never>(): <A extends strin
|
|
|
125
132
|
createActionConfig: <Act extends A, Subset extends { [key in A]: AM[key]["reachableStatues"]; }[Act][number] = { [key in A]: AM[key]["reachableStatues"]; }[Act][number]>(action: Act, nextStatus: Subset | ((context: CTX) => Subset), overridePermissions?: string[], options?: ActionConfigOptions<CTX>) => {
|
|
126
133
|
description?: string | undefined;
|
|
127
134
|
isApplicable?: ((context: CTX) => boolean) | undefined;
|
|
135
|
+
group?: PermissionGroupEnum | undefined;
|
|
128
136
|
permissions: string[];
|
|
129
137
|
next: (context: CTX) => Subset;
|
|
130
138
|
};
|
|
@@ -1,78 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Generic flow-config factory.
|
|
4
|
-
*
|
|
5
|
-
* Provides a reusable, type-safe `createActionConfig` helper for any entity
|
|
6
|
-
* flow configuration. Eliminates boilerplate type plumbing (ActionStatusMap,
|
|
7
|
-
* StateStatusForAction, createTransition) that would otherwise be duplicated
|
|
8
|
-
* in every flow config file.
|
|
9
|
-
*
|
|
10
|
-
* ---
|
|
11
|
-
* **Usage — basic**
|
|
12
|
-
* ```typescript
|
|
13
|
-
* import { createFlowConfigFactory } from "./base-flow-config.factory";
|
|
14
|
-
*
|
|
15
|
-
* const ACTION_MAP = {
|
|
16
|
-
* [MyActionEnum.APPROVE]: { statuses: [MyStatusEnum.APPROVED] as const, permissions: ["MY_APPROVE"] },
|
|
17
|
-
* [MyActionEnum.REJECT]: { statuses: [MyStatusEnum.REJECTED] as const, permissions: ["MY_REJECT"] },
|
|
18
|
-
* } satisfies ActionMap<MyActionEnum, MyStatusEnum>;
|
|
19
|
-
*
|
|
20
|
-
* const { createActionConfig } = createFlowConfigFactory<IMyContextData>()(ACTION_MAP);
|
|
21
|
-
*
|
|
22
|
-
* const transition = createActionConfig(MyStatusEnum.APPROVED, MyActionEnum.APPROVE);
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* ---
|
|
26
|
-
* **Usage — overriding a transition permission**
|
|
27
|
-
* ```typescript
|
|
28
|
-
* createActionConfig(MyStatusEnum.APPROVED, MyActionEnum.APPROVE, ["CUSTOM_APPROVE_PERM"]);
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* ---
|
|
32
|
-
* **Usage — context-driven (multi-outcome) transition**
|
|
33
|
-
* ```typescript
|
|
34
|
-
* createActionConfig(
|
|
35
|
-
* (ctx: IMyContextData) => ctx.fast ? MyStatusEnum.APPROVED : MyStatusEnum.PENDING,
|
|
36
|
-
* MyActionEnum.APPROVE,
|
|
37
|
-
* );
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* ---
|
|
41
|
-
* **Usage — subset narrowing**
|
|
42
|
-
* Restrict the compiler to a subset of the action's possible target statuses:
|
|
43
|
-
* ```typescript
|
|
44
|
-
* createActionConfig<MyActionEnum.APPROVE, MyStatusEnum.APPROVED>(
|
|
45
|
-
* MyStatusEnum.APPROVED,
|
|
46
|
-
* MyActionEnum.APPROVE,
|
|
47
|
-
* );
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* ---
|
|
51
|
-
* **Extending base enums**
|
|
52
|
-
* TypeScript enums cannot be inherited, but entity-specific enums can
|
|
53
|
-
* re-declare base values and add new ones:
|
|
54
|
-
* ```typescript
|
|
55
|
-
* import { BaseFlowActionEnum, BaseFlowStatusEnum } from "./base-flow-config.enums";
|
|
56
|
-
*
|
|
57
|
-
* export enum VendorActionEnum {
|
|
58
|
-
* VIEW = BaseFlowActionEnum.VIEW,
|
|
59
|
-
* CREATE = BaseFlowActionEnum.CREATE,
|
|
60
|
-
* UPDATE = BaseFlowActionEnum.UPDATE,
|
|
61
|
-
* DELETE = BaseFlowActionEnum.DELETE,
|
|
62
|
-
* APPROVE = BaseFlowActionEnum.APPROVE,
|
|
63
|
-
* REJECT = BaseFlowActionEnum.REJECT,
|
|
64
|
-
* RECALL = BaseFlowActionEnum.RECALL,
|
|
65
|
-
* DEACTIVATE = BaseFlowActionEnum.DEACTIVATE,
|
|
66
|
-
* SUBMIT = "submit", // ← extension
|
|
67
|
-
* }
|
|
68
|
-
*
|
|
69
|
-
* export enum VendorStatusEnum {
|
|
70
|
-
* ACTIVE = BaseFlowStatusEnum.ACTIVE,
|
|
71
|
-
* // ... all base statuses ...
|
|
72
|
-
* SUBMITTED = "SUBMITTED", // ← extension
|
|
73
|
-
* }
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
77
3
|
exports.createFlowConfigFactory = createFlowConfigFactory;
|
|
78
4
|
function createFlowConfigFactory() {
|
|
@@ -99,7 +25,7 @@ function createFlowConfigFactory() {
|
|
|
99
25
|
* (currentStatus, action) pair. Must be a subtype of
|
|
100
26
|
* `StatusForAction<Act>`.
|
|
101
27
|
*/
|
|
102
|
-
const createActionConfig = (action, nextStatus, overridePermissions, options) => (Object.assign(Object.assign({ permissions: overridePermissions !== null && overridePermissions !== void 0 ? overridePermissions : actionMap[action].permissions, next: createTransition(nextStatus) }, ((options === null || options === void 0 ? void 0 : options.isApplicable) !== undefined ? { isApplicable: options.isApplicable } : {})), ((options === null || options === void 0 ? void 0 : options.description) !== undefined ? { description: options.description } : {})));
|
|
28
|
+
const createActionConfig = (action, nextStatus, overridePermissions, options) => (Object.assign(Object.assign(Object.assign({ permissions: overridePermissions !== null && overridePermissions !== void 0 ? overridePermissions : actionMap[action].permissions, next: createTransition(nextStatus) }, (actionMap[action].group !== undefined ? { group: actionMap[action].group } : {})), ((options === null || options === void 0 ? void 0 : options.isApplicable) !== undefined ? { isApplicable: options.isApplicable } : {})), ((options === null || options === void 0 ? void 0 : options.description) !== undefined ? { description: options.description } : {})));
|
|
103
29
|
return { createActionConfig, createTransition };
|
|
104
30
|
};
|
|
105
31
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PermissionGroupEnum } from "../enums/permission_group_enum";
|
|
1
2
|
/**
|
|
2
3
|
* Defines the complete state machine configuration for a domain entity.
|
|
3
4
|
* Maps each status to its available actions and their metadata.
|
|
@@ -69,4 +70,14 @@ export interface IFlowConfigActionConfig<STATUS_ENUM_TYPE extends string, CONTEX
|
|
|
69
70
|
* to the row in its current state.
|
|
70
71
|
*/
|
|
71
72
|
isApplicable?: (data: CONTEXT_DATA_TYPE) => boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Permission group this action's permissions belong to, as stored on `permission.group`.
|
|
75
|
+
*
|
|
76
|
+
* Consumers that authorise against a single (entity, group) pair - rather than against the
|
|
77
|
+
* union of every permission in a filter map - read this to pick which permission applies.
|
|
78
|
+
* Optional so flow configs that do not participate in that path stay unchanged; a consumer
|
|
79
|
+
* that requires it should treat an absent value as an error rather than defaulting, since a
|
|
80
|
+
* silent default would authorise the action under the wrong group.
|
|
81
|
+
*/
|
|
82
|
+
group?: PermissionGroupEnum;
|
|
72
83
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.workFromHomeFlowConfig = void 0;
|
|
4
4
|
const base_flow_config_factory_1 = require("./base-flow-config.factory");
|
|
5
|
+
const permission_group_enum_1 = require("../enums/permission_group_enum");
|
|
5
6
|
const work_from_home_action_enum_1 = require("../enums/work_from_home_action_enum");
|
|
6
7
|
const work_from_home_status_enum_1 = require("../enums/work_from_home_status_enum");
|
|
7
8
|
// ORG/SELF permissions — matching legacy pattern from work_from_home.flow.config.ts
|
|
@@ -11,10 +12,13 @@ const WORK_FROM_HOME_DELETE_PERMISSION = ["WORK_FROM_HOME_DELETE_SELF"];
|
|
|
11
12
|
const WORK_FROM_HOME_APPROVE_PERMISSION = ["WORK_FROM_HOME_APPROVER_ORG"];
|
|
12
13
|
const WORK_FROM_HOME_REJECT_PERMISSION = ["WORK_FROM_HOME_APPROVER_ORG"];
|
|
13
14
|
const WORK_FROM_HOME_RECALL_PERMISSION = ["WORK_FROM_HOME_UPDATE_ORG", "WORK_FROM_HOME_UPDATE_SELF"];
|
|
15
|
+
// Every action declares its group. work_from_home_bulk_update.transaction.ts refuses to
|
|
16
|
+
// default an absent group, so all six must be annotated for any transition to keep working.
|
|
14
17
|
const ACTION_MAP = {
|
|
15
18
|
[work_from_home_action_enum_1.WorkFromHomeActionEnum.CREATE]: {
|
|
16
19
|
reachableStatues: [work_from_home_status_enum_1.WorkFromHomeStatusEnum.CREATE_APPROVAL_PENDING],
|
|
17
20
|
permissions: WORK_FROM_HOME_CREATE_PERMISSION,
|
|
21
|
+
group: permission_group_enum_1.PermissionGroupEnum.CREATE,
|
|
18
22
|
},
|
|
19
23
|
[work_from_home_action_enum_1.WorkFromHomeActionEnum.UPDATE]: {
|
|
20
24
|
reachableStatues: [
|
|
@@ -23,22 +27,27 @@ const ACTION_MAP = {
|
|
|
23
27
|
// WorkFromHomeStatusEnum.CHANGE_REQUESTED,
|
|
24
28
|
],
|
|
25
29
|
permissions: WORK_FROM_HOME_UPDATE_PERMISSION,
|
|
30
|
+
group: permission_group_enum_1.PermissionGroupEnum.UPDATE,
|
|
26
31
|
},
|
|
27
32
|
[work_from_home_action_enum_1.WorkFromHomeActionEnum.DELETE]: {
|
|
28
33
|
reachableStatues: [work_from_home_status_enum_1.WorkFromHomeStatusEnum.DELETE_APPROVAL_PENDING, work_from_home_status_enum_1.WorkFromHomeStatusEnum.DELETED],
|
|
29
34
|
permissions: WORK_FROM_HOME_DELETE_PERMISSION,
|
|
35
|
+
group: permission_group_enum_1.PermissionGroupEnum.DELETE,
|
|
30
36
|
},
|
|
31
37
|
[work_from_home_action_enum_1.WorkFromHomeActionEnum.APPROVE]: {
|
|
32
38
|
reachableStatues: [work_from_home_status_enum_1.WorkFromHomeStatusEnum.APPROVED, work_from_home_status_enum_1.WorkFromHomeStatusEnum.DELETED],
|
|
33
39
|
permissions: WORK_FROM_HOME_APPROVE_PERMISSION,
|
|
40
|
+
group: permission_group_enum_1.PermissionGroupEnum.APPROVAL_FLOW,
|
|
34
41
|
},
|
|
35
42
|
[work_from_home_action_enum_1.WorkFromHomeActionEnum.REJECT]: {
|
|
36
43
|
reachableStatues: [work_from_home_status_enum_1.WorkFromHomeStatusEnum.REJECTED, work_from_home_status_enum_1.WorkFromHomeStatusEnum.RESOLVED_REJECTED],
|
|
37
44
|
permissions: WORK_FROM_HOME_REJECT_PERMISSION,
|
|
45
|
+
group: permission_group_enum_1.PermissionGroupEnum.APPROVAL_FLOW,
|
|
38
46
|
},
|
|
39
47
|
[work_from_home_action_enum_1.WorkFromHomeActionEnum.RECALL]: {
|
|
40
48
|
reachableStatues: [work_from_home_status_enum_1.WorkFromHomeStatusEnum.APPROVED],
|
|
41
49
|
permissions: WORK_FROM_HOME_RECALL_PERMISSION,
|
|
50
|
+
group: permission_group_enum_1.PermissionGroupEnum.UPDATE,
|
|
42
51
|
},
|
|
43
52
|
};
|
|
44
53
|
const { createActionConfig } = (0, base_flow_config_factory_1.createFlowConfigFactory)()(ACTION_MAP);
|
|
@@ -72,6 +72,7 @@ export * from "./enums/client_affiliate_status_enum";
|
|
|
72
72
|
export * from "./flow-configs/client_affiliate_flow.config";
|
|
73
73
|
export * from "./interface/client_affiliate.entity.interface";
|
|
74
74
|
export * from "./interface/field-constraint/client_affiliate_field_constraints.interface";
|
|
75
|
+
export * from "./enums/permission_group_enum";
|
|
75
76
|
export * from "./interface/permission.entity.interface";
|
|
76
77
|
export * from "./interface/field-constraint/permission_field_constraints.interface";
|
|
77
78
|
export * from "./interface/role.entity.interface";
|
|
@@ -88,6 +88,7 @@ __exportStar(require("./enums/client_affiliate_status_enum"), exports);
|
|
|
88
88
|
__exportStar(require("./flow-configs/client_affiliate_flow.config"), exports);
|
|
89
89
|
__exportStar(require("./interface/client_affiliate.entity.interface"), exports);
|
|
90
90
|
__exportStar(require("./interface/field-constraint/client_affiliate_field_constraints.interface"), exports);
|
|
91
|
+
__exportStar(require("./enums/permission_group_enum"), exports);
|
|
91
92
|
__exportStar(require("./interface/permission.entity.interface"), exports);
|
|
92
93
|
__exportStar(require("./interface/field-constraint/permission_field_constraints.interface"), exports);
|
|
93
94
|
__exportStar(require("./interface/role.entity.interface"), exports);
|
package/dist/src/entities/interface/field-constraint/permission_field_constraints.interface.js
CHANGED
|
@@ -12,4 +12,12 @@ exports.permissionFieldMinMaxConstraints = {
|
|
|
12
12
|
organizationId: {
|
|
13
13
|
max: 9999999,
|
|
14
14
|
},
|
|
15
|
+
/** LW-850: `entity` holds an EntityEnum value; the longest one is 37 chars, 64 leaves headroom */
|
|
16
|
+
entity: {
|
|
17
|
+
max: 64,
|
|
18
|
+
},
|
|
19
|
+
/** LW-850: the column holds a PermissionGroupEnum value (CRUD / APPROVAL_FLOW); 64 is generous */
|
|
20
|
+
group: {
|
|
21
|
+
max: 64,
|
|
22
|
+
},
|
|
15
23
|
};
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
import { PermissionGroupEnum } from "../enums/permission_group_enum";
|
|
2
|
+
import { EntityEnum } from "./entity.utils.interface";
|
|
1
3
|
import { IEntityAuditColumn } from "./entity-audit-columns.interface";
|
|
2
4
|
export interface IPermissionEntity extends IEntityAuditColumn {
|
|
3
5
|
id: number;
|
|
4
6
|
name: string;
|
|
5
7
|
description?: string;
|
|
6
8
|
organizationId: number;
|
|
9
|
+
/**
|
|
10
|
+
* nullable on purpose — the backfill is incomplete, and an unmapped row must keep
|
|
11
|
+
* resolving by name until it is mapped. promoted to NOT NULL in a follow-up migration.
|
|
12
|
+
*/
|
|
13
|
+
entity?: EntityEnum;
|
|
14
|
+
group?: PermissionGroupEnum;
|
|
7
15
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PermissionGroupEnum } from "../enums/permission_group_enum";
|
|
1
2
|
import { EntityEnum } from "../interface/entity.utils.interface";
|
|
2
3
|
import { IPermissionEntity } from "../interface/permission.entity.interface";
|
|
3
4
|
import { RelationConfigs } from "../interface/relation-config.interface";
|
|
@@ -11,6 +12,8 @@ export declare class PermissionEntityModel extends BaseEntityModel<EntityEnum.PE
|
|
|
11
12
|
name: string;
|
|
12
13
|
description?: string;
|
|
13
14
|
organizationId: number;
|
|
15
|
+
entity?: EntityEnum;
|
|
16
|
+
group?: PermissionGroupEnum;
|
|
14
17
|
createdOn: number;
|
|
15
18
|
updatedOn: number;
|
|
16
19
|
createdBy: number;
|
|
@@ -24,4 +27,13 @@ export declare class PermissionEntityModel extends BaseEntityModel<EntityEnum.PE
|
|
|
24
27
|
get rolePermissionEntityModels(): RolePermissionMappingEntityModel[];
|
|
25
28
|
get roleEntityModels(): RoleEntityModel[];
|
|
26
29
|
get userEntityModels(): UserEntityModel[];
|
|
30
|
+
/**
|
|
31
|
+
* Permission names do not reliably use the entity's own vocabulary, so the leading token is
|
|
32
|
+
* rewritten through this table before the prefix is matched against EntityEnum. Without it
|
|
33
|
+
* TIMESHEETS_APPROVER_ORG resolves to nothing: EntityEnum.TIMESHEET is singular, and a
|
|
34
|
+
* `startsWith("timesheet_")` test never matches "timesheets_".
|
|
35
|
+
*/
|
|
36
|
+
private static readonly ENTITY_PREFIX_ALIAS;
|
|
37
|
+
static derivePermissionGroup(name: string): PermissionGroupEnum | undefined;
|
|
38
|
+
static deriveEntity(name: string): EntityEnum | undefined;
|
|
27
39
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PermissionEntityModel = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
|
+
const permission_group_enum_1 = require("../enums/permission_group_enum");
|
|
5
6
|
const relation_type_enum_1 = require("../enums/relation_type_enum");
|
|
6
7
|
const entity_utils_interface_1 = require("../interface/entity.utils.interface");
|
|
7
8
|
const base_entity_model_1 = require("./base.entity.model");
|
|
@@ -49,6 +50,34 @@ class PermissionEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
|
49
50
|
}
|
|
50
51
|
return (0, utils_1.removeDuplicatesByKey)(users, "id");
|
|
51
52
|
}
|
|
53
|
+
static derivePermissionGroup(name) {
|
|
54
|
+
var _a;
|
|
55
|
+
const mappings = Object.entries(permission_group_enum_1.PermissionGroupEnum.MAPPING);
|
|
56
|
+
// A group token in first position is invisible to the `_TOKEN_` matcher below, and
|
|
57
|
+
// EXPORT_*_DATA is the only such family currently in use.
|
|
58
|
+
const leading = mappings.find(([group]) => name.startsWith(`${group}_`));
|
|
59
|
+
if (leading)
|
|
60
|
+
return leading[1];
|
|
61
|
+
return (_a = mappings.find(([group]) => name.includes(`_${group}_`) || name.endsWith(`_${group}`))) === null || _a === void 0 ? void 0 : _a[1];
|
|
62
|
+
}
|
|
63
|
+
static deriveEntity(name) {
|
|
64
|
+
let permissionName = name.toLowerCase();
|
|
65
|
+
// EXPORT_BANK_DATA belongs to the bank entity, so strip the export framing first and let
|
|
66
|
+
// the alias table below resolve the remainder.
|
|
67
|
+
const exportMatch = /^export_(.+)_data$/.exec(permissionName);
|
|
68
|
+
if (exportMatch)
|
|
69
|
+
permissionName = `${exportMatch[1]}_`;
|
|
70
|
+
for (const [alias, entity] of Object.entries(PermissionEntityModel.ENTITY_PREFIX_ALIAS)) {
|
|
71
|
+
if (permissionName.startsWith(`${alias}_`)) {
|
|
72
|
+
permissionName = entity + permissionName.slice(alias.length);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Longest match wins so BILLING_TRANSACTION_* resolves to billing_transaction, not billing.
|
|
77
|
+
return Object.values(entity_utils_interface_1.EntityEnum)
|
|
78
|
+
.filter((entity) => permissionName.startsWith(`${entity}_`))
|
|
79
|
+
.sort((a, b) => b.length - a.length)[0];
|
|
80
|
+
}
|
|
52
81
|
}
|
|
53
82
|
exports.PermissionEntityModel = PermissionEntityModel;
|
|
54
83
|
PermissionEntityModel.relationConfigs = [
|
|
@@ -62,3 +91,22 @@ PermissionEntityModel.relationConfigs = [
|
|
|
62
91
|
},
|
|
63
92
|
},
|
|
64
93
|
];
|
|
94
|
+
/**
|
|
95
|
+
* Permission names do not reliably use the entity's own vocabulary, so the leading token is
|
|
96
|
+
* rewritten through this table before the prefix is matched against EntityEnum. Without it
|
|
97
|
+
* TIMESHEETS_APPROVER_ORG resolves to nothing: EntityEnum.TIMESHEET is singular, and a
|
|
98
|
+
* `startsWith("timesheet_")` test never matches "timesheets_".
|
|
99
|
+
*/
|
|
100
|
+
PermissionEntityModel.ENTITY_PREFIX_ALIAS = {
|
|
101
|
+
timesheets: entity_utils_interface_1.EntityEnum.TIMESHEET,
|
|
102
|
+
work_templates: entity_utils_interface_1.EntityEnum.TASK,
|
|
103
|
+
employee: entity_utils_interface_1.EntityEnum.USER,
|
|
104
|
+
clients: entity_utils_interface_1.EntityEnum.CLIENT,
|
|
105
|
+
roles_permissions: entity_utils_interface_1.EntityEnum.ROLE_PERMISSION_MAPPING,
|
|
106
|
+
bankdetails: entity_utils_interface_1.EntityEnum.BANK,
|
|
107
|
+
cron_job: entity_utils_interface_1.EntityEnum.CRON_JOBS,
|
|
108
|
+
resource: entity_utils_interface_1.EntityEnum.USER,
|
|
109
|
+
// Seeded name is misspelled; corrected here rather than by renaming the permission row,
|
|
110
|
+
// which would orphan every role_permission_mapping pointing at it.
|
|
111
|
+
blling: entity_utils_interface_1.EntityEnum.BILLING,
|
|
112
|
+
};
|
|
@@ -37,5 +37,7 @@ export declare enum ErrorKeyEnum {
|
|
|
37
37
|
CONFIGURATION_KEY = "CONFIGURATION_KEY",
|
|
38
38
|
VENDOR_INVOICE_FLOW_CONTEXT_DATA = "VENDOR_INVOICE_FLOW_CONTEXT_DATA",
|
|
39
39
|
VENDOR_TDS_LIABILITY_FLOW_CONTEXT_DATA = "VENDOR_TDS_LIABILITY_FLOW_CONTEXT_DATA",
|
|
40
|
-
DESIGNATION_ENTITIES = "DESIGNATION_ENTITIES"
|
|
40
|
+
DESIGNATION_ENTITIES = "DESIGNATION_ENTITIES",
|
|
41
|
+
PERMISSION_GROUP = "PERMISSION_GROUP",
|
|
42
|
+
ENTITY = "ENTITY"
|
|
41
43
|
}
|
|
@@ -42,4 +42,6 @@ var ErrorKeyEnum;
|
|
|
42
42
|
ErrorKeyEnum["VENDOR_INVOICE_FLOW_CONTEXT_DATA"] = "VENDOR_INVOICE_FLOW_CONTEXT_DATA";
|
|
43
43
|
ErrorKeyEnum["VENDOR_TDS_LIABILITY_FLOW_CONTEXT_DATA"] = "VENDOR_TDS_LIABILITY_FLOW_CONTEXT_DATA";
|
|
44
44
|
ErrorKeyEnum["DESIGNATION_ENTITIES"] = "DESIGNATION_ENTITIES";
|
|
45
|
+
ErrorKeyEnum["PERMISSION_GROUP"] = "PERMISSION_GROUP";
|
|
46
|
+
ErrorKeyEnum["ENTITY"] = "ENTITY";
|
|
45
47
|
})(ErrorKeyEnum || (exports.ErrorKeyEnum = ErrorKeyEnum = {}));
|