@tomei/sso 0.34.1 → 0.34.5
Sign up to get free protection for your applications and to get access to all the features.
- package/__tests__/unit/components/login-user/login.spec.ts +474 -375
- package/dist/__tests__/unit/components/login-user/login.spec.js +71 -219
- package/dist/__tests__/unit/components/login-user/login.spec.js.map +1 -1
- package/dist/src/components/group/group.d.ts +4 -1
- package/dist/src/components/group/group.js +54 -2
- package/dist/src/components/group/group.js.map +1 -1
- package/dist/src/components/group/group.repository.d.ts +2 -0
- package/dist/src/components/group/group.repository.js +25 -0
- package/dist/src/components/group/group.repository.js.map +1 -1
- package/dist/src/components/login-user/index.d.ts +1 -0
- package/dist/src/components/login-user/index.js +1 -0
- package/dist/src/components/login-user/index.js.map +1 -1
- package/dist/src/components/login-user/login-user.d.ts +7 -121
- package/dist/src/components/login-user/login-user.js +11 -1477
- package/dist/src/components/login-user/login-user.js.map +1 -1
- package/dist/src/components/login-user/user.d.ts +132 -0
- package/dist/src/components/login-user/user.js +1574 -0
- package/dist/src/components/login-user/user.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/group/group.repository.ts +15 -0
- package/src/components/group/group.ts +88 -2
- package/src/components/login-user/index.ts +1 -0
- package/src/components/login-user/login-user.ts +110 -2235
- package/src/components/login-user/user.ts +2288 -0
package/package.json
CHANGED
@@ -8,4 +8,19 @@ export class GroupRepository
|
|
8
8
|
constructor() {
|
9
9
|
super(GroupModel);
|
10
10
|
}
|
11
|
+
v;
|
12
|
+
|
13
|
+
async delete(GroupCode: string, dbTransaction?: any) {
|
14
|
+
try {
|
15
|
+
const options = {
|
16
|
+
where: {
|
17
|
+
GroupCode: GroupCode,
|
18
|
+
},
|
19
|
+
transaction: dbTransaction,
|
20
|
+
};
|
21
|
+
await GroupModel.destroy(options);
|
22
|
+
} catch (error) {
|
23
|
+
throw new Error(`An Error occured when delete : ${error.message}`);
|
24
|
+
}
|
25
|
+
}
|
11
26
|
}
|
@@ -460,6 +460,92 @@ export class Group extends ObjectBase {
|
|
460
460
|
}
|
461
461
|
}
|
462
462
|
|
463
|
+
public static async delete(
|
464
|
+
loginUser: LoginUser,
|
465
|
+
dbTransaction: any,
|
466
|
+
GroupCode: string,
|
467
|
+
) {
|
468
|
+
// Part 1: Privilege Checking
|
469
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
470
|
+
|
471
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
472
|
+
systemCode,
|
473
|
+
'GROUP_DELETE',
|
474
|
+
);
|
475
|
+
|
476
|
+
if (!isPrivileged) {
|
477
|
+
throw new ClassError(
|
478
|
+
'Group',
|
479
|
+
'GroupErrMsg03',
|
480
|
+
'You do not have the privilege to delete groups records.',
|
481
|
+
);
|
482
|
+
}
|
483
|
+
try {
|
484
|
+
const group = await Group.init(dbTransaction, GroupCode);
|
485
|
+
|
486
|
+
if (group.Status === 'Active') {
|
487
|
+
throw new ClassError(
|
488
|
+
'Group',
|
489
|
+
'GroupErrMsg03',
|
490
|
+
'Active Group cant be deleted',
|
491
|
+
);
|
492
|
+
}
|
493
|
+
|
494
|
+
const relatedGroup = await Group.findAll(
|
495
|
+
1,
|
496
|
+
Number.MAX_SAFE_INTEGER,
|
497
|
+
dbTransaction,
|
498
|
+
loginUser,
|
499
|
+
{
|
500
|
+
ParentGroupCode: GroupCode,
|
501
|
+
},
|
502
|
+
);
|
503
|
+
|
504
|
+
if (relatedGroup.Count > 0) {
|
505
|
+
const listOfRelatedGroup = relatedGroup.Groups.map((group) => {
|
506
|
+
return group.GroupCode;
|
507
|
+
});
|
508
|
+
throw new ClassError(
|
509
|
+
'Group',
|
510
|
+
'GroupErrMsg03',
|
511
|
+
`Group still has associated user group ${listOfRelatedGroup}`,
|
512
|
+
);
|
513
|
+
}
|
514
|
+
|
515
|
+
await Group._Repo.delete(GroupCode, dbTransaction);
|
516
|
+
|
517
|
+
const EntityValueBefore = {
|
518
|
+
GroupCode: group.GroupCode,
|
519
|
+
Name: group.Name,
|
520
|
+
Type: group.Type,
|
521
|
+
Description: group.Description,
|
522
|
+
ParentGroupCode: group.ParentGroupCode,
|
523
|
+
InheritParentPrivilegeYN: group.InheritParentPrivilegeYN,
|
524
|
+
InheritParentSystemAccessYN: group.InheritParentSystemAccessYN,
|
525
|
+
Status: group.Status,
|
526
|
+
CreatedById: group._CreatedById,
|
527
|
+
UpdatedById: group._UpdatedById,
|
528
|
+
CreatedAt: group._CreatedAt,
|
529
|
+
UpdatedAt: group._UpdatedAt,
|
530
|
+
};
|
531
|
+
|
532
|
+
const activity = new Activity();
|
533
|
+
activity.ActivityId = activity.createId();
|
534
|
+
activity.Action = ActionEnum.DELETE;
|
535
|
+
activity.Description = 'Delete Group';
|
536
|
+
activity.EntityType = 'Group';
|
537
|
+
activity.EntityId = group.ObjectId;
|
538
|
+
activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
|
539
|
+
activity.EntityValueAfter = JSON.stringify({});
|
540
|
+
|
541
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
542
|
+
|
543
|
+
return { Message: 'Group removed.' };
|
544
|
+
} catch (error) {
|
545
|
+
throw error;
|
546
|
+
}
|
547
|
+
}
|
548
|
+
|
463
549
|
public static async getSystemAccesses(
|
464
550
|
loginUser: LoginUser,
|
465
551
|
dbTransaction: any,
|
@@ -555,7 +641,7 @@ export class Group extends ObjectBase {
|
|
555
641
|
return systemAccess;
|
556
642
|
}
|
557
643
|
|
558
|
-
public static async
|
644
|
+
public static async isGroupCodeInHierarchy(
|
559
645
|
dbTransaction: any,
|
560
646
|
GroupCode: string,
|
561
647
|
ListGroupCode: string[] = [],
|
@@ -570,7 +656,7 @@ export class Group extends ObjectBase {
|
|
570
656
|
if (group?.ParentGroupCode) {
|
571
657
|
const isGroupCodeExist = ListGroupCode.includes(group.ParentGroupCode);
|
572
658
|
if (!isGroupCodeExist) {
|
573
|
-
await this.
|
659
|
+
await this.isGroupCodeInHierarchy(
|
574
660
|
dbTransaction,
|
575
661
|
group.ParentGroupCode,
|
576
662
|
ListGroupCode,
|