Skip to content

Commit

Permalink
Merge branch 'v3-ui' of github.com:budibase/budibase into feature/aut…
Browse files Browse the repository at this point in the history
…omation-branching-ux
  • Loading branch information
samwho committed Oct 29, 2024
2 parents 23c655e + 336bd97 commit 1bfb4ee
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "2.33.4",
"version": "2.33.5",
"npmClient": "yarn",
"packages": [
"packages/*",
Expand Down
16 changes: 8 additions & 8 deletions packages/backend-core/src/security/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ export function builtinRoleToNumber(id: string) {
const builtins = getBuiltinRoles()
const MAX = Object.values(builtins).length + 1
if (
compareRoleIds(id, BUILTIN_IDS.ADMIN) ||
compareRoleIds(id, BUILTIN_IDS.BUILDER)
roleIDsAreEqual(id, BUILTIN_IDS.ADMIN) ||
roleIDsAreEqual(id, BUILTIN_IDS.BUILDER)
) {
return MAX
}
Expand Down Expand Up @@ -278,7 +278,7 @@ export async function roleToNumber(id: string) {
const highestBuiltin: number | undefined = role.inherits
.map(roleId => {
const foundRole = hierarchy.find(role =>
compareRoleIds(role._id!, roleId)
roleIDsAreEqual(role._id!, roleId)
)
if (foundRole) {
return findNumber(foundRole) + 1
Expand Down Expand Up @@ -403,7 +403,7 @@ async function getAllUserRoles(
): Promise<RoleDoc[]> {
const allRoles = await getAllRoles()
// admins have access to all roles
if (compareRoleIds(userRoleId, BUILTIN_IDS.ADMIN)) {
if (roleIDsAreEqual(userRoleId, BUILTIN_IDS.ADMIN)) {
return allRoles
}

Expand Down Expand Up @@ -515,7 +515,7 @@ export async function getAllRoles(appId?: string): Promise<RoleDoc[]> {
for (let builtinRoleId of externalBuiltinRoles) {
const builtinRole = builtinRoles[builtinRoleId]
const dbBuiltin = roles.filter(dbRole =>
compareRoleIds(dbRole._id!, builtinRoleId)
roleIDsAreEqual(dbRole._id!, builtinRoleId)
)[0]
if (dbBuiltin == null) {
roles.push(builtinRole || builtinRoles.BASIC)
Expand Down Expand Up @@ -574,9 +574,9 @@ export class AccessController {
if (
tryingRoleId == null ||
tryingRoleId === "" ||
compareRoleIds(tryingRoleId, BUILTIN_IDS.BUILDER) ||
compareRoleIds(userRoleId!, tryingRoleId) ||
compareRoleIds(userRoleId!, BUILTIN_IDS.BUILDER)
roleIDsAreEqual(tryingRoleId, BUILTIN_IDS.BUILDER) ||
roleIDsAreEqual(userRoleId!, tryingRoleId) ||
roleIDsAreEqual(userRoleId!, BUILTIN_IDS.BUILDER)
) {
return true
}
Expand Down
56 changes: 56 additions & 0 deletions packages/server/src/api/routes/tests/row.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,62 @@ describe.each([
})
})

describe("boolean column", () => {
beforeAll(async () => {
table = await config.api.table.save(
saveTableRequest({
schema: {
active: {
name: "active",
type: FieldType.BOOLEAN,
default: "true",
},
},
})
)
})

it("creates a new row with a default value successfully", async () => {
const row = await config.api.row.save(table._id!, {})
expect(row.active).toEqual(true)
})

it("does not use default value if value specified", async () => {
const row = await config.api.row.save(table._id!, {
active: false,
})
expect(row.active).toEqual(false)
})
})

describe("bigint column", () => {
beforeAll(async () => {
table = await config.api.table.save(
saveTableRequest({
schema: {
bigNumber: {
name: "bigNumber",
type: FieldType.BIGINT,
default: "1234567890",
},
},
})
)
})

it("creates a new row with a default value successfully", async () => {
const row = await config.api.row.save(table._id!, {})
expect(row.bigNumber).toEqual("1234567890")
})

it("does not use default value if value specified", async () => {
const row = await config.api.row.save(table._id!, {
bigNumber: "9876543210",
})
expect(row.bigNumber).toEqual("9876543210")
})
})

describe("bindings", () => {
describe("string column", () => {
beforeAll(async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/shared-core/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ const allowDefaultColumnByType: Record<FieldType, boolean> = {
[FieldType.STRING]: true,
[FieldType.OPTIONS]: true,
[FieldType.ARRAY]: true,
[FieldType.BIGINT]: true,
[FieldType.BOOLEAN]: true,

[FieldType.AUTO]: false,
[FieldType.INTERNAL]: false,
[FieldType.BARCODEQR]: false,
[FieldType.BIGINT]: false,
[FieldType.BOOLEAN]: false,
[FieldType.FORMULA]: false,
[FieldType.AI]: false,
[FieldType.ATTACHMENTS]: false,
Expand Down
14 changes: 14 additions & 0 deletions packages/types/src/documents/app/table/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ export interface ArrayFieldMetadata extends BaseFieldSchema {
default?: string[]
}

export interface BooleanFieldMetadata extends BaseFieldSchema {
type: FieldType.BOOLEAN
default?: string
}

export interface BigIntFieldMetadata extends BaseFieldSchema {
type: FieldType.BIGINT
default?: string
}

interface BaseFieldSchema extends UIFieldMetadata {
type: FieldType
name: string
Expand Down Expand Up @@ -214,6 +224,8 @@ interface OtherFieldMetadata extends BaseFieldSchema {
| FieldType.STRING
| FieldType.ARRAY
| FieldType.OPTIONS
| FieldType.BOOLEAN
| FieldType.BIGINT
>
}

Expand All @@ -233,6 +245,8 @@ export type FieldSchema =
| BBReferenceSingleFieldMetadata
| ArrayFieldMetadata
| OptionsFieldMetadata
| BooleanFieldMetadata
| BigIntFieldMetadata

export interface TableSchema {
[key: string]: FieldSchema
Expand Down

0 comments on commit 1bfb4ee

Please sign in to comment.