@tomei/sso 0.49.0 → 0.50.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/src/components/login-user/user.d.ts +1 -1
- package/dist/src/components/login-user/user.js +3 -3
- package/dist/src/components/login-user/user.js.map +1 -1
- package/dist/src/components/system-privilege/system-privilege.d.ts +1 -0
- package/dist/src/components/system-privilege/system-privilege.js +41 -1
- package/dist/src/components/system-privilege/system-privilege.js.map +1 -1
- package/dist/src/components/system-privilege/system-privilege.repository.d.ts +1 -0
- package/dist/src/components/system-privilege/system-privilege.repository.js +17 -0
- package/dist/src/components/system-privilege/system-privilege.repository.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/login-user/user.ts +4 -4
- package/src/components/system-privilege/system-privilege.repository.ts +7 -0
- package/src/components/system-privilege/system-privilege.ts +71 -1
package/package.json
CHANGED
@@ -1285,8 +1285,8 @@ export class User extends UserBase {
|
|
1285
1285
|
|
1286
1286
|
// Save the hashed token to Redis
|
1287
1287
|
this._SessionService.setAuthorizationCode(
|
1288
|
-
this.ObjectId,
|
1289
1288
|
hashedToken,
|
1289
|
+
this.ObjectId,
|
1290
1290
|
60 * 60 * 24,
|
1291
1291
|
); // 24 hours
|
1292
1292
|
|
@@ -1296,7 +1296,7 @@ export class User extends UserBase {
|
|
1296
1296
|
|
1297
1297
|
public async validateAuthorizationToken(
|
1298
1298
|
autorizationToken: string,
|
1299
|
-
): Promise<
|
1299
|
+
): Promise<string> {
|
1300
1300
|
try {
|
1301
1301
|
const hashedSubmittedToken = createHash('sha256')
|
1302
1302
|
.update(autorizationToken)
|
@@ -1307,11 +1307,11 @@ export class User extends UserBase {
|
|
1307
1307
|
hashedSubmittedToken,
|
1308
1308
|
);
|
1309
1309
|
if (!userId) {
|
1310
|
-
return
|
1310
|
+
return null;
|
1311
1311
|
}
|
1312
1312
|
|
1313
1313
|
await this._SessionService.deleteAuthorizationCode(hashedSubmittedToken);
|
1314
|
-
return
|
1314
|
+
return userId;
|
1315
1315
|
} catch (error) {
|
1316
1316
|
throw error;
|
1317
1317
|
}
|
@@ -8,4 +8,11 @@ export class SystemPrivilegeRepository
|
|
8
8
|
constructor() {
|
9
9
|
super(SystemPrivilege);
|
10
10
|
}
|
11
|
+
|
12
|
+
async delete(systemPrivilegeId: string, dbTransaction?: any) {
|
13
|
+
return await SystemPrivilege.destroy({
|
14
|
+
where: { SystemPrivilegeId: systemPrivilegeId },
|
15
|
+
transaction: dbTransaction,
|
16
|
+
});
|
17
|
+
}
|
11
18
|
}
|
@@ -213,7 +213,7 @@ export class SystemPrivilege extends ObjectBase {
|
|
213
213
|
activity.Action = ActionEnum.CREATE;
|
214
214
|
activity.Description = 'Add System Privilege';
|
215
215
|
activity.EntityType = 'SystemPrivilege';
|
216
|
-
activity.EntityId = newSystemPrivilege.
|
216
|
+
activity.EntityId = newSystemPrivilege.SystemPrivilegeId;
|
217
217
|
activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
|
218
218
|
activity.EntityValueAfter = JSON.stringify(EntityValueAfter);
|
219
219
|
|
@@ -378,4 +378,74 @@ export class SystemPrivilege extends ObjectBase {
|
|
378
378
|
throw error;
|
379
379
|
}
|
380
380
|
}
|
381
|
+
|
382
|
+
public async delete(dbTransaction: any, loginUser: LoginUser) {
|
383
|
+
try {
|
384
|
+
//Part 1: Privilege Checking
|
385
|
+
const systemCode: string =
|
386
|
+
ApplicationConfig.getComponentConfigValue('system-code');
|
387
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
388
|
+
systemCode,
|
389
|
+
'PRIVILEGE_DELETE',
|
390
|
+
);
|
391
|
+
if (!isPrivileged) {
|
392
|
+
throw new ClassError(
|
393
|
+
'SystemPrivilege',
|
394
|
+
'SystemPrivilegeErrMsg0X',
|
395
|
+
'You do not have permission to delete system privileges',
|
396
|
+
);
|
397
|
+
}
|
398
|
+
|
399
|
+
//Part 2: Validation
|
400
|
+
//Make sure SystemPrivilegeId is not empty
|
401
|
+
if (!this.SystemPrivilegeId) {
|
402
|
+
throw new ClassError(
|
403
|
+
'SystemPrivilege',
|
404
|
+
'SystemPrivilegeErrMsg02',
|
405
|
+
'System Privilege Id is required',
|
406
|
+
);
|
407
|
+
}
|
408
|
+
|
409
|
+
//Part 3: Delete Privilege
|
410
|
+
|
411
|
+
//Call SystemPrivilege._Repo delete method
|
412
|
+
await SystemPrivilege._Repository.delete(
|
413
|
+
this.SystemPrivilegeId,
|
414
|
+
dbTransaction,
|
415
|
+
);
|
416
|
+
|
417
|
+
//Part 4: Record Create Privilege Activity
|
418
|
+
//Initialise EntityValueBefore variable and set to empty object.
|
419
|
+
const EntityValueBefore = {
|
420
|
+
SystemPrivilegeId: this.ObjectId,
|
421
|
+
PrivilegeCode: this.PrivilegeCode,
|
422
|
+
SystemCode: this.SystemCode,
|
423
|
+
Description: this.Description,
|
424
|
+
Status: this.Status,
|
425
|
+
CreatedById: this._CreatedById,
|
426
|
+
UpdatedById: this._UpdatedById,
|
427
|
+
CreatedAt: this._CreatedAt,
|
428
|
+
UpdatedAt: this._UpdatedAt,
|
429
|
+
};
|
430
|
+
//Initialise EntityValueAfter variable and set to newSystemPrivilege object.
|
431
|
+
const EntityValueAfter = {};
|
432
|
+
|
433
|
+
//Instantiate new activity object and populate
|
434
|
+
const activity = new Activity();
|
435
|
+
activity.ActivityId = activity.createId();
|
436
|
+
activity.Action = ActionEnum.DELETE;
|
437
|
+
activity.Description = 'Delete System Privilege';
|
438
|
+
activity.EntityType = 'SystemPrivilege';
|
439
|
+
activity.EntityId = this.SystemPrivilegeId;
|
440
|
+
activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
|
441
|
+
activity.EntityValueAfter = JSON.stringify(EntityValueAfter);
|
442
|
+
|
443
|
+
//Call Activity.create method
|
444
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
445
|
+
|
446
|
+
return this;
|
447
|
+
} catch (error) {
|
448
|
+
throw error;
|
449
|
+
}
|
450
|
+
}
|
381
451
|
}
|