shuttlepro-shared 1.2.66 → 1.2.67
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.
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const { UserRole } = require("../../models/UserRole");
|
|
2
2
|
const { getRedisData, setRedisData } = require("../../config/redis");
|
|
3
|
-
const mongoose = require("mongoose");
|
|
4
3
|
|
|
5
4
|
const defaultSelect =
|
|
6
5
|
"iconUrl thumbUrl name productsCount ordersCount contact email address websiteUrl facebookUrl twitterUrl instagramUrl members defaultModule";
|
|
@@ -231,7 +230,7 @@ const deleteUserRole = async (id) => {
|
|
|
231
230
|
};
|
|
232
231
|
|
|
233
232
|
const findUserWorkspaces = async (userId) => {
|
|
234
|
-
|
|
233
|
+
let userRoleWithWorkspaces = await UserRole.find({ userId: userId })
|
|
235
234
|
.select("userId roleId workspaceId")
|
|
236
235
|
.populate({
|
|
237
236
|
path: "roleId",
|
|
@@ -257,6 +256,7 @@ const findUserWorkspaces = async (userId) => {
|
|
|
257
256
|
permissions: ur?.roleId?.modulePermissions?.modules || [],
|
|
258
257
|
};
|
|
259
258
|
});
|
|
259
|
+
return userRoleWithWorkspaces || [];
|
|
260
260
|
};
|
|
261
261
|
|
|
262
262
|
const getUserRoleWithPermissions = async (workspaceId, userId) => {
|
|
@@ -311,41 +311,16 @@ const getUserRoleWithPermissions = async (workspaceId, userId) => {
|
|
|
311
311
|
};
|
|
312
312
|
|
|
313
313
|
const getUserPermissions = async (workspaceId, userId) => {
|
|
314
|
-
const cacheKey = `${CACHE_KEY_USER_PERMISSIONS_PREFIX}${workspaceId}_${userId}`;
|
|
315
|
-
let cachedData = await getRedisData(cacheKey);
|
|
316
|
-
|
|
317
|
-
if (cachedData && cachedData.permissions) {
|
|
318
|
-
return cachedData.permissions;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
314
|
try {
|
|
322
|
-
let
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
select: "modulePermissions",
|
|
330
|
-
})
|
|
331
|
-
.lean()
|
|
332
|
-
.exec();
|
|
333
|
-
|
|
334
|
-
if (!data) {
|
|
335
|
-
return null;
|
|
315
|
+
let members = await getCachedMembers({ workspaceId, userId });
|
|
316
|
+
console.log(members, "members");
|
|
317
|
+
if (members?.length) {
|
|
318
|
+
const permissions =
|
|
319
|
+
convertPermissionsArrayToObject(
|
|
320
|
+
members?.[0]?.roleId?.modulePermissions?.modules
|
|
321
|
+
) || null;
|
|
336
322
|
}
|
|
337
|
-
|
|
338
|
-
const permissions =
|
|
339
|
-
convertPermissionsArrayToObject(
|
|
340
|
-
data?.roleId?.modulePermissions?.modules
|
|
341
|
-
) || null;
|
|
342
|
-
|
|
343
|
-
// Store in cache with other permission data
|
|
344
|
-
const permissionsData = cachedData || {};
|
|
345
|
-
permissionsData.permissions = permissions;
|
|
346
|
-
await setRedisData(cacheKey, permissionsData);
|
|
347
|
-
|
|
348
|
-
return permissions;
|
|
323
|
+
return permissions || null;
|
|
349
324
|
} catch (err) {
|
|
350
325
|
console.error("Error in getUserPermissions:", err);
|
|
351
326
|
return null;
|