shuttlepro-shared 1.2.67 → 1.2.68
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.
|
@@ -259,70 +259,47 @@ const findUserWorkspaces = async (userId) => {
|
|
|
259
259
|
return userRoleWithWorkspaces || [];
|
|
260
260
|
};
|
|
261
261
|
|
|
262
|
-
const
|
|
263
|
-
const cacheKey = `${CACHE_KEY_USER_PERMISSIONS_PREFIX}${workspaceId}_${userId}`;
|
|
264
|
-
let cachedData = await getRedisData(cacheKey);
|
|
265
|
-
|
|
266
|
-
if (cachedData && cachedData.roleWithPermissions) {
|
|
267
|
-
return cachedData.roleWithPermissions;
|
|
268
|
-
}
|
|
269
|
-
|
|
262
|
+
const getUserPermissions = async (workspaceId, userId) => {
|
|
270
263
|
try {
|
|
271
|
-
let
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
.populate({
|
|
276
|
-
path: "roleId",
|
|
277
|
-
select:
|
|
278
|
-
"id name userId userShift permissionId modulePermissions defaultModule",
|
|
279
|
-
populate: [{ path: "permissionId", select: "id name" }],
|
|
280
|
-
})
|
|
281
|
-
.lean()
|
|
282
|
-
.exec();
|
|
283
|
-
|
|
284
|
-
if (!data) {
|
|
285
|
-
return null;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
const roleWithPermissions = {
|
|
289
|
-
...data,
|
|
290
|
-
roleId: data?.roleId?._id?.toString() || "",
|
|
291
|
-
role: data?.roleId?.name || "",
|
|
292
|
-
permissions:
|
|
264
|
+
let members = await getCachedMembers({ workspaceId, userId });
|
|
265
|
+
console.log(members, "members");
|
|
266
|
+
if (members?.length) {
|
|
267
|
+
return (
|
|
293
268
|
convertPermissionsArrayToObject(
|
|
294
|
-
|
|
295
|
-
) ||
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
// Store in cache with other permission data
|
|
302
|
-
const permissionsData = cachedData || {};
|
|
303
|
-
permissionsData.roleWithPermissions = roleWithPermissions;
|
|
304
|
-
await setRedisData(cacheKey, permissionsData);
|
|
305
|
-
|
|
306
|
-
return roleWithPermissions;
|
|
269
|
+
members?.[0]?.roleId?.modulePermissions?.modules
|
|
270
|
+
) || null
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
return null;
|
|
307
274
|
} catch (err) {
|
|
308
|
-
console.error("Error in
|
|
275
|
+
console.error("Error in getUserPermissions:", err);
|
|
309
276
|
return null;
|
|
310
277
|
}
|
|
311
278
|
};
|
|
312
279
|
|
|
313
|
-
const
|
|
280
|
+
const getUserRoleWithPermissions = async (workspaceId, userId) => {
|
|
314
281
|
try {
|
|
315
282
|
let members = await getCachedMembers({ workspaceId, userId });
|
|
316
283
|
console.log(members, "members");
|
|
317
284
|
if (members?.length) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
) ||
|
|
285
|
+
let data = members?.[0];
|
|
286
|
+
const roleWithPermissions = {
|
|
287
|
+
...data,
|
|
288
|
+
roleId: data?.roleId?._id?.toString() || "",
|
|
289
|
+
role: data?.roleId?.name || "",
|
|
290
|
+
permissions:
|
|
291
|
+
convertPermissionsArrayToObject(
|
|
292
|
+
data?.roleId?.modulePermissions?.modules
|
|
293
|
+
) || [],
|
|
294
|
+
parentRole: data?.roleId?.permissionId?.name || "",
|
|
295
|
+
parentRoleId: data?.roleId?.permissionId?._id?.toString() || "",
|
|
296
|
+
defaultModule: data?.roleId?.defaultModule || "",
|
|
297
|
+
};
|
|
298
|
+
return roleWithPermissions || null;
|
|
322
299
|
}
|
|
323
|
-
return
|
|
300
|
+
return null;
|
|
324
301
|
} catch (err) {
|
|
325
|
-
console.error("Error in
|
|
302
|
+
console.error("Error in getUserRoleWithPermissions:", err);
|
|
326
303
|
return null;
|
|
327
304
|
}
|
|
328
305
|
};
|