@tomei/sso 0.37.3 → 0.38.0
Sign up to get free protection for your applications and to get access to all the features.
- package/__tests__/unit/components/group-object-privilege/group-object-privilege.spec.ts +4 -4
- package/__tests__/unit/components/group-privilege/group-privilege.spec.ts +3 -3
- package/__tests__/unit/components/user-object-privilege/user-object-privilege.spec.ts +3 -3
- package/__tests__/unit/components/user-privilege/user-privilege.spec.ts +3 -3
- package/dist/__tests__/unit/components/group-object-privilege/group-object-privilege.spec.js +4 -4
- package/dist/__tests__/unit/components/group-object-privilege/group-object-privilege.spec.js.map +1 -1
- package/dist/__tests__/unit/components/group-privilege/group-privilege.spec.js +3 -3
- package/dist/__tests__/unit/components/group-privilege/group-privilege.spec.js.map +1 -1
- package/dist/__tests__/unit/components/user-object-privilege/user-object-privilege.spec.js +3 -3
- package/dist/__tests__/unit/components/user-object-privilege/user-object-privilege.spec.js.map +1 -1
- package/dist/__tests__/unit/components/user-privilege/user-privilege.spec.js +3 -3
- package/dist/__tests__/unit/components/user-privilege/user-privilege.spec.js.map +1 -1
- package/dist/src/components/group/group.d.ts +23 -12
- package/dist/src/components/group/group.js +188 -42
- package/dist/src/components/group/group.js.map +1 -1
- package/dist/src/components/group-object-privilege/group-object-privilege.d.ts +1 -1
- package/dist/src/components/group-object-privilege/group-object-privilege.js +7 -7
- package/dist/src/components/group-object-privilege/group-object-privilege.js.map +1 -1
- package/dist/src/components/group-privilege/group-privilege.d.ts +1 -1
- package/dist/src/components/group-privilege/group-privilege.js +2 -2
- package/dist/src/components/group-privilege/group-privilege.js.map +1 -1
- package/dist/src/components/group-privilege/group-privilege.repository.d.ts +1 -1
- package/dist/src/components/group-privilege/group-privilege.repository.js +11 -3
- package/dist/src/components/group-privilege/group-privilege.repository.js.map +1 -1
- package/dist/src/components/login-user/login-user.js.map +1 -1
- package/dist/src/components/login-user/user.js +2 -2
- package/dist/src/components/login-user/user.js.map +1 -1
- package/dist/src/components/system/system.js +1 -1
- package/dist/src/components/system/system.js.map +1 -1
- package/dist/src/components/system-privilege/system-privilege.d.ts +4 -3
- package/dist/src/components/system-privilege/system-privilege.js +18 -11
- package/dist/src/components/system-privilege/system-privilege.js.map +1 -1
- package/dist/src/components/user-group/user-group.js +2 -1
- package/dist/src/components/user-group/user-group.js.map +1 -1
- package/dist/src/components/user-object-privilege/user-object-privilege.d.ts +1 -1
- package/dist/src/components/user-object-privilege/user-object-privilege.js +1 -1
- package/dist/src/components/user-object-privilege/user-object-privilege.js.map +1 -1
- package/dist/src/components/user-privilege/user-privilege.d.ts +1 -1
- package/dist/src/components/user-privilege/user-privilege.js +1 -1
- package/dist/src/components/user-privilege/user-privilege.js.map +1 -1
- package/dist/src/interfaces/group-object-privilege.interface.d.ts +1 -1
- package/dist/src/interfaces/group-privilege.interface.d.ts +1 -1
- package/dist/src/interfaces/group.interface.d.ts +1 -0
- package/dist/src/interfaces/system-privilege.interface.d.ts +1 -0
- package/dist/src/interfaces/user-object-privilege.interface.d.ts +1 -1
- package/dist/src/interfaces/user-privilege.interface.d.ts +1 -1
- package/dist/src/models/group-object-privilege.entity.d.ts +1 -1
- package/dist/src/models/group-object-privilege.entity.js +1 -1
- package/dist/src/models/group-object-privilege.entity.js.map +1 -1
- package/dist/src/models/group-privilege.entity.d.ts +1 -1
- package/dist/src/models/group-privilege.entity.js +1 -1
- package/dist/src/models/group-privilege.entity.js.map +1 -1
- package/dist/src/models/group.entity.d.ts +1 -0
- package/dist/src/models/group.entity.js +7 -0
- package/dist/src/models/group.entity.js.map +1 -1
- package/dist/src/models/system-privilege.entity.d.ts +1 -0
- package/dist/src/models/system-privilege.entity.js +8 -0
- package/dist/src/models/system-privilege.entity.js.map +1 -1
- package/dist/src/models/user-object-privilege.entity.d.ts +1 -1
- package/dist/src/models/user-object-privilege.entity.js +1 -1
- package/dist/src/models/user-object-privilege.entity.js.map +1 -1
- package/dist/src/models/user-privilege.entity.d.ts +1 -1
- package/dist/src/models/user-privilege.entity.js +1 -1
- package/dist/src/models/user-privilege.entity.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/20240527064926-create-system-privilege-table.js +66 -62
- package/migrations/20240527065342-create-group-table.js +4 -0
- package/migrations/20240528032229-user-privilege-table.js +2 -2
- package/migrations/20240528063003-create-group-privilege-table.js +12 -2
- package/migrations/20240528063051-create-group-object-privilege-table.js +2 -2
- package/migrations/20240528063107-create-user-object-privilege-table.js +2 -2
- package/package.json +8 -8
- package/src/components/group/group.ts +225 -60
- package/src/components/group-object-privilege/group-object-privilege.ts +9 -9
- package/src/components/group-privilege/group-privilege.repository.ts +16 -3
- package/src/components/group-privilege/group-privilege.ts +3 -3
- package/src/components/login-user/login-user.ts +0 -58
- package/src/components/login-user/user.ts +2 -4
- package/src/components/system/system.ts +1 -1
- package/src/components/system-privilege/system-privilege.ts +20 -12
- package/src/components/user-group/user-group.ts +2 -1
- package/src/components/user-object-privilege/user-object-privilege.ts +2 -2
- package/src/components/user-privilege/user-privilege.ts +2 -2
- package/src/interfaces/group-object-privilege.interface.ts +1 -1
- package/src/interfaces/group-privilege.interface.ts +1 -1
- package/src/interfaces/group.interface.ts +1 -0
- package/src/interfaces/system-privilege.interface.ts +1 -0
- package/src/interfaces/user-object-privilege.interface.ts +1 -1
- package/src/interfaces/user-privilege.interface.ts +1 -1
- package/src/models/group-object-privilege.entity.ts +1 -1
- package/src/models/group-privilege.entity.ts +1 -1
- package/src/models/group.entity.ts +6 -0
- package/src/models/system-privilege.entity.ts +7 -0
- package/src/models/user-object-privilege.entity.ts +1 -1
- package/src/models/user-privilege.entity.ts +1 -1
@@ -104,64 +104,6 @@ export class LoginUser extends User implements ILoginUser {
|
|
104
104
|
}
|
105
105
|
}
|
106
106
|
|
107
|
-
// private async checkSystemAccess(
|
108
|
-
// userId: number,
|
109
|
-
// systemCode: string,
|
110
|
-
// dbTransaction?: any,
|
111
|
-
// ): Promise<void> {
|
112
|
-
// try {
|
113
|
-
// let isUserHaveAccess = false;
|
114
|
-
|
115
|
-
// const systemAccess = await User._UserSystemAccessRepo.findOne({
|
116
|
-
// where: {
|
117
|
-
// UserId: userId,
|
118
|
-
// SystemCode: systemCode,
|
119
|
-
// Status: 'Active',
|
120
|
-
// },
|
121
|
-
// dbTransaction,
|
122
|
-
// });
|
123
|
-
|
124
|
-
// if (systemAccess) {
|
125
|
-
// isUserHaveAccess = true;
|
126
|
-
// } else {
|
127
|
-
// const userGroups = await User._UserGroupRepo.findAll({
|
128
|
-
// where: {
|
129
|
-
// UserId: userId,
|
130
|
-
// InheritGroupAccessYN: 'Y',
|
131
|
-
// Status: 'Active',
|
132
|
-
// },
|
133
|
-
// include: [
|
134
|
-
// {
|
135
|
-
// model: GroupModel,
|
136
|
-
// },
|
137
|
-
// ],
|
138
|
-
// dbTransaction,
|
139
|
-
// });
|
140
|
-
|
141
|
-
// for (const usergroup of userGroups) {
|
142
|
-
// const group = usergroup.Group;
|
143
|
-
// const groupSystemAccess = await User.getInheritedSystemAccess(
|
144
|
-
// dbTransaction,
|
145
|
-
// group,
|
146
|
-
// );
|
147
|
-
|
148
|
-
// for (const system of groupSystemAccess) {
|
149
|
-
// if (system.SystemCode === systemCode) {
|
150
|
-
// isUserHaveAccess = true;
|
151
|
-
// break;
|
152
|
-
// }
|
153
|
-
// }
|
154
|
-
// }
|
155
|
-
// }
|
156
|
-
|
157
|
-
// if (!isUserHaveAccess) {
|
158
|
-
// throw new Error("User don't have access to the system.");
|
159
|
-
// }
|
160
|
-
// } catch (error) {
|
161
|
-
// throw error;
|
162
|
-
// }
|
163
|
-
// }
|
164
|
-
|
165
107
|
async checkSession(
|
166
108
|
systemCode: string,
|
167
109
|
sessionId: string,
|
@@ -6,8 +6,6 @@ import { SystemRepository } from '../system/system.repository';
|
|
6
6
|
import { LoginHistoryRepository } from '../login-history/login-history.repository';
|
7
7
|
import { PasswordHashService } from '../password-hash/password-hash.service';
|
8
8
|
import { UserGroupRepository } from '../user-group/user-group.repository';
|
9
|
-
import { SMTPMailer } from '@tomei/mailer';
|
10
|
-
import { ISystemLogin } from '../../../src/interfaces/system-login.interface';
|
11
9
|
import Staff from '../../models/staff.entity';
|
12
10
|
import SystemPrivilege from '../../models/system-privilege.entity';
|
13
11
|
import LoginHistory from '../../models/login-history.entity';
|
@@ -1380,7 +1378,7 @@ export class User extends UserBase {
|
|
1380
1378
|
//Part 5: Record Create User Activity
|
1381
1379
|
const activity = new Activity();
|
1382
1380
|
activity.ActivityId = activity.createId();
|
1383
|
-
activity.Action = ActionEnum.
|
1381
|
+
activity.Action = ActionEnum.CREATE;
|
1384
1382
|
activity.Description = 'Create User';
|
1385
1383
|
activity.EntityType = 'LoginUser';
|
1386
1384
|
activity.EntityId = newUser.UserId.toString();
|
@@ -1938,7 +1936,7 @@ export class User extends UserBase {
|
|
1938
1936
|
//4. Record Create UserGroup Activity
|
1939
1937
|
const activity = new Activity();
|
1940
1938
|
activity.ActivityId = activity.createId();
|
1941
|
-
activity.Action = ActionEnum.
|
1939
|
+
activity.Action = ActionEnum.CREATE;
|
1942
1940
|
activity.Description = 'Add User Group';
|
1943
1941
|
activity.EntityType = 'UserGroup';
|
1944
1942
|
activity.EntityId = group.GroupCode;
|
@@ -179,7 +179,7 @@ export class System extends ObjectBase {
|
|
179
179
|
//Instantiate new activity from Activity class, call createId() method, then set the properties.
|
180
180
|
const activity = new Activity();
|
181
181
|
activity.ActivityId = activity.createId();
|
182
|
-
activity.Action = ActionEnum.
|
182
|
+
activity.Action = ActionEnum.CREATE;
|
183
183
|
activity.Description = 'Add System';
|
184
184
|
activity.EntityType = 'System';
|
185
185
|
activity.EntityId = this.SystemCode;
|
@@ -13,6 +13,7 @@ export class SystemPrivilege extends ObjectBase {
|
|
13
13
|
ObjectType = 'SystemPrivilege';
|
14
14
|
TableName = 'sso_SystemPrivilege';
|
15
15
|
ObjectId: string;
|
16
|
+
PrivilegeCode: string;
|
16
17
|
SystemCode: string;
|
17
18
|
ObjectName: string;
|
18
19
|
Description: string;
|
@@ -22,11 +23,11 @@ export class SystemPrivilege extends ObjectBase {
|
|
22
23
|
private _CreatedById: number;
|
23
24
|
private _UpdatedById: number;
|
24
25
|
|
25
|
-
get
|
26
|
+
get SystemPrivilegeId() {
|
26
27
|
return this.ObjectId;
|
27
28
|
}
|
28
29
|
|
29
|
-
set
|
30
|
+
set SystemPrivilegeId(value: string) {
|
30
31
|
this.ObjectId = value;
|
31
32
|
}
|
32
33
|
|
@@ -52,7 +53,8 @@ export class SystemPrivilege extends ObjectBase {
|
|
52
53
|
private constructor(systemPrivilegeAttr?: ISystemPrivilegeAttr) {
|
53
54
|
super();
|
54
55
|
if (systemPrivilegeAttr) {
|
55
|
-
this.
|
56
|
+
this.SystemPrivilegeId = systemPrivilegeAttr.SystemPrivilegeId;
|
57
|
+
this.PrivilegeCode = systemPrivilegeAttr.PrivilegeCode;
|
56
58
|
this.SystemCode = systemPrivilegeAttr.SystemCode;
|
57
59
|
this.Description = systemPrivilegeAttr.Description;
|
58
60
|
this.Status = systemPrivilegeAttr.Status;
|
@@ -64,7 +66,8 @@ export class SystemPrivilege extends ObjectBase {
|
|
64
66
|
}
|
65
67
|
|
66
68
|
setAttributes(systemPrivilegeAttr: ISystemPrivilegeAttr) {
|
67
|
-
this.
|
69
|
+
this.PrivilegeCode = systemPrivilegeAttr.PrivilegeCode;
|
70
|
+
this.SystemPrivilegeId = systemPrivilegeAttr.SystemPrivilegeId;
|
68
71
|
this.SystemCode = systemPrivilegeAttr.SystemCode;
|
69
72
|
this.Description = systemPrivilegeAttr.Description;
|
70
73
|
this.Status = systemPrivilegeAttr.Status;
|
@@ -74,18 +77,19 @@ export class SystemPrivilege extends ObjectBase {
|
|
74
77
|
this._UpdatedById = systemPrivilegeAttr.UpdatedById;
|
75
78
|
}
|
76
79
|
|
77
|
-
static async init(dbTransaction: any,
|
80
|
+
static async init(dbTransaction: any, SystemPrivilegeId?: string) {
|
78
81
|
try {
|
79
82
|
const systemPrivilege = new SystemPrivilege();
|
80
|
-
if (
|
83
|
+
if (SystemPrivilegeId) {
|
81
84
|
const systemPrivilegeAttr = await this._Repository.findByPk(
|
82
|
-
|
85
|
+
SystemPrivilegeId,
|
83
86
|
{
|
84
87
|
transaction: dbTransaction,
|
85
88
|
},
|
86
89
|
);
|
87
90
|
if (systemPrivilegeAttr) {
|
88
|
-
systemPrivilege.
|
91
|
+
systemPrivilege.PrivilegeCode = systemPrivilegeAttr.PrivilegeCode;
|
92
|
+
systemPrivilege.ObjectId = systemPrivilegeAttr.SystemPrivilegeId;
|
89
93
|
systemPrivilege.SystemCode = systemPrivilegeAttr.SystemCode;
|
90
94
|
systemPrivilege.Description = systemPrivilegeAttr.Description;
|
91
95
|
systemPrivilege.Status = systemPrivilegeAttr.Status;
|
@@ -114,7 +118,7 @@ export class SystemPrivilege extends ObjectBase {
|
|
114
118
|
) {
|
115
119
|
try {
|
116
120
|
//Part 1: Privilege Checking
|
117
|
-
const systemCode =
|
121
|
+
const systemCode: string =
|
118
122
|
ApplicationConfig.getComponentConfigValue('system-code');
|
119
123
|
const isPrivileged = await loginUser.checkPrivileges(
|
120
124
|
systemCode,
|
@@ -169,7 +173,8 @@ export class SystemPrivilege extends ObjectBase {
|
|
169
173
|
//Part 3: Create Privilege
|
170
174
|
//Initialise new SystemPrivilege instance and populate below
|
171
175
|
const newSystemPrivilege = new SystemPrivilege();
|
172
|
-
newSystemPrivilege.ObjectId =
|
176
|
+
newSystemPrivilege.ObjectId = newSystemPrivilege.createId();
|
177
|
+
newSystemPrivilege.PrivilegeCode = systemPrivilege.PrivilegeCode;
|
173
178
|
newSystemPrivilege.SystemCode = systemPrivilege.SystemCode;
|
174
179
|
newSystemPrivilege.Description = systemPrivilege.Description;
|
175
180
|
newSystemPrivilege.Status = 'Active';
|
@@ -181,7 +186,8 @@ export class SystemPrivilege extends ObjectBase {
|
|
181
186
|
//Call SystemPrivilege._Repo create method
|
182
187
|
await this._Repository.create(
|
183
188
|
{
|
184
|
-
|
189
|
+
SystemPrivilegeId: newSystemPrivilege.ObjectId,
|
190
|
+
PrivilegeCode: newSystemPrivilege.PrivilegeCode,
|
185
191
|
SystemCode: newSystemPrivilege.SystemCode,
|
186
192
|
Description: newSystemPrivilege.Description,
|
187
193
|
Status: newSystemPrivilege.Status,
|
@@ -202,7 +208,7 @@ export class SystemPrivilege extends ObjectBase {
|
|
202
208
|
//Instantiate new activity object and populate
|
203
209
|
const activity = new Activity();
|
204
210
|
activity.ActivityId = activity.createId();
|
205
|
-
activity.Action = ActionEnum.
|
211
|
+
activity.Action = ActionEnum.CREATE;
|
206
212
|
activity.Description = 'Add System Privilege';
|
207
213
|
activity.EntityType = 'SystemPrivilege';
|
208
214
|
activity.EntityId = newSystemPrivilege.SystemCode;
|
@@ -345,9 +351,11 @@ export class SystemPrivilege extends ObjectBase {
|
|
345
351
|
);
|
346
352
|
|
347
353
|
//Call SystemPrivilege._Repo create method for each newPrivileges.
|
354
|
+
const np = new SystemPrivilege();
|
348
355
|
for (const privilegeConfig of tobeCreatePrivileges) {
|
349
356
|
await this._Repository.create(
|
350
357
|
{
|
358
|
+
SystemPrivilegeId: np.createId(),
|
351
359
|
PrivilegeCode: privilegeConfig.privilegeCode,
|
352
360
|
SystemCode: systemCode,
|
353
361
|
Description: privilegeConfig.description,
|
@@ -226,7 +226,8 @@ export class UserGroup extends ObjectBase {
|
|
226
226
|
// EntityValueBefore: <stringify of empty object>
|
227
227
|
// EntityValueAfter: EntityValueAfter
|
228
228
|
const activity = new Activity();
|
229
|
-
activity.
|
229
|
+
activity.ActivityId = activity.createId();
|
230
|
+
activity.Action = ActionEnum.CREATE;
|
230
231
|
activity.Description = 'Assign user to group.';
|
231
232
|
activity.EntityType = 'UserGroup';
|
232
233
|
activity.EntityId = this.UserGroupId.toString();
|
@@ -8,7 +8,7 @@ export class UserObjectPrivilege extends ObjectBase {
|
|
8
8
|
ObjectName: string;
|
9
9
|
ObjectPrivilegeId: number;
|
10
10
|
UserId: number;
|
11
|
-
|
11
|
+
SystemPrivilegeId: string;
|
12
12
|
ObjectId: string;
|
13
13
|
ObjectType: string;
|
14
14
|
Status: ObjectStatus;
|
@@ -40,7 +40,7 @@ export class UserObjectPrivilege extends ObjectBase {
|
|
40
40
|
if (userObjectPrivilegeAttr) {
|
41
41
|
this.ObjectPrivilegeId = userObjectPrivilegeAttr.ObjectPrivilegeId;
|
42
42
|
this.UserId = userObjectPrivilegeAttr.UserId;
|
43
|
-
this.
|
43
|
+
this.SystemPrivilegeId = userObjectPrivilegeAttr.SystemPrivilegeId;
|
44
44
|
this.ObjectId = userObjectPrivilegeAttr.ObjectId;
|
45
45
|
this.ObjectType = userObjectPrivilegeAttr.ObjectType;
|
46
46
|
this.Status = userObjectPrivilegeAttr.Status;
|
@@ -9,7 +9,7 @@ export class UserPrivilege extends ObjectBase {
|
|
9
9
|
ObjectId: string;
|
10
10
|
UserPrivilegeId: number;
|
11
11
|
UserId: number;
|
12
|
-
|
12
|
+
SystemPrivilegeId: string;
|
13
13
|
Status: string;
|
14
14
|
private _CreatedById: number;
|
15
15
|
private _UpdatedById: number;
|
@@ -39,7 +39,7 @@ export class UserPrivilege extends ObjectBase {
|
|
39
39
|
if (userPrivilegeAttr) {
|
40
40
|
this.UserPrivilegeId = userPrivilegeAttr.UserPrivilegeId;
|
41
41
|
this.UserId = userPrivilegeAttr.UserId;
|
42
|
-
this.
|
42
|
+
this.SystemPrivilegeId = userPrivilegeAttr.SystemPrivilegeId;
|
43
43
|
this.Status = userPrivilegeAttr.Status;
|
44
44
|
this._CreatedById = userPrivilegeAttr.CreatedById;
|
45
45
|
this._UpdatedById = userPrivilegeAttr.UpdatedById;
|
@@ -3,7 +3,7 @@ import { ObjectStatus } from '../enum/object-status.enum';
|
|
3
3
|
export interface IGroupObjectPrivilegeAttr {
|
4
4
|
GroupObjectPrivilegeId?: number;
|
5
5
|
GroupCode: string;
|
6
|
-
|
6
|
+
SystemPrivilegeId: string;
|
7
7
|
ObjectId: string;
|
8
8
|
ObjectType: string;
|
9
9
|
Status: ObjectStatus;
|
@@ -3,7 +3,7 @@ import { ObjectStatus } from '../enum/object-status.enum';
|
|
3
3
|
export interface IUserObjectPrivilegeAttr {
|
4
4
|
ObjectPrivilegeId: number;
|
5
5
|
UserId: number;
|
6
|
-
|
6
|
+
SystemPrivilegeId: string;
|
7
7
|
ObjectId: string;
|
8
8
|
ObjectType: string;
|
9
9
|
Status: ObjectStatus;
|
@@ -22,6 +22,13 @@ import UserPrivilegeModel from './user-privilege.entity';
|
|
22
22
|
export default class SystemPrivilegeModel extends Model {
|
23
23
|
@Column({
|
24
24
|
primaryKey: true,
|
25
|
+
allowNull: false,
|
26
|
+
type: DataType.STRING(30),
|
27
|
+
field: 'SystemPrivilegeId',
|
28
|
+
})
|
29
|
+
SystemPrivilegeId: string;
|
30
|
+
|
31
|
+
@Column({
|
25
32
|
allowNull: false,
|
26
33
|
type: DataType.STRING(50),
|
27
34
|
field: 'PrivilegeCode',
|