@tomei/sso 0.8.4 → 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/sso",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -100,12 +100,12 @@ export class LoginUser extends ObjectBase implements IPerson {
100
100
  {
101
101
  model: Staff,
102
102
  },
103
- {
104
- model: SystemPrivilege,
105
- Include: {
106
- model: SystemPrivilege,
107
- },
108
- },
103
+ // {
104
+ // model: SystemPrivilege,
105
+ // Include: {
106
+ // model: SystemPrivilege,
107
+ // },
108
+ // },
109
109
  ],
110
110
  });
111
111
 
@@ -216,15 +216,19 @@ export class LoginUser extends ObjectBase implements IPerson {
216
216
  userId: string,
217
217
  systemId: number,
218
218
  ): Promise<void> {
219
- const systemAccess = await LoginUser._SystemAccessRepository.findOne({
220
- where: {
221
- userId: userId,
222
- systemId: systemId,
223
- },
224
- });
225
-
226
- if (!systemAccess) {
227
- throw new Error("User don't have access to the system.");
219
+ try {
220
+ const systemAccess = await LoginUser._SystemAccessRepository.findOne({
221
+ where: {
222
+ UserId: userId,
223
+ SystemId: systemId,
224
+ },
225
+ });
226
+
227
+ if (!systemAccess) {
228
+ throw new Error("User don't have access to the system.");
229
+ }
230
+ } catch (error) {
231
+ throw error;
228
232
  }
229
233
  }
230
234
 
@@ -287,7 +291,7 @@ export class LoginUser extends ObjectBase implements IPerson {
287
291
  try {
288
292
  const system = await LoginUser._SystemRepository.findOne({
289
293
  where: {
290
- code: systemCode,
294
+ Code: systemCode,
291
295
  },
292
296
  });
293
297
 
@@ -352,17 +356,17 @@ export class LoginUser extends ObjectBase implements IPerson {
352
356
  // Add privileges from the userGroup to the privileges array
353
357
  privileges = [
354
358
  ...privileges,
355
- ...userGroup.groupSystemPrivileges.map((g) => g.systemPrivilege.code),
356
- ...userGroup.groupRolePrivileges.map((g) => g.systemPrivilege.code),
359
+ ...userGroup.GroupSystemPrivileges.map((g) => g.SystemPrivilege.Code),
360
+ ...userGroup.GroupRolePrivileges.map((g) => g.SystemPrivilege.Code),
357
361
  ];
358
362
 
359
363
  // Recursive call if conditions are not met and ParentGroupCode exists
360
364
  const isContinue =
361
- userGroup.groupLevel !== 0 &&
362
- userGroup.allowInheritFromParentYN === 'Y';
365
+ userGroup.GroupLevel !== 0 &&
366
+ userGroup.AllowInheritFromParentYN === 'Y';
363
367
  if (isContinue) {
364
368
  const recursivePrivileges = await this.getPrivilegesFromUserGroup(
365
- userGroup.parentGroupCode,
369
+ userGroup.ParentGroupCode,
366
370
  );
367
371
  privileges = privileges.concat(recursivePrivileges);
368
372
  }
@@ -378,7 +382,7 @@ export class LoginUser extends ObjectBase implements IPerson {
378
382
  try {
379
383
  const userGroup = await LoginUser._UserGroupRepository.findOne({
380
384
  where: {
381
- groupCode: groupCode,
385
+ GroupCode: groupCode,
382
386
  },
383
387
  include: [
384
388
  {
@@ -405,8 +409,8 @@ export class LoginUser extends ObjectBase implements IPerson {
405
409
  try {
406
410
  return await LoginUser._UserUserGroupRepository.findAll({
407
411
  where: {
408
- userId: this.ObjectId,
409
- systemId: systemCode,
412
+ UserId: this.ObjectId,
413
+ SystemId: systemCode,
410
414
  },
411
415
  include: {
412
416
  model: UserGroup,
@@ -463,25 +467,29 @@ export class LoginUser extends ObjectBase implements IPerson {
463
467
  systemCode: string,
464
468
  privilegeName: string,
465
469
  ): Promise<boolean> {
466
- if (!this.ObjectId) {
467
- throw new Error('ObjectId(UserId) is not set');
468
- }
470
+ try {
471
+ if (!this.ObjectId) {
472
+ throw new Error('ObjectId(UserId) is not set');
473
+ }
469
474
 
470
- const userSession = await this._SessionService.retrieveUserSession(
471
- this.ObjectId,
472
- );
475
+ const userSession = await this._SessionService.retrieveUserSession(
476
+ this.ObjectId,
477
+ );
473
478
 
474
- const systemLogin = userSession.systemLogins.find(
475
- (system) => system.code === systemCode,
476
- );
479
+ const systemLogin = userSession.systemLogins.find(
480
+ (system) => system.code === systemCode,
481
+ );
477
482
 
478
- if (!systemLogin) {
479
- return false;
480
- }
483
+ if (!systemLogin) {
484
+ return false;
485
+ }
481
486
 
482
- const privileges = systemLogin.privileges;
483
- const hasPrivilege = privileges.includes(privilegeName);
484
- return hasPrivilege;
487
+ const privileges = systemLogin.privileges;
488
+ const hasPrivilege = privileges.includes(privilegeName);
489
+ return hasPrivilege;
490
+ } catch (error) {
491
+ throw error;
492
+ }
485
493
  }
486
494
 
487
495
  async checkSession(
@@ -36,7 +36,7 @@ export default class UserGroup extends Model {
36
36
  @ForeignKey(() => Department)
37
37
  @Column({
38
38
  type: DataType.STRING,
39
- field: 'password',
39
+ field: 'DepartmentId',
40
40
  })
41
41
  DepartmentId: string;
42
42
 
@@ -8,6 +8,7 @@ import {
8
8
  UpdatedAt,
9
9
  } from 'sequelize-typescript';
10
10
  import User from './user.entity';
11
+ import Role from './role.entity';
11
12
 
12
13
  @Table({
13
14
  tableName: 'sso_user_roles',
@@ -17,6 +18,7 @@ import User from './user.entity';
17
18
  underscored: true,
18
19
  })
19
20
  export default class UserRole extends Model {
21
+ @ForeignKey(() => User)
20
22
  @Column({
21
23
  primaryKey: true,
22
24
  type: DataType.INTEGER,
@@ -25,6 +27,7 @@ export default class UserRole extends Model {
25
27
  })
26
28
  UserId: number;
27
29
 
30
+ @ForeignKey(() => Role)
28
31
  @Column({
29
32
  primaryKey: true,
30
33
  type: DataType.INTEGER,
@@ -47,4 +50,10 @@ export default class UserRole extends Model {
47
50
 
48
51
  @BelongsTo(() => User)
49
52
  User: User;
53
+
54
+ @BelongsTo(() => Role)
55
+ Role: Role;
56
+
57
+ @BelongsTo(() => User, 'updated_by_id')
58
+ UpdatedBy: User;
50
59
  }
@@ -24,6 +24,7 @@ export default class UserSystemPrivileges extends Model {
24
24
  primaryKey: true,
25
25
  allowNull: false,
26
26
  type: DataType.INTEGER,
27
+ field: 'UserId',
27
28
  })
28
29
  UserId: number;
29
30