@tomei/sso 0.31.4 → 0.31.5
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -290,4 +290,158 @@ export class Group extends ObjectBase {
|
|
290
290
|
throw error;
|
291
291
|
}
|
292
292
|
}
|
293
|
+
|
294
|
+
protected static async checkDuplicateGroupCode(
|
295
|
+
dbTransaction: any,
|
296
|
+
GroupCode,
|
297
|
+
) {
|
298
|
+
const isGroupCodeExist = await Group._Repo.findOne({
|
299
|
+
where: { GroupCode },
|
300
|
+
transaction: dbTransaction,
|
301
|
+
});
|
302
|
+
|
303
|
+
if (isGroupCodeExist) {
|
304
|
+
throw new ClassError(
|
305
|
+
'Group',
|
306
|
+
'GroupErrMsg07',
|
307
|
+
'GroupCode already exists.',
|
308
|
+
);
|
309
|
+
}
|
310
|
+
}
|
311
|
+
|
312
|
+
public async update(
|
313
|
+
loginUser: LoginUser,
|
314
|
+
dbTransaction: any,
|
315
|
+
group: {
|
316
|
+
GroupCode: string;
|
317
|
+
NewGroupCode?: string;
|
318
|
+
Name?: string;
|
319
|
+
Description?: string;
|
320
|
+
Type?: GroupTypeEnum;
|
321
|
+
ParentGroupCode?: string;
|
322
|
+
InheritParentPrivilegeYN?: string;
|
323
|
+
InheritParentSystemAccessYN?: string;
|
324
|
+
Status?: string;
|
325
|
+
},
|
326
|
+
) {
|
327
|
+
//Part 1: Privilege Checking
|
328
|
+
const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
|
329
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
330
|
+
systemCode,
|
331
|
+
'GROUP_UPDATE',
|
332
|
+
);
|
333
|
+
|
334
|
+
//If user does not have privilege to update user, throw a ClassError
|
335
|
+
if (!isPrivileged) {
|
336
|
+
throw new ClassError(
|
337
|
+
'Group',
|
338
|
+
'GroupErrMsg06',
|
339
|
+
'You do not have the privilege to update Group',
|
340
|
+
);
|
341
|
+
}
|
342
|
+
try {
|
343
|
+
const currentGroup = await Group.init(dbTransaction, group.GroupCode);
|
344
|
+
if (group.NewGroupCode) {
|
345
|
+
await Group.checkDuplicateGroupCode(dbTransaction, group.NewGroupCode);
|
346
|
+
}
|
347
|
+
|
348
|
+
if (
|
349
|
+
group.ParentGroupCode &&
|
350
|
+
currentGroup.ParentGroupCode !== group.ParentGroupCode
|
351
|
+
) {
|
352
|
+
const parentGroup = await Group.init(
|
353
|
+
dbTransaction,
|
354
|
+
group.ParentGroupCode,
|
355
|
+
);
|
356
|
+
if (!parentGroup) {
|
357
|
+
throw new ClassError(
|
358
|
+
'Group',
|
359
|
+
'GroupErrMsg08',
|
360
|
+
'Parent Group Code not found',
|
361
|
+
);
|
362
|
+
}
|
363
|
+
}
|
364
|
+
|
365
|
+
const entityValueBefore = {
|
366
|
+
GroupCode: currentGroup.GroupCode,
|
367
|
+
Name: currentGroup.Name,
|
368
|
+
Type: currentGroup.Type,
|
369
|
+
Description: currentGroup.Description,
|
370
|
+
ParentGroupCode: currentGroup.ParentGroupCode,
|
371
|
+
InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
|
372
|
+
InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
|
373
|
+
Status: currentGroup.Status,
|
374
|
+
CreatedById: currentGroup._CreatedById,
|
375
|
+
UpdatedById: currentGroup._UpdatedById,
|
376
|
+
CreatedAt: currentGroup._CreatedAt,
|
377
|
+
UpdatedAt: currentGroup._UpdatedAt,
|
378
|
+
};
|
379
|
+
|
380
|
+
currentGroup.GroupCode = group?.NewGroupCode || currentGroup.GroupCode;
|
381
|
+
currentGroup.Name = group?.Name || currentGroup.Name;
|
382
|
+
currentGroup.Type = group?.Type || currentGroup.Type;
|
383
|
+
currentGroup.Description = group?.Description || currentGroup.Description;
|
384
|
+
currentGroup.ParentGroupCode =
|
385
|
+
group?.ParentGroupCode || currentGroup.ParentGroupCode;
|
386
|
+
currentGroup.InheritParentPrivilegeYN =
|
387
|
+
group?.InheritParentPrivilegeYN ||
|
388
|
+
currentGroup.InheritParentPrivilegeYN;
|
389
|
+
currentGroup.InheritParentSystemAccessYN =
|
390
|
+
group?.InheritParentSystemAccessYN ||
|
391
|
+
currentGroup.InheritParentSystemAccessYN;
|
392
|
+
currentGroup.Status = group?.Status || currentGroup.Status;
|
393
|
+
currentGroup._UpdatedById = loginUser.UserId;
|
394
|
+
currentGroup._UpdatedAt = new Date();
|
395
|
+
|
396
|
+
await Group._Repo.update(
|
397
|
+
{
|
398
|
+
GroupCode: currentGroup.GroupCode,
|
399
|
+
Name: currentGroup.Name,
|
400
|
+
Type: currentGroup.Type,
|
401
|
+
Description: currentGroup.Description,
|
402
|
+
ParentGroupCode: currentGroup.ParentGroupCode,
|
403
|
+
InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
|
404
|
+
InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
|
405
|
+
Status: currentGroup.Status,
|
406
|
+
UpdatedById: currentGroup._UpdatedById,
|
407
|
+
UpdatedAt: currentGroup._UpdatedAt,
|
408
|
+
},
|
409
|
+
{
|
410
|
+
where: {
|
411
|
+
GroupCode: group.GroupCode,
|
412
|
+
},
|
413
|
+
transaction: dbTransaction,
|
414
|
+
},
|
415
|
+
);
|
416
|
+
|
417
|
+
const entityValueAfter = {
|
418
|
+
GroupCode: currentGroup.GroupCode,
|
419
|
+
Name: currentGroup.Name,
|
420
|
+
Type: currentGroup.Type,
|
421
|
+
Description: currentGroup.Description,
|
422
|
+
ParentGroupCode: currentGroup.ParentGroupCode,
|
423
|
+
InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
|
424
|
+
InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
|
425
|
+
Status: currentGroup.Status,
|
426
|
+
CreatedById: currentGroup._CreatedById,
|
427
|
+
UpdatedById: currentGroup._UpdatedById,
|
428
|
+
CreatedAt: currentGroup._CreatedAt,
|
429
|
+
UpdatedAt: currentGroup._UpdatedAt,
|
430
|
+
};
|
431
|
+
|
432
|
+
const activity = new Activity();
|
433
|
+
activity.ActivityId = activity.createId();
|
434
|
+
activity.Action = ActionEnum.UPDATE;
|
435
|
+
activity.Description = `Update Group ${group.Type}`;
|
436
|
+
activity.EntityType = 'Group';
|
437
|
+
activity.EntityId = group.GroupCode;
|
438
|
+
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
439
|
+
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
440
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
441
|
+
|
442
|
+
return currentGroup;
|
443
|
+
} catch (error) {
|
444
|
+
throw error;
|
445
|
+
}
|
446
|
+
}
|
293
447
|
}
|