rez_core 2.1.11 → 2.1.12

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": "rez_core",
3
- "version": "2.1.11",
3
+ "version": "2.1.12",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -93,4 +93,27 @@ export class ModuleAccessController {
93
93
  roles.map((id) => Number(id)),
94
94
  );
95
95
  }
96
+
97
+ @Get('user-permissions')
98
+ async getUserPermissions(@Request() req) {
99
+ const userData = req.user.userData;
100
+
101
+ const userId = userData?.id;
102
+ const appcode = userData?.appcode;
103
+ const level_type = userData?.level_type;
104
+ const level_id = userData?.level_id;
105
+
106
+ if (!userId || !appcode || !level_type || !level_id) {
107
+ throw new BadRequestException('Invalid token data');
108
+ }
109
+
110
+ return this.moduleAccessService.getUserPermissions({
111
+ userId,
112
+ appcode,
113
+ level_type,
114
+ level_id,
115
+ });
116
+ }
117
+
118
+
96
119
  }
@@ -284,4 +284,34 @@ export class ModuleAccessRepository {
284
284
  action: uniqueActions,
285
285
  };
286
286
  }
287
+ async getModuleAccessByRoles(roleIds: number[], appcode: string) {
288
+ // Step 1: Get role codes from cr_role
289
+ const roles = await this.roleRepo.find({
290
+ where: {
291
+ id: In(roleIds),
292
+ appcode,
293
+ },
294
+ select: ['id', 'code'], // fetch only needed fields
295
+ });
296
+
297
+ const roleCodes = roles.map((r) => r.code);
298
+
299
+ if (!roleCodes.length) return [];
300
+
301
+ // Step 2: Use role codes to fetch access entries
302
+ return this.moduleAccessRepo
303
+ .createQueryBuilder('access')
304
+ .select([
305
+ 'access.module_code',
306
+ 'access.action_type',
307
+ 'access.access_flag',
308
+ 'access.role_code',
309
+ ])
310
+ .where('access.role_code IN (:...roleCodes)', { roleCodes })
311
+ .andWhere('access.appcode = :appcode', { appcode })
312
+ .getRawMany();
313
+ }
314
+
315
+
287
316
  }
317
+
@@ -117,7 +117,32 @@ export class ModuleAccessService {
117
117
  async getModuleUIConfig(moduleCode: string, roleIds: number[]) {
118
118
  return this.moduleAccessRepository.getModuleUIConfig(moduleCode, roleIds);
119
119
  }
120
- }
121
-
122
120
 
123
- //hi
121
+ async getUserPermissions({
122
+ userId,
123
+ appcode,
124
+ level_type,
125
+ level_id,
126
+ }: {
127
+ userId: number;
128
+ appcode: string;
129
+ level_type: string;
130
+ level_id: number;
131
+ }) {
132
+ const roleCodes = await this.menuRepository.resolveUserRoles(
133
+ userId,
134
+ appcode,
135
+ level_type,
136
+ level_id,
137
+ );
138
+
139
+ if (!roleCodes || roleCodes.length === 0) {
140
+ return [];
141
+ }
142
+
143
+ const roleIds = roleCodes.map(Number);
144
+ return this.moduleAccessRepository.getModuleAccessByRoles(roleIds, appcode);
145
+ }
146
+
147
+
148
+ }