@tomei/sso 0.58.12 → 0.59.0
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/src/components/group/group.d.ts +1 -0
- package/dist/src/components/group/group.js +20 -0
- package/dist/src/components/group/group.js.map +1 -1
- package/dist/src/components/user-group/user-group.d.ts +1 -0
- package/dist/src/components/user-group/user-group.js +43 -8
- package/dist/src/components/user-group/user-group.js.map +1 -1
- package/dist/src/components/user-group/user-group.repository.d.ts +1 -0
- package/dist/src/components/user-group/user-group.repository.js +19 -0
- package/dist/src/components/user-group/user-group.repository.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/group/group.ts +43 -0
- package/src/components/user-group/user-group.repository.ts +8 -0
- package/src/components/user-group/user-group.ts +104 -38
package/package.json
CHANGED
@@ -22,6 +22,7 @@ import { User } from '../login-user/user';
|
|
22
22
|
import GroupReportingUserModel from '../../models/group-reporting-user.entity';
|
23
23
|
import GroupModel from '../../models/group.entity';
|
24
24
|
import UserModel from '../../models/user.entity';
|
25
|
+
import { UserGroup } from 'components/user-group';
|
25
26
|
|
26
27
|
export class Group extends TreeNodeBase<Group> {
|
27
28
|
ObjectId: string;
|
@@ -2192,4 +2193,46 @@ export class Group extends TreeNodeBase<Group> {
|
|
2192
2193
|
throw error;
|
2193
2194
|
}
|
2194
2195
|
}
|
2196
|
+
|
2197
|
+
public async unassignUser(
|
2198
|
+
UserId: number,
|
2199
|
+
loginUser: LoginUser,
|
2200
|
+
dbTransaction: Transaction,
|
2201
|
+
) {
|
2202
|
+
try {
|
2203
|
+
const systemCode =
|
2204
|
+
ApplicationConfig.getComponentConfigValue('system-code');
|
2205
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
2206
|
+
systemCode,
|
2207
|
+
'GROUP_UPDATE',
|
2208
|
+
);
|
2209
|
+
|
2210
|
+
if (!isPrivileged) {
|
2211
|
+
throw new ClassError(
|
2212
|
+
'Group',
|
2213
|
+
'GroupErrMsg05',
|
2214
|
+
'You do not have the privilege to update group',
|
2215
|
+
);
|
2216
|
+
}
|
2217
|
+
|
2218
|
+
const userGroup = await UserGroup.findOne(
|
2219
|
+
dbTransaction,
|
2220
|
+
loginUser,
|
2221
|
+
this.GroupCode,
|
2222
|
+
UserId,
|
2223
|
+
);
|
2224
|
+
|
2225
|
+
if (!userGroup) {
|
2226
|
+
throw new ClassError(
|
2227
|
+
'Group',
|
2228
|
+
'GroupErrMsg07',
|
2229
|
+
'User is not assigned to this group',
|
2230
|
+
);
|
2231
|
+
}
|
2232
|
+
|
2233
|
+
await userGroup.delete(loginUser, dbTransaction);
|
2234
|
+
} catch (error) {
|
2235
|
+
throw error;
|
2236
|
+
}
|
2237
|
+
}
|
2195
2238
|
}
|
@@ -647,51 +647,117 @@ export class UserGroup extends ObjectBase {
|
|
647
647
|
}
|
648
648
|
}
|
649
649
|
|
650
|
-
public static isUserMemberOfGroup(
|
650
|
+
public static async isUserMemberOfGroup(
|
651
651
|
dbTransaction: any,
|
652
652
|
loginUser: LoginUser,
|
653
653
|
UserId: number,
|
654
654
|
GroupCode: string,
|
655
655
|
): Promise<boolean> {
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
656
|
+
try {
|
657
|
+
// Part 1: Privilege Checking
|
658
|
+
// Call loginUser.checkPrivileges() to ensure the user has permission to retrieve system access information.
|
659
|
+
// SystemCode: Retrieve from app config.
|
660
|
+
// PrivilegeCode: 'USER_GROUP_VIEW'.
|
661
|
+
const systemCode =
|
662
|
+
ApplicationConfig.getComponentConfigValue('system-code');
|
663
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
664
|
+
systemCode,
|
665
|
+
'USER_GROUP_VIEW',
|
666
|
+
);
|
667
|
+
// If the privilege check fails, throw an error with a 403 Forbidden status.
|
668
|
+
if (!isPrivileged) {
|
669
|
+
throw new ClassError(
|
670
|
+
'UserGroup',
|
671
|
+
'UserGroupErrMsg0X',
|
672
|
+
'User does not have privilege to view user group.',
|
673
|
+
'isUserMemberOfGroup',
|
674
|
+
403,
|
667
675
|
);
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
676
|
+
}
|
677
|
+
// Part 2: Retrieve User Group
|
678
|
+
// Query the sso_UserGroup table to find the user group record with the given UserId and GroupCode.
|
679
|
+
// If the record exists, return true; otherwise, return false.
|
680
|
+
const userGroup = await UserGroup.findOne(
|
681
|
+
dbTransaction,
|
682
|
+
loginUser,
|
683
|
+
GroupCode,
|
684
|
+
UserId,
|
685
|
+
);
|
686
|
+
return !!userGroup;
|
687
|
+
} catch (error) {
|
688
|
+
throw error;
|
689
|
+
}
|
690
|
+
}
|
691
|
+
|
692
|
+
public async delete(
|
693
|
+
loginUser: LoginUser,
|
694
|
+
dbTransaction: Transaction,
|
695
|
+
): Promise<void> {
|
696
|
+
try {
|
697
|
+
// Part 1: Privilege Checking
|
698
|
+
// Call loginUser.checkPrivileges() to ensure the user has permission to delete user group records.
|
699
|
+
// SystemCode: Retrieve from app config.
|
700
|
+
// PrivilegeCode: 'USER_GROUP_DELETE'.
|
701
|
+
const systemCode =
|
702
|
+
ApplicationConfig.getComponentConfigValue('system-code');
|
703
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
704
|
+
systemCode,
|
705
|
+
'USER_GROUP_DELETE',
|
706
|
+
);
|
707
|
+
// If the privilege check fails, throw an error with a 403 Forbidden status.
|
708
|
+
if (!isPrivileged) {
|
709
|
+
throw new ClassError(
|
710
|
+
'UserGroup',
|
711
|
+
'UserGroupErrMsg0X',
|
712
|
+
'User does not have privilege to delete user group.',
|
713
|
+
'delete',
|
714
|
+
403,
|
686
715
|
);
|
687
|
-
if (userGroup) {
|
688
|
-
resolve(true);
|
689
|
-
} else {
|
690
|
-
resolve(false);
|
691
|
-
}
|
692
|
-
} catch (error) {
|
693
|
-
reject(error);
|
694
716
|
}
|
695
|
-
|
717
|
+
// Part 2: Delete User Group
|
718
|
+
// Call the UserGroup._Repo.destroy() method to delete the user group record with the given UserGroupId.
|
719
|
+
// Pass the dbTransaction parameter to ensure the operation is part of the current transaction.
|
720
|
+
await UserGroup._Repository.delete({
|
721
|
+
where: {
|
722
|
+
UserGroupId: this.UserGroupId,
|
723
|
+
},
|
724
|
+
transaction: dbTransaction,
|
725
|
+
});
|
726
|
+
// Part 3: Record Activity History
|
727
|
+
// Initialize a variable entityValueBefore to store the current state of the record before the update.
|
728
|
+
const entityValueBefore = {
|
729
|
+
UserGroupId: this.UserGroupId,
|
730
|
+
UserId: this.UserId,
|
731
|
+
GroupCode: this.GroupCode,
|
732
|
+
Status: this.Status,
|
733
|
+
CreatedById: this._CreatedById,
|
734
|
+
CreatedAt: this._CreatedAt,
|
735
|
+
UpdatedById: this._UpdatedById,
|
736
|
+
UpdatedAt: this._UpdatedAt,
|
737
|
+
InheritGroupPrivilegeYN: this.InheritGroupPrivilegeYN,
|
738
|
+
InheritGroupSystemAccessYN: this.InheritGroupSystemAccessYN,
|
739
|
+
};
|
740
|
+
// Create an instance of the Activity class and set the following properties:
|
741
|
+
// ActivityId: Call activity.createId().
|
742
|
+
// Action: Set to ActionEnum.Delete.
|
743
|
+
// Description: Set to Delete User Group.
|
744
|
+
// EntityType: Set to UserGroup.
|
745
|
+
// EntityId: Use the ID of the deleted record.
|
746
|
+
// EntityValueBefore: Stringify entityValueBefore to capture the state before the delete.
|
747
|
+
// EntityValueAfter: Set to an empty string to indicate the record has been deleted.
|
748
|
+
const activity = new Activity();
|
749
|
+
activity.ActivityId = activity.createId();
|
750
|
+
activity.Action = ActionEnum.DELETE;
|
751
|
+
activity.Description = `Delete User Group ${this.UserGroupId}`;
|
752
|
+
activity.EntityType = 'UserGroup';
|
753
|
+
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
754
|
+
activity.EntityValueAfter = JSON.stringify({});
|
755
|
+
// Call the activity create method with the following parameters:
|
756
|
+
// dbTransaction
|
757
|
+
// userId: loginUser.UserId
|
758
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
759
|
+
} catch (error) {
|
760
|
+
throw error;
|
761
|
+
}
|
696
762
|
}
|
697
763
|
}
|