@budibase/backend-core 2.10.15 → 2.10.16-alpha.1

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.
Files changed (81) hide show
  1. package/dist/index.js +60 -11
  2. package/dist/index.js.map +2 -2
  3. package/dist/index.js.meta.json +1 -1
  4. package/dist/package.json +6 -14
  5. package/dist/plugins.js.meta.json +1 -1
  6. package/dist/src/cache/appMetadata.js +1 -1
  7. package/dist/src/cache/appMetadata.js.map +1 -1
  8. package/dist/src/cache/generic.js +2 -2
  9. package/dist/src/cache/generic.js.map +1 -1
  10. package/dist/src/cache/user.d.ts +13 -0
  11. package/dist/src/cache/user.js +51 -1
  12. package/dist/src/cache/user.js.map +1 -1
  13. package/dist/src/constants/db.js +3 -3
  14. package/dist/src/constants/db.js.map +1 -1
  15. package/dist/src/constants/misc.js +5 -5
  16. package/dist/src/constants/misc.js.map +1 -1
  17. package/dist/src/context/Context.js +1 -1
  18. package/dist/src/context/Context.js.map +1 -1
  19. package/dist/src/context/types.d.ts +1 -1
  20. package/dist/src/db/lucene.d.ts +1 -1
  21. package/dist/src/db/lucene.js +6 -6
  22. package/dist/src/db/lucene.js.map +1 -1
  23. package/dist/src/errors/errors.js +1 -1
  24. package/dist/src/errors/errors.js.map +1 -1
  25. package/dist/src/events/processors/AuditLogsProcessor.js +1 -1
  26. package/dist/src/events/processors/AuditLogsProcessor.js.map +1 -1
  27. package/dist/src/events/processors/async/DocumentUpdateProcessor.d.ts +2 -2
  28. package/dist/src/features/index.js +1 -1
  29. package/dist/src/features/index.js.map +1 -1
  30. package/dist/src/middleware/passport/datasource/google.d.ts +1 -1
  31. package/dist/src/objectStore/objectStore.d.ts +1 -1
  32. package/dist/src/queue/constants.js +1 -1
  33. package/dist/src/queue/constants.js.map +1 -1
  34. package/dist/src/queue/listeners.d.ts +1 -1
  35. package/dist/src/redis/redis.d.ts +1 -1
  36. package/dist/src/redis/redis.js.map +1 -1
  37. package/dist/src/redis/redlockImpl.d.ts +3 -3
  38. package/dist/src/redis/utils.js +2 -2
  39. package/dist/src/redis/utils.js.map +1 -1
  40. package/dist/src/security/encryption.js +1 -1
  41. package/dist/src/security/encryption.js.map +1 -1
  42. package/dist/src/security/permissions.d.ts +3 -3
  43. package/dist/src/security/permissions.js +7 -3
  44. package/dist/src/security/permissions.js.map +1 -1
  45. package/dist/src/security/roles.d.ts +4 -5
  46. package/dist/src/security/roles.js +19 -9
  47. package/dist/src/security/roles.js.map +1 -1
  48. package/dist/src/users/db.d.ts +8 -8
  49. package/dist/src/users/users.d.ts +1 -1
  50. package/dist/tests/core/logging.js +1 -1
  51. package/dist/tests/core/logging.js.map +1 -1
  52. package/dist/tests/core/utilities/mocks/licenses.d.ts +1 -1
  53. package/dist/tests/core/utilities/mocks/licenses.js +4 -4
  54. package/dist/tests/core/utilities/mocks/licenses.js.map +1 -1
  55. package/dist/tests/core/utilities/structures/sso.js +3 -4
  56. package/dist/tests/core/utilities/structures/sso.js.map +1 -1
  57. package/dist/tests/core/utilities/structures/users.d.ts +4 -3
  58. package/dist/tests/core/utilities/structures/users.js +18 -10
  59. package/dist/tests/core/utilities/structures/users.js.map +1 -1
  60. package/dist/tests/extra/DBTestConfiguration.d.ts +1 -1
  61. package/dist/tests/extra/DBTestConfiguration.js.map +1 -1
  62. package/dist/tests/index.d.ts +1 -0
  63. package/dist/tests/index.js +1 -0
  64. package/dist/tests/index.js.map +1 -1
  65. package/package.json +6 -14
  66. package/src/cache/tests/user.spec.ts +145 -0
  67. package/src/cache/user.ts +60 -0
  68. package/src/middleware/passport/sso/tests/sso.spec.ts +1 -0
  69. package/src/redis/redis.ts +2 -2
  70. package/src/security/permissions.ts +7 -2
  71. package/src/security/roles.ts +16 -11
  72. package/src/utils/utils.ts +1 -1
  73. package/tests/core/utilities/mocks/licenses.ts +2 -2
  74. package/tests/core/utilities/structures/sso.ts +3 -4
  75. package/tests/core/utilities/structures/users.ts +24 -3
  76. package/tests/extra/DBTestConfiguration.ts +1 -1
  77. package/tests/index.ts +1 -0
  78. package/dist/tests/core/utilities/structures/shared.d.ts +0 -3
  79. package/dist/tests/core/utilities/structures/shared.js +0 -14
  80. package/dist/tests/core/utilities/structures/shared.js.map +0 -1
  81. package/tests/core/utilities/structures/shared.ts +0 -19
package/dist/index.js CHANGED
@@ -5695,6 +5695,7 @@ var bustCache = performExport("bustCache");
5695
5695
  var user_exports = {};
5696
5696
  __export(user_exports, {
5697
5697
  getUser: () => getUser,
5698
+ getUsers: () => getUsers,
5698
5699
  invalidateUser: () => invalidateUser
5699
5700
  });
5700
5701
  init_init();
@@ -10020,6 +10021,27 @@ async function populateFromDB2(userId, tenantId) {
10020
10021
  }
10021
10022
  return user;
10022
10023
  }
10024
+ async function populateUsersFromDB(userIds) {
10025
+ const getUsersResponse = await UserDB.bulkGet(userIds);
10026
+ const notFoundIds = userIds.filter((uid, i) => !getUsersResponse[i]);
10027
+ const users = getUsersResponse.filter((x) => x);
10028
+ await Promise.all(
10029
+ users.map(async (user) => {
10030
+ user.budibaseAccess = true;
10031
+ if (!environment_default.SELF_HOSTED && !environment_default.DISABLE_ACCOUNT_PORTAL) {
10032
+ const account = await getAccount(user.email);
10033
+ if (account) {
10034
+ user.account = account;
10035
+ user.accountPortalAccess = true;
10036
+ }
10037
+ }
10038
+ })
10039
+ );
10040
+ if (notFoundIds.length) {
10041
+ return { users, notFoundIds };
10042
+ }
10043
+ return { users };
10044
+ }
10023
10045
  async function getUser(userId, tenantId, populateUser) {
10024
10046
  if (!populateUser) {
10025
10047
  populateUser = populateFromDB2;
@@ -10053,6 +10075,22 @@ async function getUser(userId, tenantId, populateUser) {
10053
10075
  }
10054
10076
  return user;
10055
10077
  }
10078
+ async function getUsers(userIds) {
10079
+ const client = await getUserClient();
10080
+ let usersFromCache = await client.bulkGet(userIds);
10081
+ const missingUsersFromCache = userIds.filter((uid) => !usersFromCache[uid]);
10082
+ const users = Object.values(usersFromCache);
10083
+ let notFoundIds;
10084
+ if (missingUsersFromCache.length) {
10085
+ const usersFromDb = await populateUsersFromDB(missingUsersFromCache);
10086
+ notFoundIds = usersFromDb.notFoundIds;
10087
+ for (const userToCache of usersFromDb.users) {
10088
+ await client.store(userToCache._id, userToCache, EXPIRY_SECONDS3);
10089
+ }
10090
+ users.push(...usersFromDb.users);
10091
+ }
10092
+ return { users, notFoundIds };
10093
+ }
10056
10094
  async function invalidateUser(userId) {
10057
10095
  const client = await getUserClient();
10058
10096
  await client.delete(userId);
@@ -10523,12 +10561,14 @@ __export(roles_exports, {
10523
10561
  RoleIDVersion: () => RoleIDVersion,
10524
10562
  builtinRoleToNumber: () => builtinRoleToNumber,
10525
10563
  checkForRoleResourceArray: () => checkForRoleResourceArray,
10564
+ getAllRoleIds: () => getAllRoleIds,
10526
10565
  getAllRoles: () => getAllRoles,
10527
10566
  getBuiltinRoles: () => getBuiltinRoles,
10528
10567
  getDBRoleID: () => getDBRoleID,
10529
10568
  getExternalRoleID: () => getExternalRoleID,
10530
10569
  getRole: () => getRole,
10531
10570
  getUserRoleHierarchy: () => getUserRoleHierarchy,
10571
+ getUserRoleIdHierarchy: () => getUserRoleIdHierarchy,
10532
10572
  isBuiltin: () => isBuiltin,
10533
10573
  lowerBuiltinRoleID: () => lowerBuiltinRoleID,
10534
10574
  roleToNumber: () => roleToNumber
@@ -10552,9 +10592,9 @@ __export(permissions_exports, {
10552
10592
  levelToNumber: () => levelToNumber
10553
10593
  });
10554
10594
  init_src();
10555
- init_src();
10556
10595
  var import_flatten = __toESM(require("lodash/flatten"));
10557
10596
  var import_cloneDeep = __toESM(require("lodash/fp/cloneDeep"));
10597
+ init_src();
10558
10598
  var Permission = class {
10559
10599
  constructor(type, level) {
10560
10600
  this.type = type;
@@ -10613,7 +10653,8 @@ var BUILTIN_PERMISSIONS = {
10613
10653
  name: "Read only",
10614
10654
  permissions: [
10615
10655
  new Permission("query" /* QUERY */, "read" /* READ */),
10616
- new Permission("table" /* TABLE */, "read" /* READ */)
10656
+ new Permission("table" /* TABLE */, "read" /* READ */),
10657
+ new Permission("app" /* APP */, "read" /* READ */)
10617
10658
  ]
10618
10659
  },
10619
10660
  WRITE: {
@@ -10623,7 +10664,8 @@ var BUILTIN_PERMISSIONS = {
10623
10664
  new Permission("query" /* QUERY */, "write" /* WRITE */),
10624
10665
  new Permission("table" /* TABLE */, "write" /* WRITE */),
10625
10666
  new Permission("automation" /* AUTOMATION */, "execute" /* EXECUTE */),
10626
- new Permission("legacy_view" /* LEGACY_VIEW */, "read" /* READ */)
10667
+ new Permission("legacy_view" /* LEGACY_VIEW */, "read" /* READ */),
10668
+ new Permission("app" /* APP */, "read" /* READ */)
10627
10669
  ]
10628
10670
  },
10629
10671
  POWER: {
@@ -10634,7 +10676,8 @@ var BUILTIN_PERMISSIONS = {
10634
10676
  new Permission("user" /* USER */, "read" /* READ */),
10635
10677
  new Permission("automation" /* AUTOMATION */, "execute" /* EXECUTE */),
10636
10678
  new Permission("webhook" /* WEBHOOK */, "read" /* READ */),
10637
- new Permission("legacy_view" /* LEGACY_VIEW */, "read" /* READ */)
10679
+ new Permission("legacy_view" /* LEGACY_VIEW */, "read" /* READ */),
10680
+ new Permission("app" /* APP */, "read" /* READ */)
10638
10681
  ]
10639
10682
  },
10640
10683
  ADMIN: {
@@ -10646,7 +10689,8 @@ var BUILTIN_PERMISSIONS = {
10646
10689
  new Permission("automation" /* AUTOMATION */, "admin" /* ADMIN */),
10647
10690
  new Permission("webhook" /* WEBHOOK */, "read" /* READ */),
10648
10691
  new Permission("query" /* QUERY */, "admin" /* ADMIN */),
10649
- new Permission("legacy_view" /* LEGACY_VIEW */, "read" /* READ */)
10692
+ new Permission("legacy_view" /* LEGACY_VIEW */, "read" /* READ */),
10693
+ new Permission("app" /* APP */, "read" /* READ */)
10650
10694
  ]
10651
10695
  }
10652
10696
  };
@@ -10832,9 +10876,12 @@ async function getAllUserRoles(userRoleId) {
10832
10876
  }
10833
10877
  return roles;
10834
10878
  }
10835
- async function getUserRoleHierarchy(userRoleId, opts = { idOnly: true }) {
10836
- const roles = await getAllUserRoles(userRoleId);
10837
- return opts.idOnly ? roles.map((role) => role._id) : roles;
10879
+ async function getUserRoleIdHierarchy(userRoleId) {
10880
+ const roles = await getUserRoleHierarchy(userRoleId);
10881
+ return roles.map((role) => role._id);
10882
+ }
10883
+ async function getUserRoleHierarchy(userRoleId) {
10884
+ return getAllUserRoles(userRoleId);
10838
10885
  }
10839
10886
  function checkForRoleResourceArray(rolePerms, resourceId) {
10840
10887
  if (rolePerms && !Array.isArray(rolePerms[resourceId])) {
@@ -10846,6 +10893,10 @@ function checkForRoleResourceArray(rolePerms, resourceId) {
10846
10893
  }
10847
10894
  return rolePerms;
10848
10895
  }
10896
+ async function getAllRoleIds(appId) {
10897
+ const roles = await getAllRoles(appId);
10898
+ return roles.map((role) => role._id);
10899
+ }
10849
10900
  async function getAllRoles(appId) {
10850
10901
  if (appId) {
10851
10902
  return doWithDB(appId, internal);
@@ -10908,9 +10959,7 @@ var AccessController = class {
10908
10959
  }
10909
10960
  let roleIds = userRoleId ? this.userHierarchies[userRoleId] : null;
10910
10961
  if (!roleIds && userRoleId) {
10911
- roleIds = await getUserRoleHierarchy(userRoleId, {
10912
- idOnly: true
10913
- });
10962
+ roleIds = await getUserRoleIdHierarchy(userRoleId);
10914
10963
  this.userHierarchies[userRoleId] = roleIds;
10915
10964
  }
10916
10965
  return roleIds?.indexOf(tryingRoleId) !== -1;