@budibase/worker 3.33.1 → 3.33.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/worker",
3
3
  "email": "hi@budibase.com",
4
- "version": "3.33.1",
4
+ "version": "3.33.3",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -91,5 +91,5 @@
91
91
  "supertest": "6.3.3",
92
92
  "timekeeper": "2.2.0"
93
93
  },
94
- "gitHead": "7e37f4dca78aaab158a4fa07ba631720003da6b3"
94
+ "gitHead": "636f2bfa98c45e71c604b7a655ddedb16871dd85"
95
95
  }
@@ -777,27 +777,52 @@ export const inviteAccept = async (
777
777
  resolvedTenantId
778
778
  )
779
779
  const user = await tenancy.doInTenant(info.tenantId, async () => {
780
+ const appRoles = info.apps || {}
781
+ const creatorAppsFromRoles = Object.keys(appRoles).filter(
782
+ appId => appRoles[appId] === "CREATOR"
783
+ )
784
+
785
+ const builderApps = [
786
+ ...(info?.builder?.apps || []),
787
+ ...creatorAppsFromRoles,
788
+ ]
789
+ const uniqueBuilderApps = [...new Set(builderApps)]
790
+ const hasCreatorPerms =
791
+ !!info?.builder?.creator || creatorAppsFromRoles.length > 0
792
+
780
793
  let request: any = {
781
794
  firstName,
782
795
  lastName,
783
796
  password,
784
797
  email,
785
798
  admin: { global: info?.admin?.global || false },
786
- roles: info.apps,
799
+ roles: appRoles,
787
800
  tenantId: info.tenantId,
788
801
  }
789
- const builder: { global: boolean; apps?: string[] } = {
802
+ const builder: {
803
+ global: boolean
804
+ creator?: boolean
805
+ apps?: string[]
806
+ } = {
790
807
  global: info?.builder?.global || false,
791
808
  }
792
809
 
793
- if (info?.builder?.apps) {
794
- builder.apps = info.builder.apps
795
- request.builder = builder
810
+ if (hasCreatorPerms) {
811
+ builder.creator = true
812
+ }
813
+ if (uniqueBuilderApps.length) {
814
+ builder.apps = uniqueBuilderApps
796
815
  }
797
- delete info.apps
816
+
817
+ const cleanedInviteInfo = { ...info }
818
+ delete cleanedInviteInfo.apps
819
+ delete cleanedInviteInfo.builder
798
820
  request = {
799
821
  ...request,
800
- ...info,
822
+ ...cleanedInviteInfo,
823
+ }
824
+ if (info?.builder || hasCreatorPerms || uniqueBuilderApps.length) {
825
+ request.builder = builder
801
826
  }
802
827
 
803
828
  const saved = await userSdk.db.save(request)
@@ -374,6 +374,36 @@ describe("/api/global/users", () => {
374
374
  expect(events.user.invited).toHaveBeenCalledTimes(2)
375
375
  })
376
376
 
377
+ it("should persist invited creator app access when accepting the invite", async () => {
378
+ const email = structures.users.newEmail()
379
+ const workspaceId = "app_creator_invite_workspace"
380
+ const request = [
381
+ {
382
+ email,
383
+ userInfo: {
384
+ builder: { creator: true },
385
+ apps: {
386
+ [workspaceId]: "CREATOR",
387
+ },
388
+ },
389
+ },
390
+ ]
391
+
392
+ await config.api.users.sendMultiUserInvite(request)
393
+
394
+ const emailCall = sendMailMock.mock.calls[0][0]
395
+ const code = emailCall.html
396
+ .split("http://localhost:10000/builder/invite?code=")[1]
397
+ .split('"')[0]
398
+ .split("&")[0]
399
+ await config.api.users.acceptInvite(code)
400
+
401
+ const user = await config.getUser(email)
402
+ expect(user?.roles?.[workspaceId]).toBe("CREATOR")
403
+ expect(user?.builder?.creator).toBe(true)
404
+ expect(user?.builder?.apps).toEqual([workspaceId])
405
+ })
406
+
377
407
  it("should not be able to generate an invitation for existing user", async () => {
378
408
  const request = [{ email: config.user!.email, userInfo: {} }]
379
409