@tomei/sso 0.47.0 → 0.48.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/src/components/user-group/user-group.d.ts +5 -0
- package/dist/src/components/user-group/user-group.js +73 -0
- package/dist/src/components/user-group/user-group.js.map +1 -1
- package/dist/src/components/user-privilege/user-privilege.d.ts +42 -0
- package/dist/src/components/user-privilege/user-privilege.js +336 -0
- package/dist/src/components/user-privilege/user-privilege.js.map +1 -1
- package/dist/src/components/user-privilege/user-privilege.repository.d.ts +1 -0
- package/dist/src/components/user-privilege/user-privilege.repository.js +25 -0
- package/dist/src/components/user-privilege/user-privilege.repository.js.map +1 -1
- package/dist/src/components/user-system-access/user-system-access.d.ts +12 -0
- package/dist/src/components/user-system-access/user-system-access.js +148 -0
- package/dist/src/components/user-system-access/user-system-access.js.map +1 -1
- package/dist/src/components/user-system-access/user-system-access.repository.d.ts +1 -0
- package/dist/src/components/user-system-access/user-system-access.repository.js +25 -0
- package/dist/src/components/user-system-access/user-system-access.repository.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/user-group/user-group.ts +134 -0
- package/src/components/user-privilege/user-privilege.repository.ts +14 -0
- package/src/components/user-privilege/user-privilege.ts +585 -0
- package/src/components/user-system-access/user-system-access.repository.ts +14 -0
- package/src/components/user-system-access/user-system-access.ts +298 -0
package/package.json
CHANGED
@@ -8,6 +8,7 @@ import { ActionEnum, Activity } from '@tomei/activity-history';
|
|
8
8
|
import GroupSystemAccessModel from '../../models/group-system-access.entity';
|
9
9
|
import GroupModel from '../../models/group.entity';
|
10
10
|
import SystemModel from '../../models/system.entity';
|
11
|
+
import { Transaction } from 'sequelize';
|
11
12
|
|
12
13
|
export class UserGroup extends ObjectBase {
|
13
14
|
ObjectType = 'UserGroup';
|
@@ -456,4 +457,137 @@ export class UserGroup extends ObjectBase {
|
|
456
457
|
throw error;
|
457
458
|
}
|
458
459
|
}
|
460
|
+
|
461
|
+
public async update(
|
462
|
+
loginUser: LoginUser,
|
463
|
+
dbTransaction: Transaction,
|
464
|
+
UpdatedProperties: {
|
465
|
+
InheritGroupPrivilegeYN?: string;
|
466
|
+
InheritGroupSystemAccessYN?: string;
|
467
|
+
},
|
468
|
+
): Promise<UserGroup> {
|
469
|
+
try {
|
470
|
+
// Part 1: Privilege Checking
|
471
|
+
// Call loginUser.checkPrivileges() to ensure the user has permission to retrieve system access information.
|
472
|
+
// SystemCode: Retrieve from app config.
|
473
|
+
// PrivilegeCode: 'USER_GROUP_UPDATE'.
|
474
|
+
const systemCode =
|
475
|
+
ApplicationConfig.getComponentConfigValue('system-code');
|
476
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
477
|
+
systemCode,
|
478
|
+
'USER_GROUP_UPDATE',
|
479
|
+
);
|
480
|
+
// If the privilege check fails, throw an error with a 403 Forbidden status.
|
481
|
+
if (!isPrivileged) {
|
482
|
+
throw new ClassError(
|
483
|
+
'UserGroup',
|
484
|
+
'UserGroupErrMsg0X',
|
485
|
+
'User does not have privilege to update user group.',
|
486
|
+
'update',
|
487
|
+
403,
|
488
|
+
);
|
489
|
+
}
|
490
|
+
// Part 2: Validation
|
491
|
+
// Check to make sure that at least one of the UpdatedProperties is exist if not throw error.
|
492
|
+
if (
|
493
|
+
!UpdatedProperties.InheritGroupPrivilegeYN &&
|
494
|
+
!UpdatedProperties.InheritGroupSystemAccessYN
|
495
|
+
) {
|
496
|
+
throw new ClassError(
|
497
|
+
'UserGroup',
|
498
|
+
'UserGroupErrMsg04',
|
499
|
+
'At least one of the properties to update is required.',
|
500
|
+
'update',
|
501
|
+
400,
|
502
|
+
);
|
503
|
+
}
|
504
|
+
// Part 3: Update User Group
|
505
|
+
// Call the UserGroup._Repo.update() method to perform the update operation, passing:
|
506
|
+
// InheritGroupPrivilegeYN (if exist): updatedProperties.InheritGroupPrivilegeYN
|
507
|
+
// InheritGroupSystemAccessYN (if exist): updatedProperties.InheritGroupSystemAccessYN
|
508
|
+
// UpdatedById: loginUser.UserId (to indicate who updated the record).
|
509
|
+
// UpdatedAt: Set to the current date and time.
|
510
|
+
// dbTransaction: The database transaction instance.
|
511
|
+
const entityValueBefore = {
|
512
|
+
UserGroupId: this.UserGroupId,
|
513
|
+
UserId: this.UserId,
|
514
|
+
GroupCode: this.GroupCode,
|
515
|
+
Status: this.Status,
|
516
|
+
CreatedById: this._CreatedById,
|
517
|
+
CreatedAt: this._CreatedAt,
|
518
|
+
UpdatedById: this._UpdatedById,
|
519
|
+
UpdatedAt: this._UpdatedAt,
|
520
|
+
InheritGroupPrivilegeYN: this.InheritGroupPrivilegeYN,
|
521
|
+
InheritGroupSystemAccessYN: this.InheritGroupSystemAccessYN,
|
522
|
+
};
|
523
|
+
|
524
|
+
this._UpdatedById = loginUser.UserId;
|
525
|
+
this._UpdatedAt = new Date();
|
526
|
+
if (UpdatedProperties.InheritGroupPrivilegeYN) {
|
527
|
+
this.InheritGroupPrivilegeYN =
|
528
|
+
UpdatedProperties.InheritGroupPrivilegeYN;
|
529
|
+
}
|
530
|
+
if (UpdatedProperties.InheritGroupSystemAccessYN) {
|
531
|
+
this.InheritGroupSystemAccessYN =
|
532
|
+
UpdatedProperties.InheritGroupSystemAccessYN;
|
533
|
+
}
|
534
|
+
|
535
|
+
await UserGroup._Repository.update(
|
536
|
+
{
|
537
|
+
InheritGroupPrivilegeYN: this.InheritGroupPrivilegeYN,
|
538
|
+
InheritGroupSystemAccessYN: this.InheritGroupSystemAccessYN,
|
539
|
+
UpdatedById: this._UpdatedById,
|
540
|
+
UpdatedAt: this._UpdatedAt,
|
541
|
+
},
|
542
|
+
{
|
543
|
+
where: {
|
544
|
+
UserGroupId: this.UserGroupId,
|
545
|
+
},
|
546
|
+
transaction: dbTransaction,
|
547
|
+
},
|
548
|
+
);
|
549
|
+
|
550
|
+
// Part 2: Record Activity History
|
551
|
+
// Initialize a variable entityValueBefore to store the current state of the record before the update.
|
552
|
+
const entityValueAfter = {
|
553
|
+
UserGroupId: this.UserGroupId,
|
554
|
+
UserId: this.UserId,
|
555
|
+
GroupCode: this.GroupCode,
|
556
|
+
Status: this.Status,
|
557
|
+
CreatedById: this._CreatedById,
|
558
|
+
CreatedAt: this._CreatedAt,
|
559
|
+
UpdatedById: this._UpdatedById,
|
560
|
+
UpdatedAt: this._UpdatedAt,
|
561
|
+
InheritGroupPrivilegeYN: this.InheritGroupPrivilegeYN,
|
562
|
+
InheritGroupSystemAccessYN: this.InheritGroupSystemAccessYN,
|
563
|
+
};
|
564
|
+
// Create an instance of the Activity class and set the following properties:
|
565
|
+
// ActivityId: Call activity.createId().
|
566
|
+
// Action: Set to ActionEnum.Update.
|
567
|
+
// Description: Set to Update User Group.
|
568
|
+
// EntityType: Set to UserGroup.
|
569
|
+
// EntityId: Use the ID of the updated record.
|
570
|
+
// EntityValueBefore: Stringify entityValueBefore to capture the state before the update.
|
571
|
+
// EntityValueAfter: Stringify the updated record to capture the new state after the update.
|
572
|
+
const activity = new Activity();
|
573
|
+
activity.ActivityId = activity.createId();
|
574
|
+
activity.Action = ActionEnum.UPDATE;
|
575
|
+
activity.Description = 'Update User Group';
|
576
|
+
activity.EntityType = 'UserGroup';
|
577
|
+
activity.EntityId = this.UserGroupId.toString();
|
578
|
+
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
579
|
+
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
580
|
+
|
581
|
+
// Call the activity create a method with the following parameters:
|
582
|
+
// dbTransaction
|
583
|
+
// userId: loginUser.UserId
|
584
|
+
// Part 3: Return Updated Record
|
585
|
+
|
586
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
587
|
+
// Retrieve the updated user group record from the database or return the updated instance as needed.
|
588
|
+
return this;
|
589
|
+
} catch (error) {
|
590
|
+
throw error;
|
591
|
+
}
|
592
|
+
}
|
459
593
|
}
|
@@ -8,4 +8,18 @@ export class UserPrivilegeRepository
|
|
8
8
|
constructor() {
|
9
9
|
super(UserPrivilegeModel);
|
10
10
|
}
|
11
|
+
|
12
|
+
async delete(UserPrivilegeId: number, dbTransaction?: any) {
|
13
|
+
try {
|
14
|
+
const options = {
|
15
|
+
where: {
|
16
|
+
UserPrivilegeId: UserPrivilegeId,
|
17
|
+
},
|
18
|
+
transaction: dbTransaction,
|
19
|
+
};
|
20
|
+
await UserPrivilegeModel.destroy(options);
|
21
|
+
} catch (error) {
|
22
|
+
throw new Error(`An Error occured when delete : ${error.message}`);
|
23
|
+
}
|
24
|
+
}
|
11
25
|
}
|