diff --git a/packages/backend-core/src/constants/db.ts b/packages/backend-core/src/constants/db.ts index f918dcc352..b33b4835a9 100644 --- a/packages/backend-core/src/constants/db.ts +++ b/packages/backend-core/src/constants/db.ts @@ -1,5 +1,10 @@ import { prefixed, DocumentType } from "@budibase/types" -export { SEPARATOR, UNICODE_MAX, DocumentType } from "@budibase/types" +export { + SEPARATOR, + UNICODE_MAX, + DocumentType, + InternalTable, +} from "@budibase/types" /** * Can be used to create a few different forms of querying a view. @@ -30,10 +35,6 @@ export const DeprecatedViews = { ], } -export enum InternalTable { - USER_METADATA = "ta_users", -} - export const StaticDatabases = { GLOBAL: { name: "global-db", diff --git a/packages/client/src/components/app/forms/BBReferenceField.svelte b/packages/client/src/components/app/forms/BBReferenceField.svelte index 7d11ff5525..5f00c503c2 100644 --- a/packages/client/src/components/app/forms/BBReferenceField.svelte +++ b/packages/client/src/components/app/forms/BBReferenceField.svelte @@ -1,9 +1,28 @@ diff --git a/packages/client/src/components/app/forms/RelationshipField.svelte b/packages/client/src/components/app/forms/RelationshipField.svelte index bb003730b3..52faf46615 100644 --- a/packages/client/src/components/app/forms/RelationshipField.svelte +++ b/packages/client/src/components/app/forms/RelationshipField.svelte @@ -160,7 +160,9 @@ const handleChange = value => { const changed = fieldApi.setValue(value) if (onChange && changed) { - onChange({ value }) + onChange({ + value, + }) } } diff --git a/packages/shared-core/src/sdk/documents/users.ts b/packages/shared-core/src/sdk/documents/users.ts index 1be8845656..03d86daa85 100644 --- a/packages/shared-core/src/sdk/documents/users.ts +++ b/packages/shared-core/src/sdk/documents/users.ts @@ -1,4 +1,10 @@ -import { ContextUser, User } from "@budibase/types" +import { + ContextUser, + DocumentType, + SEPARATOR, + User, + InternalTable, +} from "@budibase/types" import { getProdAppID } from "./applications" // checks if a user is specifically a builder, given an app ID @@ -67,3 +73,21 @@ export function hasAdminPermissions(user?: User | ContextUser): boolean { } return !!user.admin?.global } + +export function getGlobalUserID(userId?: string): string | undefined { + if (typeof userId !== "string") { + return userId + } + const prefix = `${DocumentType.ROW}${SEPARATOR}${InternalTable.USER_METADATA}${SEPARATOR}` + if (!userId.startsWith(prefix)) { + return userId + } + return userId.split(prefix)[1] +} + +export function containsUserID(value: string | undefined): boolean { + if (typeof value !== "string") { + return false + } + return value.includes(`${DocumentType.USER}${SEPARATOR}`) +} diff --git a/packages/types/src/documents/document.ts b/packages/types/src/documents/document.ts index 763da62d61..fb9589b24d 100644 --- a/packages/types/src/documents/document.ts +++ b/packages/types/src/documents/document.ts @@ -58,6 +58,10 @@ export const DocumentTypesToImport: DocumentType[] = [ DocumentType.LAYOUT, ] +export enum InternalTable { + USER_METADATA = "ta_users", +} + // these documents don't really exist, they are part of other // documents or enriched into existence as part of get requests export enum VirtualDocumentType {