From d4335bca73b29ab0742b7c6aadd8a6c72de08482 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 6 Oct 2023 16:31:48 +0100 Subject: [PATCH 1/3] Quick fix for saving current user._id - make sure it is the correct format of ID. --- .../rowProcessor/bbReferenceProcessor.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/server/src/utilities/rowProcessor/bbReferenceProcessor.ts b/packages/server/src/utilities/rowProcessor/bbReferenceProcessor.ts index 6f41d3d55f..5b7e852f50 100644 --- a/packages/server/src/utilities/rowProcessor/bbReferenceProcessor.ts +++ b/packages/server/src/utilities/rowProcessor/bbReferenceProcessor.ts @@ -1,13 +1,15 @@ -import { cache } from "@budibase/backend-core" +import { cache, db as dbCore } from "@budibase/backend-core" import { utils } from "@budibase/shared-core" -import { FieldSubtype } from "@budibase/types" +import { FieldSubtype, DocumentType, SEPARATOR } from "@budibase/types" import { InvalidBBRefError } from "./errors" +const ROW_PREFIX = DocumentType.ROW + SEPARATOR + export async function processInputBBReferences( value: string | string[] | { _id: string } | { _id: string }[], subtype: FieldSubtype ): Promise { - const referenceIds: string[] = [] + let referenceIds: string[] = [] if (Array.isArray(value)) { referenceIds.push( @@ -26,6 +28,17 @@ export async function processInputBBReferences( ) } + // make sure all reference IDs are correct global user IDs + // they may be user metadata references (start with row prefix) + // and these need to be converted to global IDs + referenceIds = referenceIds.map(id => { + if (id?.startsWith(ROW_PREFIX)) { + return dbCore.getGlobalIDFromUserMetadataID(id) + } else { + return id + } + }) + switch (subtype) { case FieldSubtype.USER: const { notFoundIds } = await cache.user.getUsers(referenceIds) From 0dc28122fa5ffd04747aa7896b20f4b351bfa13c Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 6 Oct 2023 16:38:36 +0100 Subject: [PATCH 2/3] Adding test case. --- .../rowProcessor/tests/bbReferenceProcessor.spec.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts b/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts index d0932b399c..b6174861d4 100644 --- a/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts @@ -154,6 +154,15 @@ describe("bbReferenceProcessor", () => { expect(result).toEqual(null) }) + + it("should convert user medata IDs to global IDs", async () => { + const userId = _.sample(users)!._id! + const userMetadataId = backendCore.db.generateUserMetadataID(userId) + const result = await config.doInTenant(() => + processInputBBReferences(userMetadataId, FieldSubtype.USER) + ) + expect(result).toBe(userId) + }) }) }) From d41f81bb45c52a59f35b8de3a311874e9a6f41dd Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Fri, 6 Oct 2023 15:54:26 +0000 Subject: [PATCH 3/3] Bump version to 2.11.15 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index 6c50c0bc16..7968b8999f 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "2.11.14", + "version": "2.11.15", "npmClient": "yarn", "packages": [ "packages/*"