Merge branch 'v3-ui' of github.com:budibase/budibase into budi-8792-bigint-and-boolean-fields-dont-support-default-values

This commit is contained in:
Sam Rose 2024-10-29 12:06:43 +00:00
commit fa99c07a42
No known key found for this signature in database
6 changed files with 45 additions and 14 deletions

View File

@ -1,6 +1,6 @@
{ {
"$schema": "node_modules/lerna/schemas/lerna-schema.json", "$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "2.33.4", "version": "2.33.5",
"npmClient": "yarn", "npmClient": "yarn",
"packages": [ "packages": [
"packages/*", "packages/*",

View File

@ -237,7 +237,10 @@ export function validInherits(
export function builtinRoleToNumber(id: string) { export function builtinRoleToNumber(id: string) {
const builtins = getBuiltinRoles() const builtins = getBuiltinRoles()
const MAX = Object.values(builtins).length + 1 const MAX = Object.values(builtins).length + 1
if (id === BUILTIN_IDS.ADMIN || id === BUILTIN_IDS.BUILDER) { if (
compareRoleIds(id, BUILTIN_IDS.ADMIN) ||
compareRoleIds(id, BUILTIN_IDS.BUILDER)
) {
return MAX return MAX
} }
let role = builtins[id], let role = builtins[id],
@ -274,7 +277,9 @@ export async function roleToNumber(id: string) {
// find the built-in roles, get their number, sort it, then get the last one // find the built-in roles, get their number, sort it, then get the last one
const highestBuiltin: number | undefined = role.inherits const highestBuiltin: number | undefined = role.inherits
.map(roleId => { .map(roleId => {
const foundRole = hierarchy.find(role => role._id === roleId) const foundRole = hierarchy.find(role =>
compareRoleIds(role._id!, roleId)
)
if (foundRole) { if (foundRole) {
return findNumber(foundRole) + 1 return findNumber(foundRole) + 1
} }
@ -398,7 +403,7 @@ async function getAllUserRoles(
): Promise<RoleDoc[]> { ): Promise<RoleDoc[]> {
const allRoles = await getAllRoles() const allRoles = await getAllRoles()
// admins have access to all roles // admins have access to all roles
if (userRoleId === BUILTIN_IDS.ADMIN) { if (compareRoleIds(userRoleId, BUILTIN_IDS.ADMIN)) {
return allRoles return allRoles
} }
@ -509,17 +514,21 @@ export async function getAllRoles(appId?: string): Promise<RoleDoc[]> {
// need to combine builtin with any DB record of them (for sake of permissions) // need to combine builtin with any DB record of them (for sake of permissions)
for (let builtinRoleId of externalBuiltinRoles) { for (let builtinRoleId of externalBuiltinRoles) {
const builtinRole = builtinRoles[builtinRoleId] const builtinRole = builtinRoles[builtinRoleId]
const dbBuiltin = roles.filter( const dbBuiltin = roles.filter(dbRole =>
dbRole => compareRoleIds(dbRole._id!, builtinRoleId)
getExternalRoleID(dbRole._id!, dbRole.version) === builtinRoleId
)[0] )[0]
if (dbBuiltin == null) { if (dbBuiltin == null) {
roles.push(builtinRole || builtinRoles.BASIC) roles.push(builtinRole || builtinRoles.BASIC)
} else { } else {
// remove role and all back after combining with the builtin // remove role and all back after combining with the builtin
roles = roles.filter(role => role._id !== dbBuiltin._id) roles = roles.filter(role => role._id !== dbBuiltin._id)
dbBuiltin._id = getExternalRoleID(dbBuiltin._id!, dbBuiltin.version) dbBuiltin._id = getExternalRoleID(builtinRole._id!, dbBuiltin.version)
roles.push(Object.assign(builtinRole, dbBuiltin)) roles.push({
...builtinRole,
...dbBuiltin,
name: builtinRole.name,
_id: getExternalRoleID(builtinRole._id!, builtinRole.version),
})
} }
} }
// check permissions // check permissions
@ -565,9 +574,9 @@ export class AccessController {
if ( if (
tryingRoleId == null || tryingRoleId == null ||
tryingRoleId === "" || tryingRoleId === "" ||
tryingRoleId === userRoleId || compareRoleIds(tryingRoleId, BUILTIN_IDS.BUILDER) ||
tryingRoleId === BUILTIN_IDS.BUILDER || compareRoleIds(userRoleId!, tryingRoleId) ||
userRoleId === BUILTIN_IDS.BUILDER compareRoleIds(userRoleId!, BUILTIN_IDS.BUILDER)
) { ) {
return true return true
} }

View File

@ -38,6 +38,10 @@
let loaded = false let loaded = false
$: app = $appsStore.apps.find(app => $appStore.appId?.includes(app.appId)) $: app = $appsStore.apps.find(app => $appStore.appId?.includes(app.appId))
$: licensePlan = $auth.user?.license?.plan $: licensePlan = $auth.user?.license?.plan
// Reset the page every time that a filter gets updated
$: pageInfo.reset(), automationId, status, timeRange
$: page = $pageInfo.page $: page = $pageInfo.page
$: fetchLogs(automationId, status, page, timeRange) $: fetchLogs(automationId, status, page, timeRange)
$: isCloud = $admin.cloud $: isCloud = $admin.cloud

@ -1 +1 @@
Subproject commit f6aebba94451ce47bba551926e5ad72bd75f71c6 Subproject commit 2ab8536b6005576684810d774f1ac22239218546

View File

@ -763,12 +763,25 @@ describe.each([
expect(row.food).toEqual(["apple", "orange"]) expect(row.food).toEqual(["apple", "orange"])
}) })
it("creates a new row with a default value when given an empty list", async () => {
const row = await config.api.row.save(table._id!, { food: [] })
expect(row.food).toEqual(["apple", "orange"])
})
it("does not use default value if value specified", async () => { it("does not use default value if value specified", async () => {
const row = await config.api.row.save(table._id!, { const row = await config.api.row.save(table._id!, {
food: ["orange"], food: ["orange"],
}) })
expect(row.food).toEqual(["orange"]) expect(row.food).toEqual(["orange"])
}) })
it("resets back to its default value when empty", async () => {
let row = await config.api.row.save(table._id!, {
food: ["orange"],
})
row = await config.api.row.save(table._id!, { ...row, food: [] })
expect(row.food).toEqual(["apple", "orange"])
})
}) })
describe("user column", () => { describe("user column", () => {

View File

@ -134,7 +134,12 @@ async function processDefaultValues(table: Table, row: Row) {
} }
for (const [key, schema] of Object.entries(table.schema)) { for (const [key, schema] of Object.entries(table.schema)) {
if ("default" in schema && schema.default != null && row[key] == null) { const isEmpty =
row[key] == null ||
row[key] === "" ||
(Array.isArray(row[key]) && row[key].length === 0)
if ("default" in schema && schema.default != null && isEmpty) {
let processed: string | string[] let processed: string | string[]
if (Array.isArray(schema.default)) { if (Array.isArray(schema.default)) {
processed = schema.default.map(val => processStringSync(val, ctx)) processed = schema.default.map(val => processStringSync(val, ctx))