Converting user IDs where necessary to global user IDs in the frontend, correcting the null entry when using current user IDs, or other user IDs, as a default value for a user column form type.
This commit is contained in:
parent
afedd560fd
commit
c87a67a37a
|
@ -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",
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
<script>
|
||||
import RelationshipField from "./RelationshipField.svelte"
|
||||
import { sdk } from "@budibase/shared-core"
|
||||
</script>
|
||||
|
||||
<RelationshipField
|
||||
{...$$props}
|
||||
datasourceType={"user"}
|
||||
primaryDisplay={"email"}
|
||||
valueConversion={value => {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(val => sdk.users.getGlobalUserID(val))
|
||||
} else {
|
||||
return sdk.users.getGlobalUserID(value)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
export let filter
|
||||
export let datasourceType = "table"
|
||||
export let primaryDisplay
|
||||
export let valueConversion
|
||||
|
||||
let fieldState
|
||||
let fieldApi
|
||||
|
@ -160,7 +161,9 @@
|
|||
const handleChange = value => {
|
||||
const changed = fieldApi.setValue(value)
|
||||
if (onChange && changed) {
|
||||
onChange({ value })
|
||||
onChange({
|
||||
value: valueConversion ? valueConversion(value) : value,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,7 +179,9 @@
|
|||
{field}
|
||||
{disabled}
|
||||
{validation}
|
||||
defaultValue={expandedDefaultValue}
|
||||
defaultValue={valueConversion
|
||||
? valueConversion(expandedDefaultValue)
|
||||
: expandedDefaultValue}
|
||||
{type}
|
||||
bind:fieldState
|
||||
bind:fieldApi
|
||||
|
|
|
@ -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,14 @@ 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]
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue