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"
|
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.
|
* 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 = {
|
export const StaticDatabases = {
|
||||||
GLOBAL: {
|
GLOBAL: {
|
||||||
name: "global-db",
|
name: "global-db",
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
<script>
|
<script>
|
||||||
import RelationshipField from "./RelationshipField.svelte"
|
import RelationshipField from "./RelationshipField.svelte"
|
||||||
|
import { sdk } from "@budibase/shared-core"
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<RelationshipField
|
<RelationshipField
|
||||||
{...$$props}
|
{...$$props}
|
||||||
datasourceType={"user"}
|
datasourceType={"user"}
|
||||||
primaryDisplay={"email"}
|
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 filter
|
||||||
export let datasourceType = "table"
|
export let datasourceType = "table"
|
||||||
export let primaryDisplay
|
export let primaryDisplay
|
||||||
|
export let valueConversion
|
||||||
|
|
||||||
let fieldState
|
let fieldState
|
||||||
let fieldApi
|
let fieldApi
|
||||||
|
@ -160,7 +161,9 @@
|
||||||
const handleChange = value => {
|
const handleChange = value => {
|
||||||
const changed = fieldApi.setValue(value)
|
const changed = fieldApi.setValue(value)
|
||||||
if (onChange && changed) {
|
if (onChange && changed) {
|
||||||
onChange({ value })
|
onChange({
|
||||||
|
value: valueConversion ? valueConversion(value) : value,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +179,9 @@
|
||||||
{field}
|
{field}
|
||||||
{disabled}
|
{disabled}
|
||||||
{validation}
|
{validation}
|
||||||
defaultValue={expandedDefaultValue}
|
defaultValue={valueConversion
|
||||||
|
? valueConversion(expandedDefaultValue)
|
||||||
|
: expandedDefaultValue}
|
||||||
{type}
|
{type}
|
||||||
bind:fieldState
|
bind:fieldState
|
||||||
bind:fieldApi
|
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"
|
import { getProdAppID } from "./applications"
|
||||||
|
|
||||||
// checks if a user is specifically a builder, given an app ID
|
// 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
|
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,
|
DocumentType.LAYOUT,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
export enum InternalTable {
|
||||||
|
USER_METADATA = "ta_users",
|
||||||
|
}
|
||||||
|
|
||||||
// these documents don't really exist, they are part of other
|
// these documents don't really exist, they are part of other
|
||||||
// documents or enriched into existence as part of get requests
|
// documents or enriched into existence as part of get requests
|
||||||
export enum VirtualDocumentType {
|
export enum VirtualDocumentType {
|
||||||
|
|
Loading…
Reference in New Issue