Merge pull request #11993 from Budibase/fix/user-col-input-user-metadata-id
Fix for saving user metadata IDs - convert them to global IDs in user column
This commit is contained in:
commit
d13ae14f94
|
@ -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<string | null> {
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue