@tomei/sso 0.32.4 → 0.32.6

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/sso",
3
- "version": "0.32.4",
3
+ "version": "0.32.6",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -9,7 +9,7 @@ import { Op } from 'sequelize';
9
9
  import { ActionEnum, Activity } from '@tomei/activity-history';
10
10
  import { GroupSystemAccessRepository } from '../group-system-access/group-system-access.repository';
11
11
  import SystemModel from '../../models/system.entity';
12
- import { GroupSystemAccess } from 'components/group-system-access';
12
+ import { GroupSystemAccess } from '../group-system-access';
13
13
 
14
14
  export class Group extends ObjectBase {
15
15
  ObjectId: string;
@@ -30,7 +30,7 @@ export class Group extends ObjectBase {
30
30
  private _UpdatedById: number;
31
31
  private _UpdatedAt: Date;
32
32
  private static _Repo = new GroupRepository();
33
- private static _SystemAccessRepo = new GroupSystemAccessRepository();
33
+ private static _GroupSystemAccessRepo = new GroupSystemAccessRepository();
34
34
 
35
35
  get GroupCode(): string {
36
36
  return this.ObjectId;
@@ -507,7 +507,7 @@ export class Group extends ObjectBase {
507
507
  };
508
508
  }
509
509
 
510
- const systemAccess = await Group._SystemAccessRepo.findAndCountAll();
510
+ const systemAccess = await Group._GroupSystemAccessRepo.findAndCountAll();
511
511
  return systemAccess;
512
512
  } catch (error) {
513
513
  return error;
@@ -530,7 +530,7 @@ export class Group extends ObjectBase {
530
530
  ],
531
531
  transaction: dbTransaction,
532
532
  };
533
- let systemAccess = await Group._SystemAccessRepo.findAll(options);
533
+ let systemAccess = await Group._GroupSystemAccessRepo.findAll(options);
534
534
 
535
535
  if (group.InheritParentSystemAccessYN === 'Y') {
536
536
  const parentGroup = await Group.init(
@@ -610,7 +610,7 @@ export class Group extends ObjectBase {
610
610
  try {
611
611
  if (SystemCodes.length > 0) {
612
612
  for (let i = 0; i < SystemCodes.length; i++) {
613
- const CurrentGroupSystemAccess = Group.getSystemAccesses(
613
+ const CurrentGroupSystemAccess = await Group.getSystemAccesses(
614
614
  loginUser,
615
615
  dbTransaction,
616
616
  GroupCode,
@@ -648,7 +648,7 @@ export class Group extends ObjectBase {
648
648
  UpdatedAt: groupSystemAccess.UpdatedAt,
649
649
  };
650
650
 
651
- const systemAccess = await Group._SystemAccessRepo.create(
651
+ const systemAccess = await Group._GroupSystemAccessRepo.create(
652
652
  EntityValueAfter,
653
653
  {
654
654
  transaction: dbTransaction,
@@ -673,4 +673,77 @@ export class Group extends ObjectBase {
673
673
  throw error;
674
674
  }
675
675
  }
676
+
677
+ public static async deleteSystemAccess(
678
+ loginUser: LoginUser,
679
+ dbTransaction: any,
680
+ GroupCode: string,
681
+ SystemCode: string,
682
+ ) {
683
+ // Part 1: Privilege Checking
684
+ const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
685
+ const isPrivileged = await loginUser.checkPrivileges(
686
+ systemCode,
687
+ 'SYSTEM_ACCESS_DELETE',
688
+ );
689
+
690
+ if (!isPrivileged) {
691
+ throw new ClassError(
692
+ 'Group',
693
+ 'GroupErrMsg08',
694
+ 'You do not have the privilege to delete system access',
695
+ );
696
+ }
697
+
698
+ try {
699
+ const currentGroupSystemAccess = await Group.getSystemAccesses(
700
+ loginUser,
701
+ dbTransaction,
702
+ GroupCode,
703
+ 1,
704
+ Number.MAX_SAFE_INTEGER,
705
+ { SystemCode: SystemCode },
706
+ );
707
+
708
+ if (!currentGroupSystemAccess) {
709
+ throw new ClassError(
710
+ 'Group',
711
+ 'GroupErrMsg10',
712
+ 'No associated system access found.',
713
+ );
714
+ }
715
+
716
+ await Group._GroupSystemAccessRepo.delete(
717
+ GroupCode,
718
+ SystemCode,
719
+ dbTransaction,
720
+ );
721
+
722
+ const EntityValueBefore = {
723
+ GroupCode: currentGroupSystemAccess.GroupCode,
724
+ SystemCode: currentGroupSystemAccess.SystemCode,
725
+ Status: currentGroupSystemAccess.Status,
726
+ CreatedById: currentGroupSystemAccess.CreatedById,
727
+ CreatedAt: currentGroupSystemAccess.CreatedAt,
728
+ UpdatedById: currentGroupSystemAccess.UpdatedById,
729
+ UpdatedAt: currentGroupSystemAccess.UpdatedAt,
730
+ };
731
+
732
+ const activity = new Activity();
733
+ activity.ActivityId = activity.createId();
734
+ activity.Action = ActionEnum.DELETE;
735
+ activity.Description = 'Delete Group System Access';
736
+ activity.EntityType = 'GroupSystemAccess';
737
+ activity.EntityId =
738
+ currentGroupSystemAccess.GroupSystemAccessId?.toString();
739
+ activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
740
+ activity.EntityValueAfter = JSON.stringify({});
741
+
742
+ await activity.create(loginUser.ObjectId, dbTransaction);
743
+
744
+ return { Message: 'System access removed.', SystemCode: SystemCode };
745
+ } catch (error) {
746
+ throw error;
747
+ }
748
+ }
676
749
  }
@@ -26,4 +26,19 @@ export class GroupSystemAccessRepository
26
26
  );
27
27
  }
28
28
  }
29
+
30
+ async delete(GroupCode: string, SystemCode: string, dbTransaction?: any) {
31
+ try {
32
+ const options = {
33
+ where: {
34
+ GroupCode: GroupCode,
35
+ SystemCode: SystemCode,
36
+ },
37
+ transaction: dbTransaction,
38
+ };
39
+ await GroupSystemAccessModel.destroy(options);
40
+ } catch (error) {
41
+ throw new Error(`An Error occured when delete : ${error.message}`);
42
+ }
43
+ }
29
44
  }