@tomei/sso 0.37.4 → 0.38.0
Sign up to get free protection for your applications and to get access to all the features.
- package/__tests__/unit/components/group-object-privilege/group-object-privilege.spec.ts +4 -4
- package/__tests__/unit/components/group-privilege/group-privilege.spec.ts +3 -3
- package/__tests__/unit/components/user-object-privilege/user-object-privilege.spec.ts +3 -3
- package/__tests__/unit/components/user-privilege/user-privilege.spec.ts +3 -3
- package/dist/__tests__/unit/components/group-object-privilege/group-object-privilege.spec.js +4 -4
- package/dist/__tests__/unit/components/group-object-privilege/group-object-privilege.spec.js.map +1 -1
- package/dist/__tests__/unit/components/group-privilege/group-privilege.spec.js +3 -3
- package/dist/__tests__/unit/components/group-privilege/group-privilege.spec.js.map +1 -1
- package/dist/__tests__/unit/components/user-object-privilege/user-object-privilege.spec.js +3 -3
- package/dist/__tests__/unit/components/user-object-privilege/user-object-privilege.spec.js.map +1 -1
- package/dist/__tests__/unit/components/user-privilege/user-privilege.spec.js +3 -3
- package/dist/__tests__/unit/components/user-privilege/user-privilege.spec.js.map +1 -1
- package/dist/src/components/group/group.d.ts +23 -12
- package/dist/src/components/group/group.js +188 -42
- package/dist/src/components/group/group.js.map +1 -1
- package/dist/src/components/group-object-privilege/group-object-privilege.d.ts +1 -1
- package/dist/src/components/group-object-privilege/group-object-privilege.js +7 -7
- package/dist/src/components/group-object-privilege/group-object-privilege.js.map +1 -1
- package/dist/src/components/group-privilege/group-privilege.d.ts +1 -1
- package/dist/src/components/group-privilege/group-privilege.js +2 -2
- package/dist/src/components/group-privilege/group-privilege.js.map +1 -1
- package/dist/src/components/group-privilege/group-privilege.repository.d.ts +1 -1
- package/dist/src/components/group-privilege/group-privilege.repository.js +11 -3
- package/dist/src/components/group-privilege/group-privilege.repository.js.map +1 -1
- package/dist/src/components/login-user/login-user.js.map +1 -1
- package/dist/src/components/login-user/user.js +2 -2
- package/dist/src/components/login-user/user.js.map +1 -1
- package/dist/src/components/system/system.js +1 -1
- package/dist/src/components/system/system.js.map +1 -1
- package/dist/src/components/system-privilege/system-privilege.d.ts +4 -3
- package/dist/src/components/system-privilege/system-privilege.js +18 -11
- package/dist/src/components/system-privilege/system-privilege.js.map +1 -1
- package/dist/src/components/user-group/user-group.js +1 -1
- package/dist/src/components/user-group/user-group.js.map +1 -1
- package/dist/src/components/user-object-privilege/user-object-privilege.d.ts +1 -1
- package/dist/src/components/user-object-privilege/user-object-privilege.js +1 -1
- package/dist/src/components/user-object-privilege/user-object-privilege.js.map +1 -1
- package/dist/src/components/user-privilege/user-privilege.d.ts +1 -1
- package/dist/src/components/user-privilege/user-privilege.js +1 -1
- package/dist/src/components/user-privilege/user-privilege.js.map +1 -1
- package/dist/src/interfaces/group-object-privilege.interface.d.ts +1 -1
- package/dist/src/interfaces/group-privilege.interface.d.ts +1 -1
- package/dist/src/interfaces/group.interface.d.ts +1 -0
- package/dist/src/interfaces/system-privilege.interface.d.ts +1 -0
- package/dist/src/interfaces/user-object-privilege.interface.d.ts +1 -1
- package/dist/src/interfaces/user-privilege.interface.d.ts +1 -1
- package/dist/src/models/group-object-privilege.entity.d.ts +1 -1
- package/dist/src/models/group-object-privilege.entity.js +1 -1
- package/dist/src/models/group-object-privilege.entity.js.map +1 -1
- package/dist/src/models/group-privilege.entity.d.ts +1 -1
- package/dist/src/models/group-privilege.entity.js +1 -1
- package/dist/src/models/group-privilege.entity.js.map +1 -1
- package/dist/src/models/group.entity.d.ts +1 -0
- package/dist/src/models/group.entity.js +7 -0
- package/dist/src/models/group.entity.js.map +1 -1
- package/dist/src/models/system-privilege.entity.d.ts +1 -0
- package/dist/src/models/system-privilege.entity.js +8 -0
- package/dist/src/models/system-privilege.entity.js.map +1 -1
- package/dist/src/models/user-object-privilege.entity.d.ts +1 -1
- package/dist/src/models/user-object-privilege.entity.js +1 -1
- package/dist/src/models/user-object-privilege.entity.js.map +1 -1
- package/dist/src/models/user-privilege.entity.d.ts +1 -1
- package/dist/src/models/user-privilege.entity.js +1 -1
- package/dist/src/models/user-privilege.entity.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/20240527064926-create-system-privilege-table.js +66 -62
- package/migrations/20240527065342-create-group-table.js +4 -0
- package/migrations/20240528032229-user-privilege-table.js +2 -2
- package/migrations/20240528063003-create-group-privilege-table.js +12 -2
- package/migrations/20240528063051-create-group-object-privilege-table.js +2 -2
- package/migrations/20240528063107-create-user-object-privilege-table.js +2 -2
- package/package.json +8 -8
- package/src/components/group/group.ts +225 -60
- package/src/components/group-object-privilege/group-object-privilege.ts +9 -9
- package/src/components/group-privilege/group-privilege.repository.ts +16 -3
- package/src/components/group-privilege/group-privilege.ts +3 -3
- package/src/components/login-user/login-user.ts +0 -58
- package/src/components/login-user/user.ts +2 -4
- package/src/components/system/system.ts +1 -1
- package/src/components/system-privilege/system-privilege.ts +20 -12
- package/src/components/user-group/user-group.ts +1 -1
- package/src/components/user-object-privilege/user-object-privilege.ts +2 -2
- package/src/components/user-privilege/user-privilege.ts +2 -2
- package/src/interfaces/group-object-privilege.interface.ts +1 -1
- package/src/interfaces/group-privilege.interface.ts +1 -1
- package/src/interfaces/group.interface.ts +1 -0
- package/src/interfaces/system-privilege.interface.ts +1 -0
- package/src/interfaces/user-object-privilege.interface.ts +1 -1
- package/src/interfaces/user-privilege.interface.ts +1 -1
- package/src/models/group-object-privilege.entity.ts +1 -1
- package/src/models/group-privilege.entity.ts +1 -1
- package/src/models/group.entity.ts +6 -0
- package/src/models/system-privilege.entity.ts +7 -0
- package/src/models/user-object-privilege.entity.ts +1 -1
- package/src/models/user-privilege.entity.ts +1 -1
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ClassError, ObjectBase } from '@tomei/general';
|
1
|
+
import { ClassError, ObjectBase, TreeNodeBase } from '@tomei/general';
|
2
2
|
import { GroupRepository } from './group.repository';
|
3
3
|
import { IGroupAttr } from '../../interfaces/group.interface';
|
4
4
|
import { GroupTypeEnum } from 'enum';
|
@@ -19,7 +19,7 @@ import { GroupObjectPrivilegeRepository } from '../group-object-privilege/group-
|
|
19
19
|
import { GroupObjectPrivilege } from '../group-object-privilege/group-object-privilege';
|
20
20
|
import { GroupPrivilege } from '../group-privilege/group-privilege';
|
21
21
|
|
22
|
-
export class Group extends
|
22
|
+
export class Group extends TreeNodeBase<Group> {
|
23
23
|
ObjectId: string;
|
24
24
|
ObjectName: string;
|
25
25
|
TableName: 'sso_Group';
|
@@ -33,6 +33,10 @@ export class Group extends ObjectBase {
|
|
33
33
|
InheritParentSystemAccessYN: string;
|
34
34
|
Status: string;
|
35
35
|
ParentGroup?: any;
|
36
|
+
_Path: string = '';
|
37
|
+
isChildrenLoaded = false;
|
38
|
+
isParentLoaded = false;
|
39
|
+
|
36
40
|
private _CreatedById: number;
|
37
41
|
private _CreatedAt: Date;
|
38
42
|
private _UpdatedById: number;
|
@@ -43,6 +47,7 @@ export class Group extends ObjectBase {
|
|
43
47
|
private static _GroupObjectPrivilegeRepo =
|
44
48
|
new GroupObjectPrivilegeRepository();
|
45
49
|
private static _RedisService: RedisService;
|
50
|
+
|
46
51
|
get GroupCode(): string {
|
47
52
|
return this.ObjectId;
|
48
53
|
}
|
@@ -78,6 +83,7 @@ export class Group extends ObjectBase {
|
|
78
83
|
this.InheritParentPrivilegeYN = groupAttr?.InheritParentPrivilegeYN;
|
79
84
|
this.InheritParentSystemAccessYN = groupAttr?.InheritParentSystemAccessYN;
|
80
85
|
this.Status = groupAttr?.Status;
|
86
|
+
this._Path = groupAttr?.Path;
|
81
87
|
this._CreatedById = groupAttr.CreatedById;
|
82
88
|
this._CreatedAt = groupAttr.CreatedAt;
|
83
89
|
this._UpdatedById = groupAttr.UpdatedById;
|
@@ -108,6 +114,81 @@ export class Group extends ObjectBase {
|
|
108
114
|
}
|
109
115
|
}
|
110
116
|
|
117
|
+
async loadChildren(dbTransaction?: any) {
|
118
|
+
if (!this.GroupCode) {
|
119
|
+
throw Error('GroupCode is missing.');
|
120
|
+
}
|
121
|
+
|
122
|
+
const children = await Group._Repo.findAll({
|
123
|
+
where: { ParentGroupCode: this.GroupCode },
|
124
|
+
order: [['CreatedAt', 'ASC']],
|
125
|
+
transaction: dbTransaction,
|
126
|
+
});
|
127
|
+
|
128
|
+
this.children = children.map((child) => {
|
129
|
+
return new Group(child.get({ plain: true }));
|
130
|
+
});
|
131
|
+
|
132
|
+
this.isChildrenLoaded = true;
|
133
|
+
}
|
134
|
+
|
135
|
+
async loadParent(dbTransaction?: any) {
|
136
|
+
if (!this.GroupCode) {
|
137
|
+
throw Error('GroupCode are missing.');
|
138
|
+
}
|
139
|
+
|
140
|
+
if (this.ParentGroupCode) {
|
141
|
+
if (this.ParentGroupCode !== this.GroupCode) {
|
142
|
+
const parent = await Group._Repo.findByPk(this.ParentGroupCode, {
|
143
|
+
transaction: dbTransaction,
|
144
|
+
});
|
145
|
+
this.parent = new Group(parent.get({ plain: true }));
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
this.isParentLoaded = true;
|
150
|
+
}
|
151
|
+
|
152
|
+
async isLeaf(dbTransaction?: any): Promise<boolean> {
|
153
|
+
if (!this.isChildrenLoaded) {
|
154
|
+
await this.loadChildren(dbTransaction);
|
155
|
+
}
|
156
|
+
|
157
|
+
return this.children.length === 0;
|
158
|
+
}
|
159
|
+
|
160
|
+
async getPath(dbTransaction?: any): Promise<string> {
|
161
|
+
if (!this.isParentLoaded) {
|
162
|
+
await this.loadParent(dbTransaction);
|
163
|
+
}
|
164
|
+
|
165
|
+
if (this.parent) {
|
166
|
+
return (await this.parent.getPath(dbTransaction)) + '/' + this.Name;
|
167
|
+
}
|
168
|
+
|
169
|
+
return this.GroupCode;
|
170
|
+
}
|
171
|
+
|
172
|
+
protected async updatePath(dbTransaction?: any): Promise<void> {
|
173
|
+
const path = await this.getPath(dbTransaction);
|
174
|
+
this._Path = path;
|
175
|
+
}
|
176
|
+
|
177
|
+
async setParent(parent: Group, dbTransaction?: any): Promise<void> {
|
178
|
+
this.parent = parent;
|
179
|
+
await this.updatePath(dbTransaction);
|
180
|
+
}
|
181
|
+
|
182
|
+
async getPathDetail(dbTransaction?: any): Promise<Group[]> {
|
183
|
+
const path = this._Path.split('/');
|
184
|
+
const groups: Group[] = [];
|
185
|
+
for (let i = 0; i < path.length; i++) {
|
186
|
+
const group = await Group.init(dbTransaction, path[i]);
|
187
|
+
groups.push(group);
|
188
|
+
}
|
189
|
+
return groups;
|
190
|
+
}
|
191
|
+
|
111
192
|
public static async findAll(
|
112
193
|
page: number,
|
113
194
|
row: number,
|
@@ -263,6 +344,7 @@ export class Group extends ObjectBase {
|
|
263
344
|
newGroup.Status = 'Active';
|
264
345
|
newGroup._CreatedById = loginUser.UserId;
|
265
346
|
newGroup._UpdatedById = loginUser.UserId;
|
347
|
+
newGroup._Path = await newGroup.getPath(dbTransaction);
|
266
348
|
|
267
349
|
//Call Group._Repo create method
|
268
350
|
const entityGroupAfter = {
|
@@ -291,7 +373,7 @@ export class Group extends ObjectBase {
|
|
291
373
|
//Instantiate new activity
|
292
374
|
const activity = new Activity();
|
293
375
|
activity.ActivityId = activity.createId();
|
294
|
-
activity.Action = ActionEnum.
|
376
|
+
activity.Action = ActionEnum.CREATE;
|
295
377
|
activity.Description = 'Create Group';
|
296
378
|
activity.EntityType = 'Group';
|
297
379
|
activity.EntityId = newGroup.ObjectId;
|
@@ -325,19 +407,49 @@ export class Group extends ObjectBase {
|
|
325
407
|
}
|
326
408
|
}
|
327
409
|
|
410
|
+
private async updateChildrenPath(oldGroupCode: string, dbTransaction: any) {
|
411
|
+
try {
|
412
|
+
const isLeaf = await this.isLeaf(dbTransaction);
|
413
|
+
if (isLeaf) {
|
414
|
+
return;
|
415
|
+
}
|
416
|
+
|
417
|
+
const childrens = await Group._Repo.findAll({
|
418
|
+
where: {
|
419
|
+
Path: {
|
420
|
+
[Op.like]: `${oldGroupCode}/%`,
|
421
|
+
},
|
422
|
+
},
|
423
|
+
transaction: dbTransaction,
|
424
|
+
});
|
425
|
+
|
426
|
+
childrens.forEach(async (children) => {
|
427
|
+
//Break the path into array with oldGroupCode/ as separator;
|
428
|
+
const path = children.Path.split(`${oldGroupCode}/`);
|
429
|
+
//Retrive the last element of the array
|
430
|
+
const childPath = path[path.length - 1];
|
431
|
+
//Combine the childPath with this.Path
|
432
|
+
children.Path = `${this.Path}/${childPath}`;
|
433
|
+
await children.update({ Path: path }, { transaction: dbTransaction });
|
434
|
+
});
|
435
|
+
} catch (error) {
|
436
|
+
throw error;
|
437
|
+
}
|
438
|
+
}
|
439
|
+
|
328
440
|
public async update(
|
329
441
|
loginUser: LoginUser,
|
330
442
|
dbTransaction: any,
|
331
443
|
group: {
|
332
444
|
GroupCode: string;
|
333
445
|
NewGroupCode?: string;
|
334
|
-
Name
|
335
|
-
Description
|
336
|
-
Type
|
337
|
-
ParentGroupCode
|
338
|
-
InheritParentPrivilegeYN
|
339
|
-
InheritParentSystemAccessYN
|
340
|
-
Status
|
446
|
+
Name: string;
|
447
|
+
Description: string;
|
448
|
+
Type: GroupTypeEnum;
|
449
|
+
ParentGroupCode: string;
|
450
|
+
InheritParentPrivilegeYN: string;
|
451
|
+
InheritParentSystemAccessYN: string;
|
452
|
+
Status: string;
|
341
453
|
},
|
342
454
|
) {
|
343
455
|
//Part 1: Privilege Checking
|
@@ -360,9 +472,34 @@ export class Group extends ObjectBase {
|
|
360
472
|
await Group.checkDuplicateGroupCode(dbTransaction, group.NewGroupCode);
|
361
473
|
}
|
362
474
|
|
475
|
+
const entityValueBefore = {
|
476
|
+
GroupCode: currentGroup.GroupCode,
|
477
|
+
Name: currentGroup.Name,
|
478
|
+
Type: currentGroup.Type,
|
479
|
+
Description: currentGroup.Description,
|
480
|
+
ParentGroupCode: currentGroup.ParentGroupCode,
|
481
|
+
InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
|
482
|
+
InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
|
483
|
+
Path: this.Path,
|
484
|
+
Status: currentGroup.Status,
|
485
|
+
CreatedById: currentGroup._CreatedById,
|
486
|
+
UpdatedById: currentGroup._UpdatedById,
|
487
|
+
CreatedAt: currentGroup._CreatedAt,
|
488
|
+
UpdatedAt: currentGroup._UpdatedAt,
|
489
|
+
};
|
490
|
+
|
491
|
+
let isPathChanged = false;
|
492
|
+
const oldGroupCode = currentGroup.GroupCode;
|
493
|
+
if (group.NewGroupCode) {
|
494
|
+
currentGroup.GroupCode = group.NewGroupCode;
|
495
|
+
isPathChanged = true;
|
496
|
+
}
|
497
|
+
|
498
|
+
//Check if ParentGroupCode is changed or added
|
363
499
|
if (
|
364
|
-
group.ParentGroupCode &&
|
365
|
-
|
500
|
+
(group.ParentGroupCode &&
|
501
|
+
currentGroup.ParentGroupCode !== group.ParentGroupCode) ||
|
502
|
+
(group.ParentGroupCode && !currentGroup.ParentGroupCode)
|
366
503
|
) {
|
367
504
|
const parentGroup = await Group.init(
|
368
505
|
dbTransaction,
|
@@ -375,24 +512,18 @@ export class Group extends ObjectBase {
|
|
375
512
|
'Parent Group Code not found',
|
376
513
|
);
|
377
514
|
}
|
515
|
+
await currentGroup.setParent(parentGroup);
|
516
|
+
//Check if ParentGroupCode is removed
|
517
|
+
isPathChanged = true;
|
518
|
+
} else if (!group.ParentGroupCode && currentGroup.ParentGroupCode) {
|
519
|
+
await currentGroup.setParent(null);
|
520
|
+
isPathChanged = true;
|
378
521
|
}
|
379
522
|
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
Type: currentGroup.Type,
|
384
|
-
Description: currentGroup.Description,
|
385
|
-
ParentGroupCode: currentGroup.ParentGroupCode,
|
386
|
-
InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
|
387
|
-
InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
|
388
|
-
Status: currentGroup.Status,
|
389
|
-
CreatedById: currentGroup._CreatedById,
|
390
|
-
UpdatedById: currentGroup._UpdatedById,
|
391
|
-
CreatedAt: currentGroup._CreatedAt,
|
392
|
-
UpdatedAt: currentGroup._UpdatedAt,
|
393
|
-
};
|
523
|
+
if (isPathChanged) {
|
524
|
+
await this.updateChildrenPath(oldGroupCode, dbTransaction);
|
525
|
+
}
|
394
526
|
|
395
|
-
currentGroup.GroupCode = group?.NewGroupCode || currentGroup.GroupCode;
|
396
527
|
currentGroup.Name = group?.Name || currentGroup.Name;
|
397
528
|
currentGroup.Type = group?.Type || currentGroup.Type;
|
398
529
|
currentGroup.Description = group?.Description || currentGroup.Description;
|
@@ -780,7 +911,7 @@ export class Group extends ObjectBase {
|
|
780
911
|
|
781
912
|
const activity = new Activity();
|
782
913
|
activity.ActivityId = activity.createId();
|
783
|
-
activity.Action = ActionEnum.
|
914
|
+
activity.Action = ActionEnum.CREATE;
|
784
915
|
activity.Description = 'Create Group System Access';
|
785
916
|
activity.EntityType = 'GroupSystemAccess';
|
786
917
|
activity.EntityId = systemAccess.GroupSystemAccessId?.toString();
|
@@ -984,6 +1115,15 @@ export class Group extends ObjectBase {
|
|
984
1115
|
},
|
985
1116
|
};
|
986
1117
|
}
|
1118
|
+
|
1119
|
+
if (search.PrivilegeCode) {
|
1120
|
+
systemPrivilegeWhere = {
|
1121
|
+
...systemPrivilegeWhere,
|
1122
|
+
PrivilegeCode: {
|
1123
|
+
[Op.substring]: search.PrivilegeCode,
|
1124
|
+
},
|
1125
|
+
};
|
1126
|
+
}
|
987
1127
|
}
|
988
1128
|
const group = await Group._Repo.findOne({
|
989
1129
|
where: where,
|
@@ -1010,12 +1150,12 @@ export class Group extends ObjectBase {
|
|
1010
1150
|
const systemWhere: any = {};
|
1011
1151
|
if (search) {
|
1012
1152
|
Object.entries(search).forEach(([key, value]) => {
|
1013
|
-
if (key === '
|
1014
|
-
|
1153
|
+
if (key === 'Status') {
|
1154
|
+
objectWhere[key] = {
|
1015
1155
|
[Op.substring]: value,
|
1016
1156
|
};
|
1017
1157
|
} else {
|
1018
|
-
|
1158
|
+
systemWhere[key] = {
|
1019
1159
|
[Op.substring]: value,
|
1020
1160
|
};
|
1021
1161
|
}
|
@@ -1064,9 +1204,11 @@ export class Group extends ObjectBase {
|
|
1064
1204
|
|
1065
1205
|
//format to make sure no duplicate
|
1066
1206
|
const uniquePrivileges = Array.from(
|
1067
|
-
new Set(privileges.map((a) => a.
|
1068
|
-
).map((
|
1069
|
-
return privileges.find(
|
1207
|
+
new Set(privileges.map((a) => a.SystemPrivilegeId)),
|
1208
|
+
).map((SystemPrivilegeId) => {
|
1209
|
+
return privileges.find(
|
1210
|
+
(a) => a.SystemPrivilegeId === SystemPrivilegeId,
|
1211
|
+
);
|
1070
1212
|
});
|
1071
1213
|
|
1072
1214
|
return uniquePrivileges;
|
@@ -1129,6 +1271,7 @@ export class Group extends ObjectBase {
|
|
1129
1271
|
dbTransaction: any,
|
1130
1272
|
GroupCode: string,
|
1131
1273
|
GroupObjectPrivileges: GroupObjectPrivilege[],
|
1274
|
+
SystemCode: string,
|
1132
1275
|
): Promise<string> {
|
1133
1276
|
try {
|
1134
1277
|
//Part 1: Privilege Checking
|
@@ -1174,7 +1317,7 @@ export class Group extends ObjectBase {
|
|
1174
1317
|
group.ParentGroupCode,
|
1175
1318
|
1,
|
1176
1319
|
Number.MAX_SAFE_INTEGER,
|
1177
|
-
|
1320
|
+
undefined,
|
1178
1321
|
);
|
1179
1322
|
}
|
1180
1323
|
|
@@ -1183,7 +1326,7 @@ export class Group extends ObjectBase {
|
|
1183
1326
|
//Initialise existing System privilege
|
1184
1327
|
const systemPrivilege = await SystemPrivilege.init(
|
1185
1328
|
dbTransaction,
|
1186
|
-
groupObjectPrivilege.
|
1329
|
+
groupObjectPrivilege.SystemPrivilegeId,
|
1187
1330
|
);
|
1188
1331
|
//Check whether the system codes used by that privilege is exist inside the group system access
|
1189
1332
|
const combinedSystemAccesses = {
|
@@ -1199,7 +1342,7 @@ export class Group extends ObjectBase {
|
|
1199
1342
|
'Group',
|
1200
1343
|
'GroupErrMsg13',
|
1201
1344
|
'Failed to assign privilege ' +
|
1202
|
-
groupObjectPrivilege.
|
1345
|
+
groupObjectPrivilege.SystemPrivilegeId +
|
1203
1346
|
' due to non-existent system access.',
|
1204
1347
|
);
|
1205
1348
|
}
|
@@ -1209,7 +1352,7 @@ export class Group extends ObjectBase {
|
|
1209
1352
|
await Group._GroupObjectPrivilegeRepo.findOne({
|
1210
1353
|
where: {
|
1211
1354
|
GroupCode,
|
1212
|
-
|
1355
|
+
SystemPrivilegeId: groupObjectPrivilege.SystemPrivilegeId,
|
1213
1356
|
ObjectId: groupObjectPrivilege.ObjectId,
|
1214
1357
|
ObjectType: groupObjectPrivilege.ObjectType,
|
1215
1358
|
},
|
@@ -1276,7 +1419,7 @@ export class Group extends ObjectBase {
|
|
1276
1419
|
|
1277
1420
|
if (search) {
|
1278
1421
|
Object.entries(search).forEach(([key, value]) => {
|
1279
|
-
if (key === 'SystemCode') {
|
1422
|
+
if (key === 'SystemCode' || key === 'PrivilegeCode') {
|
1280
1423
|
systemWhere[key] = {
|
1281
1424
|
[Op.substring]: value,
|
1282
1425
|
};
|
@@ -1311,9 +1454,11 @@ export class Group extends ObjectBase {
|
|
1311
1454
|
|
1312
1455
|
//Remove duplicate
|
1313
1456
|
const uniquePrivileges = Array.from(
|
1314
|
-
new Set(privileges.map((a) => a.
|
1315
|
-
).map((
|
1316
|
-
return privileges.find(
|
1457
|
+
new Set(privileges.map((a) => a.SystemPrivilegeId)),
|
1458
|
+
).map((SystemPrivilegeId) => {
|
1459
|
+
return privileges.find(
|
1460
|
+
(a) => a.SystemPrivilegeId === SystemPrivilegeId,
|
1461
|
+
);
|
1317
1462
|
});
|
1318
1463
|
|
1319
1464
|
// Create the result based on the spec on return then returns it.
|
@@ -1327,7 +1472,7 @@ export class Group extends ObjectBase {
|
|
1327
1472
|
loginUser: LoginUser,
|
1328
1473
|
dbTransaction: any,
|
1329
1474
|
GroupCode: string,
|
1330
|
-
|
1475
|
+
SystemPrivilegeIds: string[],
|
1331
1476
|
) {
|
1332
1477
|
try {
|
1333
1478
|
// Part 1: Privilege Checking
|
@@ -1379,11 +1524,11 @@ export class Group extends ObjectBase {
|
|
1379
1524
|
}
|
1380
1525
|
|
1381
1526
|
// For each Params.PrivilegesCodes.
|
1382
|
-
for (const
|
1527
|
+
for (const SystemPrivilegeId of SystemPrivilegeIds) {
|
1383
1528
|
// Initialise existing System privilege by calling SystemPrivilege.init
|
1384
1529
|
const systemPrivilege = await SystemPrivilege.init(
|
1385
1530
|
dbTransaction,
|
1386
|
-
|
1531
|
+
SystemPrivilegeId,
|
1387
1532
|
);
|
1388
1533
|
//Check whether the system codes used by that privilege is exist inside the group system access retrieved from step 2.2 & 2.4. If system code does not exist in group system access, throw a new ClassError by passing:
|
1389
1534
|
// Classname: "Group"
|
@@ -1402,7 +1547,7 @@ export class Group extends ObjectBase {
|
|
1402
1547
|
'Group',
|
1403
1548
|
'GroupErrMsg13',
|
1404
1549
|
'Failed to assign privilege ' +
|
1405
|
-
|
1550
|
+
SystemPrivilegeId +
|
1406
1551
|
' due to non-existent system access.',
|
1407
1552
|
);
|
1408
1553
|
}
|
@@ -1411,8 +1556,13 @@ export class Group extends ObjectBase {
|
|
1411
1556
|
const groupPrivilege = await Group._GroupPrivilegeRepo.findOne({
|
1412
1557
|
where: {
|
1413
1558
|
GroupCode,
|
1414
|
-
|
1559
|
+
SystemPrivilegeId,
|
1415
1560
|
},
|
1561
|
+
include: [
|
1562
|
+
{
|
1563
|
+
model: SystemPrivilegeModel,
|
1564
|
+
},
|
1565
|
+
],
|
1416
1566
|
transaction: dbTransaction,
|
1417
1567
|
});
|
1418
1568
|
|
@@ -1423,7 +1573,7 @@ export class Group extends ObjectBase {
|
|
1423
1573
|
|
1424
1574
|
let entityValueBefore = {};
|
1425
1575
|
let entityValueAfter = {};
|
1426
|
-
let action = ActionEnum.
|
1576
|
+
let action = ActionEnum.CREATE;
|
1427
1577
|
let description = 'Create Group Privilege';
|
1428
1578
|
let entityId = null;
|
1429
1579
|
//If GroupPrivilege record exist and status is not "Active" do the following:
|
@@ -1431,7 +1581,7 @@ export class Group extends ObjectBase {
|
|
1431
1581
|
//Set this GroupPrivilege entity as EntityValueBefore
|
1432
1582
|
entityValueBefore = {
|
1433
1583
|
GroupCode: groupPrivilege.GroupCode,
|
1434
|
-
|
1584
|
+
SystemPrivilegeId: groupPrivilege.SystemPrivilegeId,
|
1435
1585
|
Status: groupPrivilege.Status,
|
1436
1586
|
CreatedById: groupPrivilege.CreatedById,
|
1437
1587
|
CreatedAt: groupPrivilege.CreatedAt,
|
@@ -1445,18 +1595,27 @@ export class Group extends ObjectBase {
|
|
1445
1595
|
UpdatedById: loginUser.UserId,
|
1446
1596
|
UpdatedAt: new Date(),
|
1447
1597
|
};
|
1448
|
-
await Group._GroupPrivilegeRepo.
|
1598
|
+
const data = await Group._GroupPrivilegeRepo.findOne({
|
1449
1599
|
where: {
|
1450
1600
|
GroupCode,
|
1451
|
-
|
1601
|
+
SystemPrivilegeId,
|
1452
1602
|
},
|
1603
|
+
include: [
|
1604
|
+
{
|
1605
|
+
model: SystemPrivilegeModel,
|
1606
|
+
},
|
1607
|
+
],
|
1453
1608
|
transaction: dbTransaction,
|
1454
1609
|
});
|
1610
|
+
data.Status = 'Active';
|
1611
|
+
data.UpdatedById = updatedPayload.UpdatedById;
|
1612
|
+
data.UpdatedAt = updatedPayload.UpdatedAt;
|
1613
|
+
await data.save({ transaction: dbTransaction });
|
1455
1614
|
|
1456
1615
|
//Set updated GroupPrivilege as EntityValueAfter
|
1457
1616
|
entityValueAfter = {
|
1458
1617
|
GroupCode: groupPrivilege.GroupCode,
|
1459
|
-
|
1618
|
+
SystemPrivilegeId: groupPrivilege.SystemPrivilegeId,
|
1460
1619
|
Status: updatedPayload.Status,
|
1461
1620
|
CreatedById: groupPrivilege.CreatedById,
|
1462
1621
|
CreatedAt: groupPrivilege.CreatedAt,
|
@@ -1475,7 +1634,7 @@ export class Group extends ObjectBase {
|
|
1475
1634
|
//Set the attributes
|
1476
1635
|
newGroupPrivilege.setAttributes({
|
1477
1636
|
GroupCode,
|
1478
|
-
|
1637
|
+
SystemPrivilegeId,
|
1479
1638
|
Status: 'Active',
|
1480
1639
|
CreatedById: loginUser.UserId,
|
1481
1640
|
CreatedAt: new Date(),
|
@@ -1486,7 +1645,7 @@ export class Group extends ObjectBase {
|
|
1486
1645
|
// Set EntityValueAfter to above instance.
|
1487
1646
|
entityValueAfter = {
|
1488
1647
|
GroupCode: newGroupPrivilege.GroupCode,
|
1489
|
-
|
1648
|
+
SystemPrivilegeId: newGroupPrivilege.SystemPrivilegeId,
|
1490
1649
|
Status: newGroupPrivilege.Status,
|
1491
1650
|
CreatedById: newGroupPrivilege.CreatedById,
|
1492
1651
|
CreatedAt: newGroupPrivilege.CreatedAt,
|
@@ -1501,7 +1660,7 @@ export class Group extends ObjectBase {
|
|
1501
1660
|
transaction: dbTransaction,
|
1502
1661
|
},
|
1503
1662
|
);
|
1504
|
-
action = ActionEnum.
|
1663
|
+
action = ActionEnum.CREATE;
|
1505
1664
|
description = 'Create Group Privilege';
|
1506
1665
|
entityId = groupPrivilege.GroupPrivilegeId;
|
1507
1666
|
}
|
@@ -1530,7 +1689,7 @@ export class Group extends ObjectBase {
|
|
1530
1689
|
loginUser: LoginUser,
|
1531
1690
|
dbTransaction: any,
|
1532
1691
|
GroupCode: string,
|
1533
|
-
|
1692
|
+
SystemPrivilegeIds: string[],
|
1534
1693
|
) {
|
1535
1694
|
try {
|
1536
1695
|
// Part 1: Privilege Checking
|
@@ -1551,13 +1710,18 @@ export class Group extends ObjectBase {
|
|
1551
1710
|
|
1552
1711
|
// Part 2: Validation, Create and Record Activity
|
1553
1712
|
// For each Params.PrivilegesCodes.
|
1554
|
-
for (const
|
1713
|
+
for (const SystemPrivilegeId of SystemPrivilegeIds) {
|
1555
1714
|
//Check whether the record exist in database by calling Group._GroupPrivilegeRepo.findOne
|
1556
1715
|
const groupPrivilege = await Group._GroupPrivilegeRepo.findOne({
|
1557
1716
|
where: {
|
1558
1717
|
GroupCode,
|
1559
|
-
|
1718
|
+
SystemPrivilegeId,
|
1560
1719
|
},
|
1720
|
+
include: [
|
1721
|
+
{
|
1722
|
+
model: SystemPrivilegeModel,
|
1723
|
+
},
|
1724
|
+
],
|
1561
1725
|
transaction: dbTransaction,
|
1562
1726
|
});
|
1563
1727
|
|
@@ -1573,7 +1737,7 @@ export class Group extends ObjectBase {
|
|
1573
1737
|
//Set the EntityValueBefore to the GroupPrivilegesValue from step 1.c.
|
1574
1738
|
const entityValueBefore = {
|
1575
1739
|
GroupCode: groupPrivilege.GroupCode,
|
1576
|
-
|
1740
|
+
SystemPrivilegeId: groupPrivilege.SystemPrivilegeId,
|
1577
1741
|
Status: groupPrivilege.Status,
|
1578
1742
|
CreatedById: groupPrivilege.CreatedById,
|
1579
1743
|
CreatedAt: groupPrivilege.CreatedAt,
|
@@ -1584,9 +1748,10 @@ export class Group extends ObjectBase {
|
|
1584
1748
|
//Call Group._GroupPrivilegeRepo.delete
|
1585
1749
|
await Group._GroupPrivilegeRepo.delete(
|
1586
1750
|
GroupCode,
|
1587
|
-
|
1751
|
+
SystemPrivilegeId,
|
1588
1752
|
dbTransaction,
|
1589
1753
|
);
|
1754
|
+
|
1590
1755
|
// Instantiate new activity from Activity class, call createId() method, then set:
|
1591
1756
|
const activity = new Activity();
|
1592
1757
|
activity.ActivityId = activity.createId();
|
@@ -11,7 +11,7 @@ export class GroupObjectPrivilege extends ObjectBase {
|
|
11
11
|
ObjectName: string;
|
12
12
|
GroupObjectPrivilegeId: number;
|
13
13
|
GroupCode: string;
|
14
|
-
|
14
|
+
SystemPrivilegeId: string;
|
15
15
|
ObjectId: string;
|
16
16
|
ObjectType: string;
|
17
17
|
Status: ObjectStatus;
|
@@ -44,7 +44,7 @@ export class GroupObjectPrivilege extends ObjectBase {
|
|
44
44
|
this.GroupObjectPrivilegeId =
|
45
45
|
GroupObjectPrivilegeAttr.GroupObjectPrivilegeId;
|
46
46
|
this.GroupCode = GroupObjectPrivilegeAttr.GroupCode;
|
47
|
-
this.
|
47
|
+
this.SystemPrivilegeId = GroupObjectPrivilegeAttr.SystemPrivilegeId;
|
48
48
|
this.ObjectId = GroupObjectPrivilegeAttr.ObjectId;
|
49
49
|
this.ObjectType = GroupObjectPrivilegeAttr.ObjectType;
|
50
50
|
this.Status = GroupObjectPrivilegeAttr.Status;
|
@@ -115,12 +115,12 @@ export class GroupObjectPrivilege extends ObjectBase {
|
|
115
115
|
'GroupCode is missing.',
|
116
116
|
);
|
117
117
|
}
|
118
|
-
// Params.groupObjectPrivilege.
|
119
|
-
if (!groupObjectPrivilege.
|
118
|
+
// Params.groupObjectPrivilege.SystemPrivilegeId
|
119
|
+
if (!groupObjectPrivilege.SystemPrivilegeId) {
|
120
120
|
throw new ClassError(
|
121
121
|
'GroupObjectPrivilege',
|
122
122
|
'GroupObjectPrivilegeErrMsg02',
|
123
|
-
'
|
123
|
+
'SystemPrivilegeId is missing.',
|
124
124
|
);
|
125
125
|
}
|
126
126
|
// Params.groupObjectPrivilege.ObjectId
|
@@ -145,7 +145,7 @@ export class GroupObjectPrivilege extends ObjectBase {
|
|
145
145
|
await GroupObjectPrivilege._Repository.findOne({
|
146
146
|
where: {
|
147
147
|
GroupCode: groupObjectPrivilege.GroupCode,
|
148
|
-
|
148
|
+
SystemPrivilegeId: groupObjectPrivilege.SystemPrivilegeId,
|
149
149
|
ObjectId: groupObjectPrivilege.ObjectId,
|
150
150
|
ObjectType: groupObjectPrivilege.ObjectType,
|
151
151
|
},
|
@@ -165,7 +165,7 @@ export class GroupObjectPrivilege extends ObjectBase {
|
|
165
165
|
// Initialise new Group instance and populate the attributes
|
166
166
|
const objectAttr = {
|
167
167
|
GroupCode: groupObjectPrivilege.GroupCode,
|
168
|
-
|
168
|
+
SystemPrivilegeId: groupObjectPrivilege.SystemPrivilegeId,
|
169
169
|
ObjectId: groupObjectPrivilege.ObjectId,
|
170
170
|
ObjectType: groupObjectPrivilege.ObjectType,
|
171
171
|
Status: ObjectStatus.ACTIVE,
|
@@ -194,7 +194,7 @@ export class GroupObjectPrivilege extends ObjectBase {
|
|
194
194
|
// Instantiate new activity from Activity class
|
195
195
|
const activity = new Activity();
|
196
196
|
activity.createId();
|
197
|
-
activity.Action = ActionEnum.
|
197
|
+
activity.Action = ActionEnum.CREATE;
|
198
198
|
activity.Description = `Create GroupObjectPrivilege for (${newGroupObjectPrivilege.GroupCode})`;
|
199
199
|
activity.EntityType = 'GroupObjectPrivilege';
|
200
200
|
activity.EntityId =
|
@@ -245,7 +245,7 @@ export class GroupObjectPrivilege extends ObjectBase {
|
|
245
245
|
// Initialise EntityValueBefore variable and set GroupObjectPrivelege column properties
|
246
246
|
const EntityValueBefore = {
|
247
247
|
GroupCode: this.GroupCode,
|
248
|
-
|
248
|
+
SystemPrivilegeId: this.SystemPrivilegeId,
|
249
249
|
ObjectId: this.ObjectId,
|
250
250
|
ObjectType: this.ObjectType,
|
251
251
|
Status: this.Status,
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import SystemPrivilegeModel from '../../models/system-privilege.entity';
|
1
2
|
import GroupPrivilegeModel from '../../models/group-privilege.entity';
|
2
3
|
import { RepositoryBase, IRepositoryBase } from '@tomei/general';
|
3
4
|
|
@@ -9,12 +10,24 @@ export class GroupPrivilegeRepository
|
|
9
10
|
super(GroupPrivilegeModel);
|
10
11
|
}
|
11
12
|
|
12
|
-
async delete(
|
13
|
+
async delete(
|
14
|
+
GroupCode: string,
|
15
|
+
PrivilegeCode: string,
|
16
|
+
SystemCode: string,
|
17
|
+
dbTransaction?: any,
|
18
|
+
) {
|
13
19
|
try {
|
14
|
-
|
20
|
+
const data = await GroupPrivilegeModel.findOne({
|
15
21
|
where: { GroupCode, PrivilegeCode },
|
16
|
-
|
22
|
+
include: [
|
23
|
+
{
|
24
|
+
model: SystemPrivilegeModel,
|
25
|
+
where: { SystemCode },
|
26
|
+
},
|
27
|
+
],
|
17
28
|
});
|
29
|
+
data.destroy({ transaction: dbTransaction });
|
30
|
+
return data;
|
18
31
|
} catch (error) {
|
19
32
|
throw error;
|
20
33
|
}
|
@@ -9,7 +9,7 @@ export class GroupPrivilege extends ObjectBase {
|
|
9
9
|
ObjectType = 'GroupPrivilege';
|
10
10
|
GroupPrivilegeId: number;
|
11
11
|
GroupCode: string;
|
12
|
-
|
12
|
+
SystemPrivilegeId: string;
|
13
13
|
Status: string;
|
14
14
|
private _CreatedAt: Date;
|
15
15
|
private _UpdatedAt: Date;
|
@@ -39,7 +39,7 @@ export class GroupPrivilege extends ObjectBase {
|
|
39
39
|
if (GroupPrivilegeAttr) {
|
40
40
|
this.GroupPrivilegeId = GroupPrivilegeAttr.GroupPrivilegeId;
|
41
41
|
this.GroupCode = GroupPrivilegeAttr.GroupCode;
|
42
|
-
this.
|
42
|
+
this.SystemPrivilegeId = GroupPrivilegeAttr.SystemPrivilegeId;
|
43
43
|
this.Status = GroupPrivilegeAttr.Status;
|
44
44
|
this._CreatedAt = GroupPrivilegeAttr.CreatedAt;
|
45
45
|
this._UpdatedAt = GroupPrivilegeAttr.UpdatedAt;
|
@@ -51,7 +51,7 @@ export class GroupPrivilege extends ObjectBase {
|
|
51
51
|
setAttributes(GroupPrivilegeAttr: IGroupPrivilegeAttr) {
|
52
52
|
this.GroupPrivilegeId = GroupPrivilegeAttr.GroupPrivilegeId;
|
53
53
|
this.GroupCode = GroupPrivilegeAttr.GroupCode;
|
54
|
-
this.
|
54
|
+
this.SystemPrivilegeId = GroupPrivilegeAttr.SystemPrivilegeId;
|
55
55
|
this.Status = GroupPrivilegeAttr.Status;
|
56
56
|
this._CreatedAt = GroupPrivilegeAttr.CreatedAt;
|
57
57
|
this._UpdatedAt = GroupPrivilegeAttr.UpdatedAt;
|