@tomei/sso 0.31.4 → 0.31.6
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/src/components/group/group.d.ts +17 -0
- package/dist/src/components/group/group.js +144 -0
- package/dist/src/components/group/group.js.map +1 -1
- package/dist/src/components/group-system-access/group-system-access.repository.d.ts +1 -0
- package/dist/src/components/group-system-access/group-system-access.repository.js +26 -0
- package/dist/src/components/group-system-access/group-system-access.repository.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/group/group.ts +221 -0
- package/src/components/group-system-access/group-system-access.repository.ts +18 -0
- package/dist/__tests__/unit/components/login-user/login-user.spec.d.ts +0 -0
- package/dist/__tests__/unit/components/login-user/login-user.spec.js +0 -1
- package/dist/__tests__/unit/components/login-user/login-user.spec.js.map +0 -1
package/package.json
CHANGED
@@ -7,6 +7,7 @@ import { IGroupSearchAttr } from '../../interfaces/group-search-attr.interface';
|
|
7
7
|
import { ApplicationConfig } from '@tomei/config';
|
8
8
|
import { Op } from 'sequelize';
|
9
9
|
import { ActionEnum, Activity } from '@tomei/activity-history';
|
10
|
+
import { GroupSystemAccessRepository } from '../group-system-access/group-system-access.repository';
|
10
11
|
|
11
12
|
export class Group extends ObjectBase {
|
12
13
|
ObjectId: string;
|
@@ -27,6 +28,7 @@ export class Group extends ObjectBase {
|
|
27
28
|
private _UpdatedById: number;
|
28
29
|
private _UpdatedAt: Date;
|
29
30
|
private static _Repo = new GroupRepository();
|
31
|
+
private static _SystemAccessRepo = new GroupSystemAccessRepository();
|
30
32
|
|
31
33
|
get GroupCode(): string {
|
32
34
|
return this.ObjectId;
|
@@ -290,4 +292,223 @@ export class Group extends ObjectBase {
|
|
290
292
|
throw error;
|
291
293
|
}
|
292
294
|
}
|
295
|
+
|
296
|
+
protected static async checkDuplicateGroupCode(
|
297
|
+
dbTransaction: any,
|
298
|
+
GroupCode,
|
299
|
+
) {
|
300
|
+
const isGroupCodeExist = await Group._Repo.findOne({
|
301
|
+
where: { GroupCode },
|
302
|
+
transaction: dbTransaction,
|
303
|
+
});
|
304
|
+
|
305
|
+
if (isGroupCodeExist) {
|
306
|
+
throw new ClassError(
|
307
|
+
'Group',
|
308
|
+
'GroupErrMsg07',
|
309
|
+
'GroupCode already exists.',
|
310
|
+
);
|
311
|
+
}
|
312
|
+
}
|
313
|
+
|
314
|
+
public async update(
|
315
|
+
loginUser: LoginUser,
|
316
|
+
dbTransaction: any,
|
317
|
+
group: {
|
318
|
+
GroupCode: string;
|
319
|
+
NewGroupCode?: string;
|
320
|
+
Name?: string;
|
321
|
+
Description?: string;
|
322
|
+
Type?: GroupTypeEnum;
|
323
|
+
ParentGroupCode?: string;
|
324
|
+
InheritParentPrivilegeYN?: string;
|
325
|
+
InheritParentSystemAccessYN?: string;
|
326
|
+
Status?: string;
|
327
|
+
},
|
328
|
+
) {
|
329
|
+
//Part 1: Privilege Checking
|
330
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
331
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
332
|
+
systemCode,
|
333
|
+
'GROUP_UPDATE',
|
334
|
+
);
|
335
|
+
|
336
|
+
if (!isPrivileged) {
|
337
|
+
throw new ClassError(
|
338
|
+
'Group',
|
339
|
+
'GroupErrMsg06',
|
340
|
+
'You do not have the privilege to update Group',
|
341
|
+
);
|
342
|
+
}
|
343
|
+
try {
|
344
|
+
const currentGroup = await Group.init(dbTransaction, group.GroupCode);
|
345
|
+
if (group.NewGroupCode) {
|
346
|
+
await Group.checkDuplicateGroupCode(dbTransaction, group.NewGroupCode);
|
347
|
+
}
|
348
|
+
|
349
|
+
if (
|
350
|
+
group.ParentGroupCode &&
|
351
|
+
currentGroup.ParentGroupCode !== group.ParentGroupCode
|
352
|
+
) {
|
353
|
+
const parentGroup = await Group.init(
|
354
|
+
dbTransaction,
|
355
|
+
group.ParentGroupCode,
|
356
|
+
);
|
357
|
+
if (!parentGroup) {
|
358
|
+
throw new ClassError(
|
359
|
+
'Group',
|
360
|
+
'GroupErrMsg08',
|
361
|
+
'Parent Group Code not found',
|
362
|
+
);
|
363
|
+
}
|
364
|
+
}
|
365
|
+
|
366
|
+
const entityValueBefore = {
|
367
|
+
GroupCode: currentGroup.GroupCode,
|
368
|
+
Name: currentGroup.Name,
|
369
|
+
Type: currentGroup.Type,
|
370
|
+
Description: currentGroup.Description,
|
371
|
+
ParentGroupCode: currentGroup.ParentGroupCode,
|
372
|
+
InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
|
373
|
+
InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
|
374
|
+
Status: currentGroup.Status,
|
375
|
+
CreatedById: currentGroup._CreatedById,
|
376
|
+
UpdatedById: currentGroup._UpdatedById,
|
377
|
+
CreatedAt: currentGroup._CreatedAt,
|
378
|
+
UpdatedAt: currentGroup._UpdatedAt,
|
379
|
+
};
|
380
|
+
|
381
|
+
currentGroup.GroupCode = group?.NewGroupCode || currentGroup.GroupCode;
|
382
|
+
currentGroup.Name = group?.Name || currentGroup.Name;
|
383
|
+
currentGroup.Type = group?.Type || currentGroup.Type;
|
384
|
+
currentGroup.Description = group?.Description || currentGroup.Description;
|
385
|
+
currentGroup.ParentGroupCode =
|
386
|
+
group?.ParentGroupCode || currentGroup.ParentGroupCode;
|
387
|
+
currentGroup.InheritParentPrivilegeYN =
|
388
|
+
group?.InheritParentPrivilegeYN ||
|
389
|
+
currentGroup.InheritParentPrivilegeYN;
|
390
|
+
currentGroup.InheritParentSystemAccessYN =
|
391
|
+
group?.InheritParentSystemAccessYN ||
|
392
|
+
currentGroup.InheritParentSystemAccessYN;
|
393
|
+
currentGroup.Status = group?.Status || currentGroup.Status;
|
394
|
+
currentGroup._UpdatedById = loginUser.UserId;
|
395
|
+
currentGroup._UpdatedAt = new Date();
|
396
|
+
|
397
|
+
await Group._Repo.update(
|
398
|
+
{
|
399
|
+
GroupCode: currentGroup.GroupCode,
|
400
|
+
Name: currentGroup.Name,
|
401
|
+
Type: currentGroup.Type,
|
402
|
+
Description: currentGroup.Description,
|
403
|
+
ParentGroupCode: currentGroup.ParentGroupCode,
|
404
|
+
InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
|
405
|
+
InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
|
406
|
+
Status: currentGroup.Status,
|
407
|
+
UpdatedById: currentGroup._UpdatedById,
|
408
|
+
UpdatedAt: currentGroup._UpdatedAt,
|
409
|
+
},
|
410
|
+
{
|
411
|
+
where: {
|
412
|
+
GroupCode: group.GroupCode,
|
413
|
+
},
|
414
|
+
transaction: dbTransaction,
|
415
|
+
},
|
416
|
+
);
|
417
|
+
|
418
|
+
const entityValueAfter = {
|
419
|
+
GroupCode: currentGroup.GroupCode,
|
420
|
+
Name: currentGroup.Name,
|
421
|
+
Type: currentGroup.Type,
|
422
|
+
Description: currentGroup.Description,
|
423
|
+
ParentGroupCode: currentGroup.ParentGroupCode,
|
424
|
+
InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
|
425
|
+
InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
|
426
|
+
Status: currentGroup.Status,
|
427
|
+
CreatedById: currentGroup._CreatedById,
|
428
|
+
UpdatedById: currentGroup._UpdatedById,
|
429
|
+
CreatedAt: currentGroup._CreatedAt,
|
430
|
+
UpdatedAt: currentGroup._UpdatedAt,
|
431
|
+
};
|
432
|
+
|
433
|
+
const activity = new Activity();
|
434
|
+
activity.ActivityId = activity.createId();
|
435
|
+
activity.Action = ActionEnum.UPDATE;
|
436
|
+
activity.Description = `Update Group ${group.Type}`;
|
437
|
+
activity.EntityType = 'Group';
|
438
|
+
activity.EntityId = group.GroupCode;
|
439
|
+
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
440
|
+
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
441
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
442
|
+
|
443
|
+
return currentGroup;
|
444
|
+
} catch (error) {
|
445
|
+
throw error;
|
446
|
+
}
|
447
|
+
}
|
448
|
+
|
449
|
+
public static async getSystemAccesses(
|
450
|
+
loginUser: LoginUser,
|
451
|
+
dbTransaction: any,
|
452
|
+
GroupCode: string,
|
453
|
+
Page: number,
|
454
|
+
Rows: number,
|
455
|
+
Search: {
|
456
|
+
SystemCode?: string;
|
457
|
+
Status?: string;
|
458
|
+
},
|
459
|
+
) {
|
460
|
+
// Part 1: Privilege Checking
|
461
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
462
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
463
|
+
systemCode,
|
464
|
+
'SYSTEM_ACCESS_VIEW',
|
465
|
+
);
|
466
|
+
|
467
|
+
if (!isPrivileged) {
|
468
|
+
throw new ClassError(
|
469
|
+
'Group',
|
470
|
+
'GroupErrMsg06',
|
471
|
+
'You do not have the privilege to view system access',
|
472
|
+
);
|
473
|
+
}
|
474
|
+
|
475
|
+
try {
|
476
|
+
// Part 2: Validation
|
477
|
+
await Group.init(dbTransaction, GroupCode);
|
478
|
+
|
479
|
+
// Part 3: Retrieve System Access and returns
|
480
|
+
const queryObj: any = { GroupCode: GroupCode };
|
481
|
+
|
482
|
+
if (Search) {
|
483
|
+
Object.entries(Search).forEach(([key, value]) => {
|
484
|
+
queryObj[key] = {
|
485
|
+
[Op.eq]: value,
|
486
|
+
};
|
487
|
+
});
|
488
|
+
}
|
489
|
+
|
490
|
+
let options: any = {
|
491
|
+
where: queryObj,
|
492
|
+
distinct: true,
|
493
|
+
transaction: dbTransaction,
|
494
|
+
};
|
495
|
+
|
496
|
+
if (Page && Rows) {
|
497
|
+
options = {
|
498
|
+
...options,
|
499
|
+
limit: Rows,
|
500
|
+
offset: Rows * (Page - 1),
|
501
|
+
order: [
|
502
|
+
['CreatedAt', 'DESC'],
|
503
|
+
['Status', 'Active'],
|
504
|
+
],
|
505
|
+
};
|
506
|
+
}
|
507
|
+
|
508
|
+
const systemAccess = await Group._SystemAccessRepo.findAndCountAll();
|
509
|
+
return systemAccess;
|
510
|
+
} catch (error) {
|
511
|
+
return error;
|
512
|
+
}
|
513
|
+
}
|
293
514
|
}
|
@@ -8,4 +8,22 @@ export class GroupSystemAccessRepository
|
|
8
8
|
constructor() {
|
9
9
|
super(GroupSystemAccessModel);
|
10
10
|
}
|
11
|
+
|
12
|
+
async findAndCountAll(options?: any) {
|
13
|
+
try {
|
14
|
+
let GroupSystemAccess: any;
|
15
|
+
if (options) {
|
16
|
+
GroupSystemAccess = await GroupSystemAccessModel.findAndCountAll(
|
17
|
+
options,
|
18
|
+
);
|
19
|
+
} else {
|
20
|
+
GroupSystemAccess = await GroupSystemAccessModel.findAndCountAll();
|
21
|
+
}
|
22
|
+
return GroupSystemAccess;
|
23
|
+
} catch (error) {
|
24
|
+
throw new Error(
|
25
|
+
`An Error occured when retriving GroupSystemAccess: ${error.message}`,
|
26
|
+
);
|
27
|
+
}
|
28
|
+
}
|
11
29
|
}
|
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
//# sourceMappingURL=login-user.spec.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"login-user.spec.js","sourceRoot":"","sources":["../../../../../__tests__/unit/components/login-user/login-user.spec.ts"],"names":[],"mappings":""}
|