1
0
Fork 0
mirror of synced 2024-08-08 06:37:55 +12:00

Merge branch 'master' into budi-7589/user-column-multi-user-filtering-support

This commit is contained in:
Adria Navarro 2023-10-09 09:22:55 +02:00
commit 047936bcbf
3 changed files with 27 additions and 5 deletions

View file

@ -1,5 +1,5 @@
{
"version": "2.11.14",
"version": "2.11.15",
"npmClient": "yarn",
"packages": [
"packages/*"

View file

@ -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"
export async function processInputBBReferences<T extends FieldSubtype>(
const ROW_PREFIX = DocumentType.ROW + SEPARATOR
export async function processInputBBReferences(
value: string | string[] | { _id: string } | { _id: string }[],
subtype: FieldSubtype
): Promise<string | string[] | null> {
const referenceIds: string[] = []
let referenceIds: string[] = []
if (Array.isArray(value)) {
referenceIds.push(
@ -26,6 +28,17 @@ export async function processInputBBReferences<T extends FieldSubtype>(
)
}
// 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:
case FieldSubtype.USERS:

View file

@ -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)
})
})
})