rez_core 2.1.24 → 2.1.25
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/dist/module/module/service/module-access.service.js +9 -1
- package/dist/module/module/service/module-access.service.js.map +1 -1
- package/dist/module/user/entity/user.entity.d.ts +2 -0
- package/dist/module/user/entity/user.entity.js +8 -0
- package/dist/module/user/entity/user.entity.js.map +1 -1
- package/dist/module/user/service/login.service.d.ts +2 -2
- package/dist/module/user/service/login.service.js +22 -10
- package/dist/module/user/service/login.service.js.map +1 -1
- package/dist/module/user/service/user-session.service.js +1 -1
- package/dist/module/user/service/user-session.service.js.map +1 -1
- package/dist/module/user/service/user.service.d.ts +1 -0
- package/dist/module/user/service/user.service.js +9 -0
- package/dist/module/user/service/user.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/module/service/module-access.service.ts +28 -1
- package/src/module/user/entity/user.entity.ts +6 -0
- package/src/module/user/service/login.service.ts +33 -17
- package/src/module/user/service/user-session.service.ts +2 -2
- package/src/module/user/service/user.service.ts +17 -0
package/package.json
CHANGED
|
@@ -129,6 +129,7 @@ export class ModuleAccessService {
|
|
|
129
129
|
level_type: string;
|
|
130
130
|
level_id: number;
|
|
131
131
|
}) {
|
|
132
|
+
// Step 1: Resolve roles
|
|
132
133
|
const roleCodes = await this.menuRepository.resolveUserRoles(
|
|
133
134
|
userId,
|
|
134
135
|
appcode,
|
|
@@ -141,8 +142,34 @@ export class ModuleAccessService {
|
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
const roleIds = roleCodes.map(Number);
|
|
144
|
-
|
|
145
|
+
|
|
146
|
+
// Step 2: Get full permissions
|
|
147
|
+
const allPermissions = await this.moduleAccessRepository.getModuleAccessByRoles(
|
|
148
|
+
roleIds,
|
|
149
|
+
appcode,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
// Step 3: If level_type is SCH, check school status using raw query
|
|
153
|
+
if (level_type === 'SCH') {
|
|
154
|
+
const result = await this.dataSource.query(
|
|
155
|
+
`SELECT * FROM cr_school WHERE id = ${level_id}`,
|
|
156
|
+
[level_id],
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const school = result?.[0];
|
|
160
|
+
|
|
161
|
+
if (!school || school.status === "INACTIVE") {
|
|
162
|
+
// Return only VIEW permissions
|
|
163
|
+
return allPermissions.filter(
|
|
164
|
+
(perm) => perm.action === 'VIEW'
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Step 4: Return all permissions normally
|
|
170
|
+
return allPermissions;
|
|
145
171
|
}
|
|
146
172
|
|
|
147
173
|
|
|
174
|
+
|
|
148
175
|
}
|
|
@@ -44,4 +44,10 @@ export class UserData extends BaseEntity {
|
|
|
44
44
|
|
|
45
45
|
@Column({ type: 'varchar', nullable: true })
|
|
46
46
|
last_app_access: string;
|
|
47
|
+
|
|
48
|
+
@Column({ type: 'varchar', nullable: true })
|
|
49
|
+
last_level_type: string;
|
|
50
|
+
|
|
51
|
+
@Column({ type: 'varchar', nullable: true })
|
|
52
|
+
last_level_id: string;
|
|
47
53
|
}
|
|
@@ -59,25 +59,41 @@ export class LoginService {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
const roleMappings = await this.userRoleMappingRepository.find({
|
|
64
|
-
where: {
|
|
65
|
-
user_id: user.id,
|
|
66
|
-
appcode: user.last_app_access,
|
|
67
|
-
},
|
|
68
|
-
});
|
|
62
|
+
let defaultAccess;
|
|
69
63
|
|
|
70
|
-
if (!
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
if (!user.last_level_type && !user.last_level_id) {
|
|
65
|
+
const roleMappings = await this.userRoleMappingRepository.find({
|
|
66
|
+
where: {
|
|
67
|
+
user_id: user.id,
|
|
68
|
+
appcode: user.last_app_access,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (!roleMappings.length) {
|
|
73
|
+
throw new BadRequestException(
|
|
74
|
+
'User does not have any access mapped for this app.',
|
|
75
|
+
);
|
|
76
|
+
}
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
// ✅ Pick default access based on priority
|
|
79
|
+
const priority = { org: 1, sch: 2, brn: 3 };
|
|
80
|
+
defaultAccess = roleMappings.sort(
|
|
81
|
+
(a, b) => priority[a.level_type] - priority[b.level_type],
|
|
82
|
+
)[0];
|
|
83
|
+
|
|
84
|
+
if ((defaultAccess.level_type, defaultAccess.level_id)) {
|
|
85
|
+
await this.userService.setLastLevelTypeAndId(
|
|
86
|
+
user.id,
|
|
87
|
+
defaultAccess.level_type,
|
|
88
|
+
defaultAccess.level_id,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
defaultAccess = {
|
|
93
|
+
level_type: user.last_level_type,
|
|
94
|
+
level_id: user.last_level_id,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
81
97
|
|
|
82
98
|
//appcode
|
|
83
99
|
|
|
@@ -85,8 +85,8 @@ export class UserSessionService {
|
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
await this.dataSource.query(
|
|
88
|
-
`UPDATE cr_user SET last_app_access = ? WHERE id = ?`,
|
|
89
|
-
[data.appcode, currentUser.id],
|
|
88
|
+
`UPDATE cr_user SET last_app_access = ? , last_level_type = ?, last_level_id = ? WHERE id = ?`,
|
|
89
|
+
[data.appcode, data.level_type, data.level_id, currentUser.id],
|
|
90
90
|
);
|
|
91
91
|
|
|
92
92
|
return {
|
|
@@ -249,4 +249,21 @@ export class UserService extends EntityServiceImpl {
|
|
|
249
249
|
|
|
250
250
|
await this.userRepository.saveUser(user); // This persists the updated field
|
|
251
251
|
}
|
|
252
|
+
|
|
253
|
+
async setLastLevelTypeAndId(
|
|
254
|
+
userId: number,
|
|
255
|
+
levelType: string,
|
|
256
|
+
levelId: string,
|
|
257
|
+
): Promise<void> {
|
|
258
|
+
const user = await this.userRepository.findById(userId);
|
|
259
|
+
|
|
260
|
+
if (!user) {
|
|
261
|
+
throw new BadRequestException('User not found');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
user.last_level_type = levelType;
|
|
265
|
+
user.last_level_id = levelId;
|
|
266
|
+
|
|
267
|
+
await this.userRepository.saveUser(user); // This persists the updated field
|
|
268
|
+
}
|
|
252
269
|
}
|