@tomei/sso 0.52.1 → 0.52.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/src/components/group/group.js +0 -4
- package/dist/src/components/group/group.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 +146 -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 +17 -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/group/group.ts +0 -5
- package/src/components/user-system-access/user-system-access.repository.ts +16 -0
- package/src/components/user-system-access/user-system-access.ts +230 -1
package/package.json
CHANGED
@@ -1192,11 +1192,6 @@ export class Group extends TreeNodeBase<Group> {
|
|
1192
1192
|
//Retrieve Roles based on privilege on a system
|
1193
1193
|
let systemWhere: any = {};
|
1194
1194
|
|
1195
|
-
if (search) {
|
1196
|
-
if (search.GroupCode.length) {
|
1197
|
-
}
|
1198
|
-
}
|
1199
|
-
|
1200
1195
|
if (SystemCode) {
|
1201
1196
|
systemWhere = {
|
1202
1197
|
SystemCode: {
|
@@ -9,6 +9,22 @@ export class UserSystemAccessRepository
|
|
9
9
|
super(UserSystemAccessModel);
|
10
10
|
}
|
11
11
|
|
12
|
+
async findAndCountAll(options?: any) {
|
13
|
+
try {
|
14
|
+
let UserSystemAccess: any;
|
15
|
+
if (options) {
|
16
|
+
UserSystemAccess = await UserSystemAccessModel.findAndCountAll(options);
|
17
|
+
} else {
|
18
|
+
UserSystemAccess = await UserSystemAccessModel.findAndCountAll();
|
19
|
+
}
|
20
|
+
return UserSystemAccess;
|
21
|
+
} catch (error) {
|
22
|
+
throw new Error(
|
23
|
+
`An Error occured when retriving UserSystemAccess: ${error.message}`,
|
24
|
+
);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
12
28
|
async delete(UserSystemAccessId: number, dbTransaction?: any) {
|
13
29
|
try {
|
14
30
|
const options = {
|
@@ -2,9 +2,12 @@ import { ClassError, ObjectBase } from '@tomei/general';
|
|
2
2
|
import { UserSystemAccessRepository } from './user-system-access.repository';
|
3
3
|
import { IUserSystemAccess } from '../../interfaces/user-system-access.interface';
|
4
4
|
import { User } from '../login-user/user';
|
5
|
-
import { System } from '../system/system';
|
6
5
|
import { ApplicationConfig } from '@tomei/config';
|
7
6
|
import SystemModel from '../../models/system.entity';
|
7
|
+
import SystemPrivilegeModel from '../../models/system-privilege.entity';
|
8
|
+
import UserSystemAccessModel from '../../models/user-system-access.entity';
|
9
|
+
import GroupModel from '../../models/group.entity';
|
10
|
+
import GroupSystemAccessModel from '../../models/group-system-access.entity';
|
8
11
|
import UserModel from '../../models/user.entity';
|
9
12
|
import { ActionEnum, Activity } from '@tomei/activity-history';
|
10
13
|
import { Op } from 'sequelize';
|
@@ -182,6 +185,232 @@ export class UserSystemAccess extends ObjectBase {
|
|
182
185
|
}
|
183
186
|
}
|
184
187
|
|
188
|
+
public static async findAllUsers(
|
189
|
+
loginUser: User, //The currently logged-in user initiating the request.
|
190
|
+
dbTransaction: any, //The active database transaction to ensure consistency during the query.
|
191
|
+
SystemCode: string,
|
192
|
+
Page: number,
|
193
|
+
Rows: number,
|
194
|
+
Search: {
|
195
|
+
UserId?: string | number;
|
196
|
+
Status?: string;
|
197
|
+
},
|
198
|
+
) {
|
199
|
+
// Part 1: Privilege Checking
|
200
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
201
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
202
|
+
systemCode,
|
203
|
+
'USER_SYSTEM_ACCESS_LIST',
|
204
|
+
);
|
205
|
+
|
206
|
+
if (!isPrivileged) {
|
207
|
+
throw new ClassError(
|
208
|
+
'UserSystemAccessUser',
|
209
|
+
'UserSystemAccessUserErrMsg01',
|
210
|
+
'You do not have permission to view system access users.',
|
211
|
+
);
|
212
|
+
}
|
213
|
+
|
214
|
+
try {
|
215
|
+
// Part 2: Retrieve System Access Users and returns
|
216
|
+
const queryObj: any = { SystemCode: SystemCode };
|
217
|
+
|
218
|
+
if (Search) {
|
219
|
+
Object.entries(Search).forEach(([key, value]) => {
|
220
|
+
queryObj[key] = value;
|
221
|
+
});
|
222
|
+
}
|
223
|
+
|
224
|
+
let options: any = {
|
225
|
+
where: queryObj,
|
226
|
+
distinct: true,
|
227
|
+
transaction: dbTransaction,
|
228
|
+
};
|
229
|
+
|
230
|
+
if (Page && Rows) {
|
231
|
+
options = {
|
232
|
+
...options,
|
233
|
+
limit: Rows,
|
234
|
+
offset: Rows * (Page - 1),
|
235
|
+
order: [['CreatedAt', 'DESC']],
|
236
|
+
include: [
|
237
|
+
{
|
238
|
+
model: SystemModel,
|
239
|
+
attributes: ['Name', 'SystemCode'],
|
240
|
+
},
|
241
|
+
{
|
242
|
+
model: UserModel,
|
243
|
+
as: 'User',
|
244
|
+
attributes: ['UserId', 'FullName'],
|
245
|
+
},
|
246
|
+
],
|
247
|
+
};
|
248
|
+
}
|
249
|
+
|
250
|
+
const userSystemAccesses =
|
251
|
+
await this._Repository.findAndCountAll(options);
|
252
|
+
return userSystemAccesses;
|
253
|
+
} catch (error) {
|
254
|
+
throw error;
|
255
|
+
}
|
256
|
+
}
|
257
|
+
|
258
|
+
public static async findAllUserPrivileges(
|
259
|
+
loginUser: User, //The currently logged-in user initiating the request.
|
260
|
+
dbTransaction: any, //The active database transaction to ensure consistency during the query.
|
261
|
+
SystemCode: string,
|
262
|
+
search?: {
|
263
|
+
UserId?: string[];
|
264
|
+
Status?: string;
|
265
|
+
},
|
266
|
+
) {
|
267
|
+
// Part 1: Privilege Checking
|
268
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
269
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
270
|
+
systemCode,
|
271
|
+
'USER_SYSTEM_ACCESS_LIST',
|
272
|
+
);
|
273
|
+
|
274
|
+
if (!isPrivileged) {
|
275
|
+
throw new ClassError(
|
276
|
+
'UserSystemAccessUser',
|
277
|
+
'UserSystemAccessUserErrMsg01',
|
278
|
+
'You do not have permission to view system access users.',
|
279
|
+
);
|
280
|
+
}
|
281
|
+
|
282
|
+
try {
|
283
|
+
//Part 2: Retrieve User System Access Based on Privileges
|
284
|
+
let systemWhere: any = {};
|
285
|
+
|
286
|
+
if (SystemCode) {
|
287
|
+
systemWhere = {
|
288
|
+
SystemCode: {
|
289
|
+
[Op.substring]: SystemCode,
|
290
|
+
},
|
291
|
+
};
|
292
|
+
}
|
293
|
+
|
294
|
+
const allSystemAccessUsers = await UserSystemAccessModel.findAll({
|
295
|
+
include: [
|
296
|
+
{
|
297
|
+
model: SystemModel,
|
298
|
+
where: systemWhere,
|
299
|
+
},
|
300
|
+
{
|
301
|
+
model: UserModel,
|
302
|
+
as: 'User',
|
303
|
+
attributes: ['UserId', 'FullName'],
|
304
|
+
},
|
305
|
+
],
|
306
|
+
transaction: dbTransaction,
|
307
|
+
});
|
308
|
+
|
309
|
+
const allPrivileges = await SystemPrivilegeModel.findAll({
|
310
|
+
where: systemWhere,
|
311
|
+
transaction: dbTransaction,
|
312
|
+
});
|
313
|
+
|
314
|
+
const systemAccessUserPrivileges = allPrivileges.map((privilege) => {
|
315
|
+
const filteredUsers = allSystemAccessUsers
|
316
|
+
.map((userAccess) => userAccess.User)
|
317
|
+
.filter((user) => search.UserId.includes(String(user.UserId)));
|
318
|
+
|
319
|
+
return {
|
320
|
+
...privilege.get({ plain: true }),
|
321
|
+
Users: filteredUsers,
|
322
|
+
};
|
323
|
+
});
|
324
|
+
|
325
|
+
return systemAccessUserPrivileges;
|
326
|
+
} catch (error) {
|
327
|
+
throw error;
|
328
|
+
}
|
329
|
+
}
|
330
|
+
|
331
|
+
public static async findAllUserRoles(
|
332
|
+
loginUser: User, //The currently logged-in user initiating the request.
|
333
|
+
dbTransaction: any, //The active database transaction to ensure consistency during the query.
|
334
|
+
SystemCode: string,
|
335
|
+
search?: {
|
336
|
+
UserId?: string[];
|
337
|
+
Status?: string;
|
338
|
+
},
|
339
|
+
) {
|
340
|
+
// Part 1: Privilege Checking
|
341
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
342
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
343
|
+
systemCode,
|
344
|
+
'USER_SYSTEM_ACCESS_LIST',
|
345
|
+
);
|
346
|
+
|
347
|
+
if (!isPrivileged) {
|
348
|
+
throw new ClassError(
|
349
|
+
'UserSystemAccessUser',
|
350
|
+
'UserSystemAccessUserErrMsg01',
|
351
|
+
'You do not have permission to view system access users.',
|
352
|
+
);
|
353
|
+
}
|
354
|
+
|
355
|
+
try {
|
356
|
+
//Part 2: Retrieve User System Access Based on Privileges
|
357
|
+
let systemWhere: any = {};
|
358
|
+
|
359
|
+
if (SystemCode) {
|
360
|
+
systemWhere = {
|
361
|
+
SystemCode: {
|
362
|
+
[Op.substring]: SystemCode,
|
363
|
+
},
|
364
|
+
};
|
365
|
+
}
|
366
|
+
|
367
|
+
const allGroupSystemAccess = await GroupSystemAccessModel.findAll({
|
368
|
+
where: systemWhere,
|
369
|
+
include: [
|
370
|
+
{
|
371
|
+
model: GroupModel,
|
372
|
+
where: {
|
373
|
+
Type: 'Role',
|
374
|
+
},
|
375
|
+
},
|
376
|
+
],
|
377
|
+
transaction: dbTransaction,
|
378
|
+
});
|
379
|
+
|
380
|
+
const allSystemAccessUsers = await UserSystemAccessModel.findAll({
|
381
|
+
include: [
|
382
|
+
{
|
383
|
+
model: SystemModel,
|
384
|
+
where: systemWhere,
|
385
|
+
},
|
386
|
+
{
|
387
|
+
model: UserModel,
|
388
|
+
as: 'User',
|
389
|
+
attributes: ['UserId', 'FullName'],
|
390
|
+
},
|
391
|
+
],
|
392
|
+
transaction: dbTransaction,
|
393
|
+
});
|
394
|
+
|
395
|
+
const systemAccessUserRoles = allGroupSystemAccess.map(
|
396
|
+
(groupSystemAccess) => {
|
397
|
+
const filteredUsers = allSystemAccessUsers
|
398
|
+
.map((userAccess) => userAccess.User)
|
399
|
+
.filter((user) => search.UserId.includes(String(user.UserId)));
|
400
|
+
|
401
|
+
return {
|
402
|
+
...groupSystemAccess.Group.get({ plain: true }),
|
403
|
+
Users: filteredUsers,
|
404
|
+
};
|
405
|
+
},
|
406
|
+
);
|
407
|
+
|
408
|
+
return systemAccessUserRoles;
|
409
|
+
} catch (error) {
|
410
|
+
throw error;
|
411
|
+
}
|
412
|
+
}
|
413
|
+
|
185
414
|
public static async createAccess(
|
186
415
|
loginUser: User, //The currently logged-in user initiating the request.
|
187
416
|
dbTransaction: any, //The active database transaction to ensure consistency during the query.
|