@budibase/server 2.4.42-alpha.4 → 2.4.42

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 (60) hide show
  1. package/__mocks__/node-fetch.ts +1 -6
  2. package/builder/assets/favicon.e7fc7733.png +0 -0
  3. package/builder/assets/{index.3e01f4fd.js → index.3d64bc07.js} +384 -384
  4. package/builder/assets/index.b0e3aca6.css +6 -0
  5. package/builder/index.html +7 -7
  6. package/dist/api/controllers/application.js +24 -28
  7. package/dist/api/controllers/row/external.js +0 -15
  8. package/dist/api/controllers/row/utils.js +3 -4
  9. package/dist/api/controllers/static/index.js +24 -84
  10. package/dist/api/controllers/static/templates/BudibaseApp.svelte +11 -34
  11. package/dist/api/controllers/table/utils.js +1 -0
  12. package/dist/api/routes/public/index.js +0 -8
  13. package/dist/app.js +0 -1
  14. package/dist/integrations/redis.js +1 -1
  15. package/dist/package.json +12 -13
  16. package/dist/sdk/users/utils.js +1 -2
  17. package/dist/tsconfig.build.tsbuildinfo +1 -1
  18. package/dist/utilities/global.js +7 -17
  19. package/jest.config.ts +0 -1
  20. package/package.json +13 -14
  21. package/scripts/test.sh +3 -3
  22. package/specs/openapi.json +0 -39
  23. package/specs/openapi.yaml +0 -169
  24. package/specs/resources/application.ts +0 -11
  25. package/specs/resources/index.ts +0 -2
  26. package/src/api/controllers/application.ts +21 -20
  27. package/src/api/controllers/row/external.ts +0 -14
  28. package/src/api/controllers/row/utils.ts +3 -4
  29. package/src/api/controllers/static/index.ts +26 -69
  30. package/src/api/controllers/static/templates/BudibaseApp.svelte +11 -34
  31. package/src/api/controllers/table/utils.ts +1 -0
  32. package/src/api/controllers/view/tests/__snapshots__/viewBuilder.spec.js.snap +48 -48
  33. package/src/api/routes/public/index.ts +1 -10
  34. package/src/api/routes/tests/__snapshots__/datasource.spec.ts.snap +22 -22
  35. package/src/api/routes/tests/__snapshots__/view.spec.js.snap +5 -5
  36. package/src/api/routes/tests/internalSearch.spec.js +7 -8
  37. package/src/app.ts +1 -2
  38. package/src/automations/automationUtils.ts +1 -1
  39. package/src/automations/tests/automation.spec.js +84 -0
  40. package/src/definitions/openapi.ts +0 -15
  41. package/src/integration-test/postgres.spec.ts +52 -46
  42. package/src/integrations/redis.ts +1 -1
  43. package/src/integrations/tests/googlesheets.spec.ts +13 -13
  44. package/src/integrations/tests/redis.spec.ts +5 -9
  45. package/src/middleware/currentapp.ts +2 -2
  46. package/src/sdk/users/utils.ts +1 -4
  47. package/src/tests/jestEnv.ts +0 -1
  48. package/src/tests/jestSetup.ts +1 -5
  49. package/src/tests/utilities/TestConfiguration.ts +0 -13
  50. package/src/tests/utilities/structures.ts +1 -13
  51. package/src/utilities/global.ts +9 -21
  52. package/builder/assets/index.3cb1022d.css +0 -6
  53. package/dist/api/controllers/public/metrics.js +0 -113
  54. package/dist/api/routes/public/metrics.js +0 -30
  55. package/specs/resources/metrics.ts +0 -81
  56. package/src/api/controllers/public/metrics.ts +0 -251
  57. package/src/api/routes/public/metrics.ts +0 -28
  58. package/src/api/routes/public/tests/metrics.spec.js +0 -34
  59. package/src/api/routes/tests/appSync.spec.ts +0 -31
  60. package/src/automations/tests/automation.spec.ts +0 -99
@@ -0,0 +1,84 @@
1
+ jest.mock("../../threads/automation")
2
+ jest.mock("../../utilities/redis", () => ({
3
+ init: jest.fn(),
4
+ checkTestFlag: () => {
5
+ return false
6
+ },
7
+ }))
8
+
9
+ jest.spyOn(global.console, "error")
10
+
11
+ require("../../environment")
12
+ const automation = require("../index")
13
+ const thread = require("../../threads/automation")
14
+ const triggers = require("../triggers")
15
+ const { basicAutomation } = require("../../tests/utilities/structures")
16
+ const { wait } = require("../../utilities")
17
+ const { makePartial } = require("../../tests/utilities")
18
+ const { cleanInputValues } = require("../automationUtils")
19
+ const setup = require("./utilities")
20
+
21
+ describe("Run through some parts of the automations system", () => {
22
+ let config = setup.getConfig()
23
+
24
+ beforeAll(async () => {
25
+ await automation.init()
26
+ await config.init()
27
+ })
28
+
29
+ afterAll(setup.afterAll)
30
+
31
+ it("should be able to init in builder", async () => {
32
+ await triggers.externalTrigger(basicAutomation(), { a: 1, appId: config.appId })
33
+ await wait(100)
34
+ expect(thread.execute).toHaveBeenCalled()
35
+ })
36
+
37
+ it("should check coercion", async () => {
38
+ const table = await config.createTable()
39
+ const automation = basicAutomation()
40
+ automation.definition.trigger.inputs.tableId = table._id
41
+ automation.definition.trigger.stepId = "APP"
42
+ automation.definition.trigger.inputs.fields = { a: "number" }
43
+ await triggers.externalTrigger(automation, {
44
+ appId: config.getAppId(),
45
+ fields: {
46
+ a: "1"
47
+ }
48
+ })
49
+ await wait(100)
50
+ expect(thread.execute).toHaveBeenCalledWith(makePartial({
51
+ data: {
52
+ event: {
53
+ fields: {
54
+ a: 1
55
+ }
56
+ }
57
+ }
58
+ }), expect.any(Function))
59
+ })
60
+
61
+ it("should be able to clean inputs with the utilities", () => {
62
+ // can't clean without a schema
63
+ let output = cleanInputValues({a: "1"})
64
+ expect(output.a).toBe("1")
65
+ output = cleanInputValues({a: "1", b: "true", c: "false", d: 1, e: "help"}, {
66
+ properties: {
67
+ a: {
68
+ type: "number",
69
+ },
70
+ b: {
71
+ type: "boolean",
72
+ },
73
+ c: {
74
+ type: "boolean",
75
+ }
76
+ }
77
+ })
78
+ expect(output.a).toBe(1)
79
+ expect(output.b).toBe(true)
80
+ expect(output.c).toBe(false)
81
+ expect(output.d).toBe(1)
82
+ expect(output.e).toBe("help")
83
+ })
84
+ })
@@ -22,10 +22,6 @@ export interface paths {
22
22
  /** Based on application properties (currently only name) search for applications. */
23
23
  post: operations["appSearch"];
24
24
  };
25
- "/metrics": {
26
- /** Output metrics in OpenMetrics format compatible with Prometheus */
27
- get: operations["metricsGet"];
28
- };
29
25
  "/queries/{queryId}": {
30
26
  /** Queries which have been created within a Budibase app can be executed using this, */
31
27
  post: operations["queryExecute"];
@@ -848,17 +844,6 @@ export interface operations {
848
844
  };
849
845
  };
850
846
  };
851
- /** Output metrics in OpenMetrics format compatible with Prometheus */
852
- metricsGet: {
853
- responses: {
854
- /** Returns tenant metrics. */
855
- 200: {
856
- content: {
857
- "text/plain": string;
858
- };
859
- };
860
- };
861
- };
862
847
  /** Queries which have been created within a Budibase app can be executed using this, */
863
848
  queryExecute: {
864
849
  parameters: {
@@ -1,6 +1,3 @@
1
- import fetch from "node-fetch"
2
- // @ts-ignore
3
- fetch.mockSearch()
4
1
  import {
5
2
  generateMakeRequest,
6
3
  MakeRequestResponse,
@@ -19,7 +16,6 @@ import _ from "lodash"
19
16
  import { generator } from "@budibase/backend-core/tests"
20
17
  import { utils } from "@budibase/backend-core"
21
18
  import { GenericContainer } from "testcontainers"
22
- import { generateRowIdField } from "../integrations/utils"
23
19
 
24
20
  const config = setup.getConfig()!
25
21
 
@@ -84,10 +80,16 @@ describe("row api - postgres", () => {
84
80
  name: "id",
85
81
  type: FieldType.AUTO,
86
82
  autocolumn: true,
83
+ constraints: {
84
+ presence: true,
85
+ },
87
86
  },
88
87
  title: {
89
88
  name: "title",
90
89
  type: FieldType.STRING,
90
+ constraints: {
91
+ presence: true,
92
+ },
91
93
  },
92
94
  },
93
95
  sourceId: postgresDatasource._id,
@@ -119,10 +121,16 @@ describe("row api - postgres", () => {
119
121
  name: "id",
120
122
  type: FieldType.AUTO,
121
123
  autocolumn: true,
124
+ constraints: {
125
+ presence: true,
126
+ },
122
127
  },
123
128
  name: {
124
129
  name: "name",
125
130
  type: FieldType.STRING,
131
+ constraints: {
132
+ presence: true,
133
+ },
126
134
  },
127
135
  description: {
128
136
  name: "description",
@@ -136,6 +144,7 @@ describe("row api - postgres", () => {
136
144
  type: FieldType.LINK,
137
145
  constraints: {
138
146
  type: "array",
147
+ presence: false,
139
148
  },
140
149
  fieldName: oneToManyRelationshipInfo.fieldName,
141
150
  name: "oneToManyRelation",
@@ -147,6 +156,7 @@ describe("row api - postgres", () => {
147
156
  type: FieldType.LINK,
148
157
  constraints: {
149
158
  type: "array",
159
+ presence: false,
150
160
  },
151
161
  fieldName: manyToOneRelationshipInfo.fieldName,
152
162
  name: "manyToOneRelation",
@@ -158,6 +168,7 @@ describe("row api - postgres", () => {
158
168
  type: FieldType.LINK,
159
169
  constraints: {
160
170
  type: "array",
171
+ presence: false,
161
172
  },
162
173
  fieldName: manyToManyRelationshipInfo.fieldName,
163
174
  name: "manyToManyRelation",
@@ -298,6 +309,9 @@ describe("row api - postgres", () => {
298
309
  id: {
299
310
  name: "id",
300
311
  type: FieldType.AUTO,
312
+ constraints: {
313
+ presence: true,
314
+ },
301
315
  },
302
316
  },
303
317
  sourceId: postgresDatasource._id,
@@ -907,55 +921,47 @@ describe("row api - postgres", () => {
907
921
  foreignRows,
908
922
  x => x.relationshipType
909
923
  )
910
- const m2mFieldName = manyToManyRelationshipInfo.fieldName,
911
- o2mFieldName = oneToManyRelationshipInfo.fieldName,
912
- m2oFieldName = manyToOneRelationshipInfo.fieldName
913
- const m2mRow1 = res.body[m2mFieldName].find(
914
- (row: Row) => row.id === 1
915
- )
916
- const m2mRow2 = res.body[m2mFieldName].find(
917
- (row: Row) => row.id === 2
918
- )
919
- expect(m2mRow1).toEqual({
920
- ...foreignRowsByType[RelationshipTypes.MANY_TO_MANY][0].row,
921
- [m2mFieldName]: [
924
+ expect(res.body).toEqual({
925
+ ...rowData,
926
+ [`fk_${oneToManyRelationshipInfo.table.name}_${oneToManyRelationshipInfo.fieldName}`]:
927
+ foreignRowsByType[RelationshipTypes.ONE_TO_MANY][0].row.id,
928
+ [oneToManyRelationshipInfo.fieldName]: [
922
929
  {
923
- _id: row._id,
930
+ ...foreignRowsByType[RelationshipTypes.ONE_TO_MANY][0].row,
931
+ _id: expect.any(String),
932
+ _rev: expect.any(String),
924
933
  },
925
934
  ],
926
- })
927
- expect(m2mRow2).toEqual({
928
- ...foreignRowsByType[RelationshipTypes.MANY_TO_MANY][1].row,
929
- [m2mFieldName]: [
935
+ [manyToOneRelationshipInfo.fieldName]: [
936
+ {
937
+ ...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][0].row,
938
+ [`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
939
+ row.id,
940
+ },
930
941
  {
931
- _id: row._id,
942
+ ...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][1].row,
943
+ [`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
944
+ row.id,
945
+ },
946
+ {
947
+ ...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][2].row,
948
+ [`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
949
+ row.id,
950
+ },
951
+ ],
952
+ [manyToManyRelationshipInfo.fieldName]: [
953
+ {
954
+ ...foreignRowsByType[RelationshipTypes.MANY_TO_MANY][0].row,
955
+ },
956
+ {
957
+ ...foreignRowsByType[RelationshipTypes.MANY_TO_MANY][1].row,
932
958
  },
933
959
  ],
960
+ id: row.id,
961
+ tableId: row.tableId,
962
+ _id: expect.any(String),
963
+ _rev: expect.any(String),
934
964
  })
935
- expect(res.body[m2oFieldName]).toEqual([
936
- {
937
- ...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][0].row,
938
- [`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
939
- row.id,
940
- },
941
- {
942
- ...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][1].row,
943
- [`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
944
- row.id,
945
- },
946
- {
947
- ...foreignRowsByType[RelationshipTypes.MANY_TO_ONE][2].row,
948
- [`fk_${manyToOneRelationshipInfo.table.name}_${manyToOneRelationshipInfo.fieldName}`]:
949
- row.id,
950
- },
951
- ])
952
- expect(res.body[o2mFieldName]).toEqual([
953
- {
954
- ...foreignRowsByType[RelationshipTypes.ONE_TO_MANY][0].row,
955
- _id: expect.any(String),
956
- _rev: expect.any(String),
957
- },
958
- ])
959
965
  })
960
966
  })
961
967
  })
@@ -92,7 +92,7 @@ class RedisIntegration {
92
92
  }
93
93
 
94
94
  async disconnect() {
95
- return this.client.quit()
95
+ return this.client.disconnect()
96
96
  }
97
97
 
98
98
  async redisContext(query: Function) {
@@ -39,10 +39,6 @@ describe("Google Sheets Integration", () => {
39
39
  config.setGoogleAuth("test")
40
40
  })
41
41
 
42
- afterAll(async () => {
43
- await config.end()
44
- })
45
-
46
42
  beforeEach(async () => {
47
43
  integration = new GoogleSheetsIntegration.integration({
48
44
  spreadsheetId: "randomId",
@@ -103,8 +99,8 @@ describe("Google Sheets Integration", () => {
103
99
  })
104
100
  })
105
101
 
106
- test("removing an existing field will remove the header from the google sheet", async () => {
107
- const sheet = await config.doInContext(structures.uuid(), async () => {
102
+ test("removing an existing field will not remove the data from the spreadsheet", async () => {
103
+ await config.doInContext(structures.uuid(), async () => {
108
104
  const tableColumns = ["name"]
109
105
  const table = createBasicTable(structures.uuid(), tableColumns)
110
106
 
@@ -113,14 +109,18 @@ describe("Google Sheets Integration", () => {
113
109
  })
114
110
  sheetsByTitle[table.name] = sheet
115
111
  await integration.updateTable(table)
116
- return sheet
117
- })
118
- expect(sheet.loadHeaderRow).toBeCalledTimes(1)
119
- expect(sheet.setHeaderRow).toBeCalledTimes(1)
120
- expect(sheet.setHeaderRow).toBeCalledWith(["name"])
121
112
 
122
- // No undefined are sent
123
- expect((sheet.setHeaderRow as any).mock.calls[0][0]).toHaveLength(1)
113
+ expect(sheet.loadHeaderRow).toBeCalledTimes(1)
114
+ expect(sheet.setHeaderRow).toBeCalledTimes(1)
115
+ expect(sheet.setHeaderRow).toBeCalledWith([
116
+ "name",
117
+ "description",
118
+ "location",
119
+ ])
120
+
121
+ // No undefineds are sent
122
+ expect((sheet.setHeaderRow as any).mock.calls[0][0]).toHaveLength(3)
123
+ })
124
124
  })
125
125
  })
126
126
  })
@@ -3,17 +3,17 @@ import { default as RedisIntegration } from "../redis"
3
3
 
4
4
  class TestConfiguration {
5
5
  integration: any
6
+ redis: any
6
7
 
7
8
  constructor(config: any = {}) {
8
9
  this.integration = new RedisIntegration.integration(config)
9
- // have to kill the basic integration before replacing it
10
- this.integration.client.quit()
11
- this.integration.client = new Redis({
10
+ this.redis = new Redis({
12
11
  data: {
13
12
  test: "test",
14
13
  result: "1",
15
14
  },
16
15
  })
16
+ this.integration.client = this.redis
17
17
  }
18
18
  }
19
19
 
@@ -24,17 +24,13 @@ describe("Redis Integration", () => {
24
24
  config = new TestConfiguration()
25
25
  })
26
26
 
27
- afterAll(() => {
28
- config.integration.disconnect()
29
- })
30
-
31
27
  it("calls the create method with the correct params", async () => {
32
28
  const body = {
33
29
  key: "key",
34
30
  value: "value",
35
31
  }
36
32
  await config.integration.create(body)
37
- expect(await config.integration.client.get("key")).toEqual("value")
33
+ expect(await config.redis.get("key")).toEqual("value")
38
34
  })
39
35
 
40
36
  it("calls the read method with the correct params", async () => {
@@ -50,7 +46,7 @@ describe("Redis Integration", () => {
50
46
  key: "test",
51
47
  }
52
48
  await config.integration.delete(body)
53
- expect(await config.integration.client.get(body.key)).toEqual(null)
49
+ expect(await config.redis.get(body.key)).toEqual(null)
54
50
  })
55
51
 
56
52
  it("calls the pipeline method with the correct params", async () => {
@@ -10,9 +10,9 @@ import { generateUserMetadataID, isDevAppID } from "../db/utils"
10
10
  import { getCachedSelf } from "../utilities/global"
11
11
  import env from "../environment"
12
12
  import { isWebhookEndpoint } from "./utils"
13
- import { UserCtx } from "@budibase/types"
13
+ import { BBContext } from "@budibase/types"
14
14
 
15
- export default async (ctx: UserCtx, next: any) => {
15
+ export default async (ctx: BBContext, next: any) => {
16
16
  // try to get the appID from the request
17
17
  let requestAppId = await utils.getAppIdFromCtx(ctx)
18
18
  // get app cookie if it exists
@@ -9,10 +9,7 @@ import { isEqual } from "lodash"
9
9
 
10
10
  export function combineMetadataAndUser(user: any, metadata: any) {
11
11
  // skip users with no access
12
- if (
13
- user.roleId == null ||
14
- user.roleId === rolesCore.BUILTIN_ROLE_IDS.PUBLIC
15
- ) {
12
+ if (user.roleId === rolesCore.BUILTIN_ROLE_IDS.PUBLIC) {
16
13
  return null
17
14
  }
18
15
  delete user._rev
@@ -9,4 +9,3 @@ process.env.LOG_LEVEL = process.env.LOG_LEVEL || "error"
9
9
  process.env.ENABLE_4XX_HTTP_LOGGING = "0"
10
10
  process.env.MOCK_REDIS = "1"
11
11
  process.env.PLATFORM_URL = "http://localhost:10000"
12
- process.env.REDIS_PASSWORD = "budibase"
@@ -1,6 +1,6 @@
1
1
  import "./logging"
2
2
  import env from "../environment"
3
- import { env as coreEnv, timers } from "@budibase/backend-core"
3
+ import { env as coreEnv } from "@budibase/backend-core"
4
4
  import { testContainerUtils } from "@budibase/backend-core/tests"
5
5
 
6
6
  if (!process.env.DEBUG) {
@@ -17,7 +17,3 @@ if (!process.env.CI) {
17
17
  }
18
18
 
19
19
  testContainerUtils.setupEnv(env, coreEnv)
20
-
21
- afterAll(() => {
22
- timers.cleanup()
23
- })
@@ -46,7 +46,6 @@ import {
46
46
  Row,
47
47
  SourceName,
48
48
  Table,
49
- SearchFilters,
50
49
  } from "@budibase/types"
51
50
 
52
51
  type DefaultUserValues = {
@@ -165,8 +164,6 @@ class TestConfiguration {
165
164
  }
166
165
  if (this.server) {
167
166
  this.server.close()
168
- } else {
169
- require("../../app").default.close()
170
167
  }
171
168
  if (this.allApps) {
172
169
  cleanup(this.allApps.map(app => app.appId))
@@ -571,16 +568,6 @@ class TestConfiguration {
571
568
  return this._req(null, { tableId }, controllers.row.fetch)
572
569
  }
573
570
 
574
- async searchRows(tableId: string, searchParams: SearchFilters = {}) {
575
- if (!tableId && this.table) {
576
- tableId = this.table._id
577
- }
578
- const body = {
579
- query: searchParams,
580
- }
581
- return this._req(body, { tableId }, controllers.row.search)
582
- }
583
-
584
571
  // ROLE
585
572
 
586
573
  async createRole(config?: any) {
@@ -106,7 +106,7 @@ export function newAutomation({ steps, trigger }: any = {}) {
106
106
  return automation
107
107
  }
108
108
 
109
- export function basicAutomation(appId?: string) {
109
+ export function basicAutomation() {
110
110
  return {
111
111
  name: "My Automation",
112
112
  screenId: "kasdkfldsafkl",
@@ -114,23 +114,11 @@ export function basicAutomation(appId?: string) {
114
114
  uiTree: {},
115
115
  definition: {
116
116
  trigger: {
117
- stepId: AutomationTriggerStepId.APP,
118
- name: "test",
119
- tagline: "test",
120
- icon: "test",
121
- description: "test",
122
- type: "trigger",
123
- id: "test",
124
117
  inputs: {},
125
- schema: {
126
- inputs: {},
127
- outputs: {},
128
- },
129
118
  },
130
119
  steps: [],
131
120
  },
132
121
  type: "automation",
133
- appId,
134
122
  }
135
123
  }
136
124
 
@@ -8,7 +8,7 @@ import {
8
8
  } from "@budibase/backend-core"
9
9
  import env from "../environment"
10
10
  import { groups } from "@budibase/pro"
11
- import { UserCtx, ContextUser, User, UserGroup } from "@budibase/types"
11
+ import { BBContext, ContextUser, User } from "@budibase/types"
12
12
 
13
13
  export function updateAppRole(
14
14
  user: ContextUser,
@@ -43,40 +43,33 @@ export function updateAppRole(
43
43
 
44
44
  async function checkGroupRoles(
45
45
  user: ContextUser,
46
- opts: { appId?: string; groups?: UserGroup[] } = {}
46
+ { appId }: { appId?: string } = {}
47
47
  ) {
48
48
  if (user.roleId && user.roleId !== roles.BUILTIN_ROLE_IDS.PUBLIC) {
49
49
  return user
50
50
  }
51
- if (opts.appId) {
52
- user.roleId = await groups.getGroupRoleId(user as User, opts.appId, {
53
- groups: opts.groups,
54
- })
55
- }
56
- // final fallback, simply couldn't find a role - user must be public
57
- if (!user.roleId) {
58
- user.roleId = roles.BUILTIN_ROLE_IDS.PUBLIC
51
+ if (appId) {
52
+ user.roleId = await groups.getGroupRoleId(user as User, appId)
59
53
  }
60
54
  return user
61
55
  }
62
56
 
63
57
  async function processUser(
64
58
  user: ContextUser,
65
- opts: { appId?: string; groups?: UserGroup[] } = {}
59
+ { appId }: { appId?: string } = {}
66
60
  ) {
67
61
  if (user) {
68
62
  delete user.password
69
63
  }
70
- const appId = opts.appId || context.getAppId()
71
- user = updateAppRole(user, { appId })
64
+ user = await updateAppRole(user, { appId })
72
65
  if (!user.roleId && user?.userGroups?.length) {
73
- user = await checkGroupRoles(user, { appId, groups: opts?.groups })
66
+ user = await checkGroupRoles(user, { appId })
74
67
  }
75
68
 
76
69
  return user
77
70
  }
78
71
 
79
- export async function getCachedSelf(ctx: UserCtx, appId: string) {
72
+ export async function getCachedSelf(ctx: BBContext, appId: string) {
80
73
  // this has to be tenant aware, can't depend on the context to find it out
81
74
  // running some middlewares before the tenancy causes context to break
82
75
  const user = await cache.user.getUser(ctx.user?._id!)
@@ -97,7 +90,6 @@ export async function getGlobalUser(userId: string) {
97
90
  export async function getGlobalUsers(users?: ContextUser[]) {
98
91
  const appId = context.getAppId()
99
92
  const db = tenancy.getGlobalDB()
100
- const allGroups = await groups.fetch()
101
93
  let globalUsers
102
94
  if (users) {
103
95
  const globalIds = users.map(user =>
@@ -126,11 +118,7 @@ export async function getGlobalUsers(users?: ContextUser[]) {
126
118
  return globalUsers
127
119
  }
128
120
 
129
- // pass in the groups, meaning we don't actually need to retrieve them for
130
- // each user individually
131
- return Promise.all(
132
- globalUsers.map(user => processUser(user, { groups: allGroups }))
133
- )
121
+ return globalUsers.map(user => updateAppRole(user))
134
122
  }
135
123
 
136
124
  export async function getGlobalUsersFromMetadata(users: ContextUser[]) {