Skip to content

Commit

Permalink
Merge branch 'v3-ui' into feature/automation-branching-ux
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr authored Oct 29, 2024
2 parents 8336f25 + 3f00655 commit 23c655e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
31 changes: 20 additions & 11 deletions packages/backend-core/src/security/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ export function validInherits(
export function builtinRoleToNumber(id: string) {
const builtins = getBuiltinRoles()
const MAX = Object.values(builtins).length + 1
if (id === BUILTIN_IDS.ADMIN || id === BUILTIN_IDS.BUILDER) {
if (
compareRoleIds(id, BUILTIN_IDS.ADMIN) ||

Check failure on line 241 in packages/backend-core/src/security/roles.ts

View workflow job for this annotation

GitHub Actions / lint

'compareRoleIds' is not defined
compareRoleIds(id, BUILTIN_IDS.BUILDER)

Check failure on line 242 in packages/backend-core/src/security/roles.ts

View workflow job for this annotation

GitHub Actions / lint

'compareRoleIds' is not defined
) {
return MAX
}
let role = builtins[id],
Expand Down Expand Up @@ -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
const highestBuiltin: number | undefined = role.inherits
.map(roleId => {
const foundRole = hierarchy.find(role => role._id === roleId)
const foundRole = hierarchy.find(role =>
compareRoleIds(role._id!, roleId)

Check failure on line 281 in packages/backend-core/src/security/roles.ts

View workflow job for this annotation

GitHub Actions / lint

'compareRoleIds' is not defined
)
if (foundRole) {
return findNumber(foundRole) + 1
}
Expand Down Expand Up @@ -398,7 +403,7 @@ async function getAllUserRoles(
): Promise<RoleDoc[]> {
const allRoles = await getAllRoles()
// admins have access to all roles
if (userRoleId === BUILTIN_IDS.ADMIN) {
if (compareRoleIds(userRoleId, BUILTIN_IDS.ADMIN)) {

Check failure on line 406 in packages/backend-core/src/security/roles.ts

View workflow job for this annotation

GitHub Actions / lint

'compareRoleIds' is not defined
return allRoles
}

Expand Down Expand Up @@ -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)
for (let builtinRoleId of externalBuiltinRoles) {
const builtinRole = builtinRoles[builtinRoleId]
const dbBuiltin = roles.filter(
dbRole =>
getExternalRoleID(dbRole._id!, dbRole.version) === builtinRoleId
const dbBuiltin = roles.filter(dbRole =>
compareRoleIds(dbRole._id!, builtinRoleId)

Check failure on line 518 in packages/backend-core/src/security/roles.ts

View workflow job for this annotation

GitHub Actions / lint

'compareRoleIds' is not defined
)[0]
if (dbBuiltin == null) {
roles.push(builtinRole || builtinRoles.BASIC)
} else {
// remove role and all back after combining with the builtin
roles = roles.filter(role => role._id !== dbBuiltin._id)
dbBuiltin._id = getExternalRoleID(dbBuiltin._id!, dbBuiltin.version)
roles.push(Object.assign(builtinRole, dbBuiltin))
dbBuiltin._id = getExternalRoleID(builtinRole._id!, dbBuiltin.version)
roles.push({
...builtinRole,
...dbBuiltin,
name: builtinRole.name,
_id: getExternalRoleID(builtinRole._id!, builtinRole.version),
})
}
}
// check permissions
Expand Down Expand Up @@ -565,9 +574,9 @@ export class AccessController {
if (
tryingRoleId == null ||
tryingRoleId === "" ||
tryingRoleId === userRoleId ||
tryingRoleId === BUILTIN_IDS.BUILDER ||
userRoleId === BUILTIN_IDS.BUILDER
compareRoleIds(tryingRoleId, BUILTIN_IDS.BUILDER) ||

Check failure on line 577 in packages/backend-core/src/security/roles.ts

View workflow job for this annotation

GitHub Actions / lint

'compareRoleIds' is not defined
compareRoleIds(userRoleId!, tryingRoleId) ||

Check failure on line 578 in packages/backend-core/src/security/roles.ts

View workflow job for this annotation

GitHub Actions / lint

'compareRoleIds' is not defined
compareRoleIds(userRoleId!, BUILTIN_IDS.BUILDER)

Check failure on line 579 in packages/backend-core/src/security/roles.ts

View workflow job for this annotation

GitHub Actions / lint

'compareRoleIds' is not defined
) {
return true
}
Expand Down
13 changes: 13 additions & 0 deletions packages/server/src/api/routes/tests/row.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,12 +763,25 @@ describe.each([
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 () => {
const row = await config.api.row.save(table._id!, {
food: ["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", () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/server/src/utilities/rowProcessor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ async function processDefaultValues(table: Table, row: Row) {
}

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[]
if (Array.isArray(schema.default)) {
processed = schema.default.map(val => processStringSync(val, ctx))
Expand Down

0 comments on commit 23c655e

Please sign in to comment.