@tomei/sso 0.58.11 → 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/src/enum/building-type.enum.d.ts +6 -0
- package/dist/src/enum/building-type.enum.js +11 -0
- package/dist/src/enum/building-type.enum.js.map +1 -0
- package/dist/src/models/building.entity.d.ts +9 -18
- package/dist/src/models/building.entity.js +44 -133
- package/dist/src/models/building.entity.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/src/enum/building-type.enum.ts +6 -0
- package/src/models/building.entity.ts +30 -128
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
|
}
|
@@ -4,198 +4,100 @@ import {
|
|
4
4
|
CreatedAt,
|
5
5
|
DataType,
|
6
6
|
ForeignKey,
|
7
|
-
HasMany,
|
8
7
|
Model,
|
9
8
|
Table,
|
10
9
|
UpdatedAt,
|
11
10
|
} from 'sequelize-typescript';
|
12
|
-
|
13
|
-
import
|
14
|
-
import Staff from './staff.entity';
|
11
|
+
import { BuildingTypeEnum } from '../enum/building-type.enum';
|
12
|
+
import GroupModel from './group.entity';
|
15
13
|
|
16
14
|
@Table({
|
17
|
-
tableName: '
|
15
|
+
tableName: 'sso_Building',
|
18
16
|
timestamps: true,
|
19
|
-
createdAt: '
|
20
|
-
updatedAt: '
|
21
|
-
underscored: true,
|
17
|
+
createdAt: 'CreatedAt',
|
18
|
+
updatedAt: 'UpdatedAt',
|
22
19
|
})
|
23
|
-
export default class
|
20
|
+
export default class BuildingModel extends Model {
|
21
|
+
@ForeignKey(() => GroupModel)
|
24
22
|
@Column({
|
25
23
|
primaryKey: true,
|
26
24
|
allowNull: false,
|
27
|
-
|
28
|
-
type: DataType.INTEGER,
|
29
|
-
})
|
30
|
-
id: number;
|
31
|
-
|
32
|
-
@Column({
|
33
|
-
allowNull: true,
|
34
|
-
type: DataType.STRING,
|
35
|
-
field: 'name',
|
36
|
-
})
|
37
|
-
Name: string;
|
38
|
-
|
39
|
-
@Column({
|
40
|
-
allowNull: false,
|
41
|
-
type: DataType.STRING,
|
42
|
-
field: 'code',
|
25
|
+
type: DataType.STRING(10),
|
43
26
|
})
|
44
|
-
|
45
|
-
|
46
|
-
// @ForeignKey(() => BuildingType)
|
47
|
-
// @Column({
|
48
|
-
// allowNull: false,
|
49
|
-
// type: DataType.INTEGER,
|
50
|
-
// field: 'building_type_id',
|
51
|
-
// })
|
52
|
-
// BuildingTypeId: number;
|
27
|
+
GroupCode: string;
|
53
28
|
|
54
29
|
@Column({
|
55
30
|
allowNull: false,
|
56
|
-
type: DataType.STRING,
|
57
|
-
field: 'status',
|
31
|
+
type: DataType.STRING(100),
|
58
32
|
})
|
59
|
-
|
33
|
+
BuildingType: BuildingTypeEnum;
|
60
34
|
|
61
35
|
@Column({
|
62
36
|
allowNull: true,
|
63
|
-
type: DataType.STRING,
|
64
|
-
field: 'email',
|
37
|
+
type: DataType.STRING(200),
|
65
38
|
})
|
66
39
|
Email: string;
|
67
40
|
|
68
41
|
@Column({
|
69
42
|
allowNull: true,
|
70
|
-
type: DataType.STRING,
|
71
|
-
field: 'mobile',
|
43
|
+
type: DataType.STRING(20),
|
72
44
|
})
|
73
45
|
Mobile: string;
|
74
46
|
|
75
47
|
@Column({
|
76
48
|
allowNull: false,
|
77
|
-
type: DataType.STRING,
|
78
|
-
field: 'phone',
|
49
|
+
type: DataType.STRING(20),
|
79
50
|
})
|
80
51
|
Phone: string;
|
81
52
|
|
82
|
-
@Column({
|
83
|
-
allowNull: false,
|
84
|
-
type: DataType.STRING,
|
85
|
-
field: 'address',
|
86
|
-
})
|
87
|
-
Address: string;
|
88
|
-
|
89
53
|
@Column({
|
90
54
|
allowNull: true,
|
91
|
-
type: DataType.STRING,
|
92
|
-
field: 'latitude',
|
55
|
+
type: DataType.STRING(10),
|
93
56
|
})
|
94
|
-
|
57
|
+
Brand: string;
|
95
58
|
|
96
59
|
@Column({
|
97
|
-
allowNull:
|
98
|
-
type: DataType.
|
99
|
-
field: 'longitude',
|
60
|
+
allowNull: false,
|
61
|
+
type: DataType.INTEGER,
|
100
62
|
})
|
101
|
-
|
63
|
+
AreaManagerUserId: number;
|
102
64
|
|
103
65
|
@Column({
|
104
66
|
allowNull: false,
|
105
|
-
type: DataType.
|
106
|
-
field: 'postcode',
|
67
|
+
type: DataType.DATE,
|
107
68
|
})
|
108
|
-
|
109
|
-
|
110
|
-
// @ForeignKey(() => Country)
|
111
|
-
// @Column({
|
112
|
-
// allowNull: false,
|
113
|
-
// type: DataType.INTEGER,
|
114
|
-
// field: 'country_id',
|
115
|
-
// })
|
116
|
-
// CountryId: number;
|
69
|
+
OpeningDate: Date;
|
117
70
|
|
118
71
|
@Column({
|
119
72
|
allowNull: false,
|
120
|
-
type: DataType.
|
121
|
-
field: 'state',
|
73
|
+
type: DataType.DATE,
|
122
74
|
})
|
123
|
-
|
75
|
+
CeasedDate: Date;
|
124
76
|
|
125
77
|
@Column({
|
126
|
-
allowNull:
|
127
|
-
type: DataType.STRING,
|
128
|
-
field: 'city',
|
78
|
+
allowNull: true,
|
79
|
+
type: DataType.STRING(200),
|
129
80
|
})
|
130
|
-
|
81
|
+
OpeningHours: string;
|
131
82
|
|
132
|
-
@ForeignKey(() => User)
|
133
83
|
@Column({
|
134
|
-
allowNull:
|
84
|
+
allowNull: false,
|
135
85
|
type: DataType.INTEGER,
|
136
|
-
field: 'created_by_id',
|
137
86
|
})
|
138
87
|
CreatedById: number;
|
139
88
|
|
140
|
-
@ForeignKey(() => User)
|
141
89
|
@Column({
|
142
|
-
allowNull:
|
90
|
+
allowNull: false,
|
143
91
|
type: DataType.INTEGER,
|
144
|
-
field: 'updated_by_id',
|
145
92
|
})
|
146
93
|
UpdatedById: number;
|
147
94
|
|
148
|
-
@Column({
|
149
|
-
allowNull: true,
|
150
|
-
type: DataType.STRING,
|
151
|
-
field: 'brand',
|
152
|
-
})
|
153
|
-
Brand: string;
|
154
|
-
|
155
|
-
@Column({
|
156
|
-
allowNull: true,
|
157
|
-
type: DataType.STRING,
|
158
|
-
field: 'area_staff_id',
|
159
|
-
})
|
160
|
-
AreaStaffId: string;
|
161
|
-
|
162
|
-
@Column({
|
163
|
-
allowNull: true,
|
164
|
-
type: DataType.DATE,
|
165
|
-
field: 'opening_date',
|
166
|
-
})
|
167
|
-
OpeningDate: Date;
|
168
|
-
|
169
|
-
@Column({
|
170
|
-
allowNull: true,
|
171
|
-
type: DataType.DATE,
|
172
|
-
field: 'ceased_date',
|
173
|
-
})
|
174
|
-
CeasedDate: Date;
|
175
|
-
|
176
|
-
@Column({
|
177
|
-
allowNull: true,
|
178
|
-
type: DataType.STRING,
|
179
|
-
field: 'opening_hours',
|
180
|
-
})
|
181
|
-
OpeningHours: string;
|
182
|
-
|
183
|
-
@Column({
|
184
|
-
allowNull: true,
|
185
|
-
type: DataType.STRING,
|
186
|
-
field: 'image',
|
187
|
-
})
|
188
|
-
Image: string;
|
189
|
-
|
190
95
|
@CreatedAt
|
191
96
|
CreatedAt: Date;
|
192
97
|
|
193
98
|
@UpdatedAt
|
194
99
|
UpdatedAt: Date;
|
195
100
|
|
196
|
-
@BelongsTo(() =>
|
197
|
-
|
198
|
-
|
199
|
-
@BelongsTo(() => User, 'updated_by_id')
|
200
|
-
UpdatedBy: User;
|
101
|
+
@BelongsTo(() => GroupModel, 'GroupCode')
|
102
|
+
Group: GroupModel;
|
201
103
|
}
|