@tomei/sso 0.50.6 → 0.50.8

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/sso",
3
- "version": "0.50.6",
3
+ "version": "0.50.8",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -776,7 +776,7 @@ export class User extends UserBase {
776
776
  }
777
777
  }
778
778
 
779
- private async getPrivileges(
779
+ public async getPrivileges(
780
780
  systemCode: string,
781
781
  dbTransaction?: any,
782
782
  ): Promise<string[]> {
@@ -8,6 +8,7 @@ import { ActionEnum, Activity } from '@tomei/activity-history';
8
8
  import GroupSystemAccessModel from '../../models/group-system-access.entity';
9
9
  import GroupModel from '../../models/group.entity';
10
10
  import SystemModel from '../../models/system.entity';
11
+ import UserModel from '../../models/user.entity';
11
12
  import { Transaction } from 'sequelize';
12
13
 
13
14
  export class UserGroup extends ObjectBase {
@@ -301,6 +302,59 @@ export class UserGroup extends ObjectBase {
301
302
  }
302
303
  }
303
304
 
305
+ public static async getUser(
306
+ dbTransaction: any,
307
+ loginUser: LoginUser,
308
+ GroupCode: string,
309
+ ) {
310
+ try {
311
+ // Part 1: Privilege Checking
312
+ // Call loginUser.checkPrivileges() by passing:
313
+ // SystemCode: "<get_from_app_config>"
314
+ // PrivilegeCode: "USER_GROUP_VIEW"
315
+ const systemCode =
316
+ ApplicationConfig.getComponentConfigValue('system-code');
317
+ const isPrivileged = await loginUser.checkPrivileges(
318
+ systemCode,
319
+ 'USER_GROUP_VIEW',
320
+ );
321
+
322
+ // If user does not have privilege to view user group, throw a ClassError
323
+ if (!isPrivileged) {
324
+ throw new ClassError(
325
+ 'UserGroup',
326
+ 'UserGroupErrMsg0X',
327
+ 'User does not have privilege to view user group.',
328
+ );
329
+ }
330
+
331
+ // Part 2: Retrieve Record
332
+ // Call UserGroup._Repo findAll method by passing:
333
+ // where:
334
+ // GroupCode: Params.GroupCode
335
+ // dbTransaction
336
+ const userGroup = await UserGroup._Repository.findAll({
337
+ where: {
338
+ GroupCode,
339
+ },
340
+ include: [
341
+ {
342
+ model: UserModel,
343
+ as: 'User',
344
+ attributes: ['UserId', 'FullName', 'Email'],
345
+ },
346
+ ],
347
+ transaction: dbTransaction,
348
+ });
349
+ // If record exists, instantiate UserGroup by calling the private constructor and passing the attributes. Then, returns the instance
350
+ return userGroup;
351
+ // If record not exists, return null.
352
+ return null;
353
+ } catch (error) {
354
+ throw error;
355
+ }
356
+ }
357
+
304
358
  static async findAllInheritedSystemAccesses(
305
359
  UserId: number,
306
360
  loginUser: User,