easywork-common-lib 1.0.997 → 1.0.998
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/common/@types/enums/permission.enum.d.ts +32 -0
- package/dist/common/@types/enums/permission.enum.js.map +1 -1
- package/dist/entities/permission.entity.d.ts +2 -0
- package/dist/entities/permission.entity.js +41 -2
- package/dist/entities/permission.entity.js.map +1 -1
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { User } from "../../../entities/user.entity";
|
|
1
2
|
export declare enum Roles {
|
|
2
3
|
ADMIN = "ADMIN",
|
|
3
4
|
USER = "USER",
|
|
@@ -39,11 +40,29 @@ export declare enum PermissionCondition {
|
|
|
39
40
|
TIME_BASED = "timeBased",
|
|
40
41
|
STATUS_BASED = "statusBased"
|
|
41
42
|
}
|
|
43
|
+
export interface FilterCondition {
|
|
44
|
+
field: string;
|
|
45
|
+
operator: "equals" | "in" | "contains" | "not_in" | "is_null" | "is_not_null" | "like" | "gt" | "gte" | "lt" | "lte";
|
|
46
|
+
value?: any;
|
|
47
|
+
values?: any[];
|
|
48
|
+
}
|
|
49
|
+
export interface FilterCriteria {
|
|
50
|
+
fields?: FilterCondition[];
|
|
51
|
+
includeOwn?: boolean;
|
|
52
|
+
includeAssigned?: boolean;
|
|
53
|
+
includeObserved?: boolean;
|
|
54
|
+
includeTeam?: boolean;
|
|
55
|
+
includeGroup?: boolean;
|
|
56
|
+
includeSupervised?: boolean;
|
|
57
|
+
orConditions?: FilterCriteria[];
|
|
58
|
+
andConditions?: FilterCriteria[];
|
|
59
|
+
}
|
|
42
60
|
export interface PermissionRule {
|
|
43
61
|
action: PermissionAction;
|
|
44
62
|
scope: PermissionScope;
|
|
45
63
|
conditions?: PermissionCondition[];
|
|
46
64
|
roleLevel?: number;
|
|
65
|
+
filterCriteria?: FilterCriteria;
|
|
47
66
|
customConditions?: Record<string, any>;
|
|
48
67
|
timeRestrictions?: {
|
|
49
68
|
createdWithin?: number;
|
|
@@ -55,3 +74,16 @@ export interface ResourcePermission {
|
|
|
55
74
|
resource: string;
|
|
56
75
|
rules: PermissionRule[];
|
|
57
76
|
}
|
|
77
|
+
export interface PermissionContextType {
|
|
78
|
+
user: User;
|
|
79
|
+
resource: string;
|
|
80
|
+
action: PermissionAction;
|
|
81
|
+
targetEntity?: any;
|
|
82
|
+
additionalContext?: Record<string, any>;
|
|
83
|
+
}
|
|
84
|
+
export interface PermissionResult {
|
|
85
|
+
allowed: boolean;
|
|
86
|
+
scope?: PermissionScope;
|
|
87
|
+
filters?: Record<string, any>;
|
|
88
|
+
reason?: string;
|
|
89
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission.enum.js","sourceRoot":"","sources":["../../../../src/common/@types/enums/permission.enum.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"permission.enum.js","sourceRoot":"","sources":["../../../../src/common/@types/enums/permission.enum.ts"],"names":[],"mappings":";;;AAEA,IAAY,KAKX;AALD,WAAY,KAAK;IACf,wBAAe,CAAA;IACf,sBAAa,CAAA;IACb,kCAAyB,CAAA;IACzB,0BAAiB,CAAA;AACnB,CAAC,EALW,KAAK,qBAAL,KAAK,QAKhB;AAED,IAAY,gBAeX;AAfD,WAAY,gBAAgB;IAC1B,qCAAiB,CAAA;IACjB,iCAAa,CAAA;IACb,qCAAiB,CAAA;IACjB,qCAAiB,CAAA;IACjB,qCAAiB,CAAA;IACjB,qCAAiB,CAAA;IACjB,qCAAiB,CAAA;IACjB,qCAAiB,CAAA;IACjB,uCAAmB,CAAA;IACnB,qCAAiB,CAAA;IACjB,qCAAiB,CAAA;IACjB,uCAAmB,CAAA;IACnB,mCAAe,CAAA;IACf,uCAAmB,CAAA;AACrB,CAAC,EAfW,gBAAgB,gCAAhB,gBAAgB,QAe3B;AAED,IAAY,eAOX;AAPD,WAAY,eAAe;IACzB,8BAAW,CAAA;IACX,gCAAa,CAAA;IACb,kCAAe,CAAA;IACf,8BAAW,CAAA;IACX,wCAAqB,CAAA;IACrB,4CAAyB,CAAA;AAC3B,CAAC,EAPW,eAAe,+BAAf,eAAe,QAO1B;AAED,IAAY,mBAUX;AAVD,WAAY,mBAAmB;IAC7B,wCAAiB,CAAA;IACjB,sCAAe,CAAA;IACf,iDAA0B,CAAA;IAC1B,4CAAqB,CAAA;IACrB,+CAAwB,CAAA;IACxB,6CAAsB,CAAA;IACtB,+CAAwB,CAAA;IACxB,+CAAwB,CAAA;IACxB,mDAA4B,CAAA;AAC9B,CAAC,EAVW,mBAAmB,mCAAnB,mBAAmB,QAU9B"}
|
|
@@ -21,15 +21,34 @@ let Permission = class Permission extends base_entity_1.EntityBase {
|
|
|
21
21
|
minRoleLevel;
|
|
22
22
|
maxRoleLevel;
|
|
23
23
|
useRoleLevel;
|
|
24
|
+
description;
|
|
25
|
+
priority;
|
|
24
26
|
};
|
|
25
27
|
exports.Permission = Permission;
|
|
26
28
|
__decorate([
|
|
27
|
-
(0, swagger_1.ApiProperty)({
|
|
29
|
+
(0, swagger_1.ApiProperty)({
|
|
30
|
+
type: String,
|
|
31
|
+
description: "Resource for the permission (e.g., 'contact', 'lead', 'policy')",
|
|
32
|
+
}),
|
|
28
33
|
(0, typeorm_1.Column)(),
|
|
29
34
|
__metadata("design:type", String)
|
|
30
35
|
], Permission.prototype, "resource", void 0);
|
|
31
36
|
__decorate([
|
|
32
|
-
(0, swagger_1.ApiProperty)({
|
|
37
|
+
(0, swagger_1.ApiProperty)({
|
|
38
|
+
type: "array",
|
|
39
|
+
description: "Dynamic permission rules with FilterCriteria for data-driven filtering",
|
|
40
|
+
example: [
|
|
41
|
+
{
|
|
42
|
+
action: "read",
|
|
43
|
+
scope: "assigned",
|
|
44
|
+
filterCriteria: {
|
|
45
|
+
includeOwn: true,
|
|
46
|
+
includeAssigned: true,
|
|
47
|
+
includeObserved: true,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
}),
|
|
33
52
|
(0, typeorm_1.Column)({ type: "jsonb", nullable: true }),
|
|
34
53
|
__metadata("design:type", Array)
|
|
35
54
|
], Permission.prototype, "rules", void 0);
|
|
@@ -63,6 +82,26 @@ __decorate([
|
|
|
63
82
|
(0, typeorm_1.Column)({ type: "boolean", default: false }),
|
|
64
83
|
__metadata("design:type", Boolean)
|
|
65
84
|
], Permission.prototype, "useRoleLevel", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
(0, swagger_1.ApiProperty)({
|
|
87
|
+
type: String,
|
|
88
|
+
description: "Human-readable description of what this permission allows",
|
|
89
|
+
required: false,
|
|
90
|
+
example: "Allows team leads to read contacts they own, are assigned to, or observe",
|
|
91
|
+
}),
|
|
92
|
+
(0, typeorm_1.Column)({ type: "text", nullable: true }),
|
|
93
|
+
__metadata("design:type", String)
|
|
94
|
+
], Permission.prototype, "description", void 0);
|
|
95
|
+
__decorate([
|
|
96
|
+
(0, swagger_1.ApiProperty)({
|
|
97
|
+
type: Number,
|
|
98
|
+
description: "Priority order when multiple permissions apply (lower = higher priority)",
|
|
99
|
+
required: false,
|
|
100
|
+
example: 1,
|
|
101
|
+
}),
|
|
102
|
+
(0, typeorm_1.Column)({ type: "int", nullable: true, default: 100 }),
|
|
103
|
+
__metadata("design:type", Number)
|
|
104
|
+
], Permission.prototype, "priority", void 0);
|
|
66
105
|
exports.Permission = Permission = __decorate([
|
|
67
106
|
(0, typeorm_1.Entity)()
|
|
68
107
|
], Permission);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission.entity.js","sourceRoot":"","sources":["../../src/entities/permission.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gEAA4D;AAC5D,qCAAgE;AAChE,+CAAqC;AACrC,6CAA8C;AAIvC,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,wBAAU;
|
|
1
|
+
{"version":3,"file":"permission.entity.js","sourceRoot":"","sources":["../../src/entities/permission.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