Merge branch 'master' into feat/pick-relationship-fields
This commit is contained in:
commit
658d4b01b0
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
||||||
"version": "2.31.2",
|
"version": "2.31.3",
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"packages": [
|
"packages": [
|
||||||
"packages/*",
|
"packages/*",
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 516b27b74cbcb7069a25f5e738dc91c22d7c4538
|
Subproject commit c403315c5fa09a05dfd8fa4cd1890acfd8de0430
|
|
@ -10,7 +10,7 @@
|
||||||
export let inline = false
|
export let inline = false
|
||||||
export let disableCancel = false
|
export let disableCancel = false
|
||||||
export let autoFocus = true
|
export let autoFocus = true
|
||||||
export let zIndex = 999
|
export let zIndex = 99999
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
let visible = fixed || inline
|
let visible = fixed || inline
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 51a83b791a7a11b1d51c1fdb91f2ac246298279e
|
Subproject commit f2862855dcfeb4f4a28d6902daf411ec8f4a28e8
|
File diff suppressed because it is too large
Load Diff
|
@ -1,10 +1,10 @@
|
||||||
import { Ctx, Row } from "@budibase/types"
|
import { Ctx, Row, ViewV2 } from "@budibase/types"
|
||||||
|
|
||||||
import sdk from "../sdk"
|
import sdk from "../sdk"
|
||||||
import { Next } from "koa"
|
import { Next } from "koa"
|
||||||
import { getSourceId } from "../api/controllers/row/utils"
|
import { getSourceId } from "../api/controllers/row/utils"
|
||||||
|
|
||||||
export default async (ctx: Ctx<Row>, next: Next) => {
|
export default async (ctx: Ctx<Row, Row>, next: Next) => {
|
||||||
const { body } = ctx.request
|
const { body } = ctx.request
|
||||||
const viewId = getSourceId(ctx).viewId ?? body._viewId
|
const viewId = getSourceId(ctx).viewId ?? body._viewId
|
||||||
|
|
||||||
|
@ -14,22 +14,31 @@ export default async (ctx: Ctx<Row>, next: Next) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't need to trim delete requests
|
// don't need to trim delete requests
|
||||||
if (ctx?.method?.toLowerCase() !== "delete") {
|
const trimFields = ctx?.method?.toLowerCase() !== "delete"
|
||||||
await trimViewFields(ctx.request.body, viewId)
|
if (!trimFields) {
|
||||||
|
return next()
|
||||||
}
|
}
|
||||||
|
|
||||||
return next()
|
const view = await sdk.views.get(viewId)
|
||||||
|
ctx.request.body = await trimNonViewFields(ctx.request.body, view, "WRITE")
|
||||||
|
|
||||||
|
await next()
|
||||||
|
|
||||||
|
ctx.body = await trimNonViewFields(ctx.body, view, "READ")
|
||||||
}
|
}
|
||||||
|
|
||||||
// have to mutate the koa context, can't return
|
// have to mutate the koa context, can't return
|
||||||
export async function trimViewFields(body: Row, viewId: string): Promise<void> {
|
export async function trimNonViewFields(
|
||||||
const view = await sdk.views.get(viewId)
|
row: Row,
|
||||||
const allowedKeys = sdk.views.allowedFields(view)
|
view: ViewV2,
|
||||||
|
permission: "WRITE" | "READ"
|
||||||
|
): Promise<Row> {
|
||||||
|
row = { ...row }
|
||||||
|
const allowedKeys = sdk.views.allowedFields(view, permission)
|
||||||
// have to mutate the context, can't update reference
|
// have to mutate the context, can't update reference
|
||||||
const toBeRemoved = Object.keys(body).filter(
|
const toBeRemoved = Object.keys(row).filter(key => !allowedKeys.includes(key))
|
||||||
key => !allowedKeys.includes(key)
|
|
||||||
)
|
|
||||||
for (let removeKey of toBeRemoved) {
|
for (let removeKey of toBeRemoved) {
|
||||||
delete body[removeKey]
|
delete row[removeKey]
|
||||||
}
|
}
|
||||||
|
return row
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import {
|
||||||
PROTECTED_EXTERNAL_COLUMNS,
|
PROTECTED_EXTERNAL_COLUMNS,
|
||||||
PROTECTED_INTERNAL_COLUMNS,
|
PROTECTED_INTERNAL_COLUMNS,
|
||||||
} from "@budibase/shared-core"
|
} from "@budibase/shared-core"
|
||||||
import { cloneDeep } from "lodash/fp"
|
|
||||||
|
|
||||||
import * as utils from "../../../db/utils"
|
import * as utils from "../../../db/utils"
|
||||||
import { isExternalTableID } from "../../../integrations/utils"
|
import { isExternalTableID } from "../../../integrations/utils"
|
||||||
|
@ -139,14 +138,20 @@ export async function remove(viewId: string): Promise<ViewV2> {
|
||||||
return pickApi(tableId).remove(viewId)
|
return pickApi(tableId).remove(viewId)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function allowedFields(view: View | ViewV2) {
|
export function allowedFields(
|
||||||
|
view: View | ViewV2,
|
||||||
|
permission: "WRITE" | "READ"
|
||||||
|
) {
|
||||||
return [
|
return [
|
||||||
...Object.keys(view?.schema || {}).filter(key => {
|
...Object.keys(view?.schema || {}).filter(key => {
|
||||||
if (!isV2(view)) {
|
if (!isV2(view)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
const fieldSchema = view.schema![key]
|
const fieldSchema = view.schema![key]
|
||||||
return fieldSchema.visible && !fieldSchema.readonly
|
if (permission === "WRITE") {
|
||||||
|
return fieldSchema.visible && !fieldSchema.readonly
|
||||||
|
}
|
||||||
|
return fieldSchema.visible
|
||||||
}),
|
}),
|
||||||
...PROTECTED_EXTERNAL_COLUMNS,
|
...PROTECTED_EXTERNAL_COLUMNS,
|
||||||
...PROTECTED_INTERNAL_COLUMNS,
|
...PROTECTED_INTERNAL_COLUMNS,
|
||||||
|
@ -157,18 +162,19 @@ export async function enrichSchema(
|
||||||
view: ViewV2,
|
view: ViewV2,
|
||||||
tableSchema: TableSchema
|
tableSchema: TableSchema
|
||||||
): Promise<ViewV2Enriched> {
|
): Promise<ViewV2Enriched> {
|
||||||
let schema = cloneDeep(tableSchema)
|
let schema: TableSchema = {}
|
||||||
|
|
||||||
const anyViewOrder = Object.values(view.schema || {}).some(
|
const anyViewOrder = Object.values(view.schema || {}).some(
|
||||||
ui => ui.order != null
|
ui => ui.order != null
|
||||||
)
|
)
|
||||||
for (const key of Object.keys(schema)) {
|
for (const key of Object.keys(tableSchema).filter(
|
||||||
|
key => tableSchema[key].visible !== false
|
||||||
|
)) {
|
||||||
// if nothing specified in view, then it is not visible
|
// if nothing specified in view, then it is not visible
|
||||||
const ui = view.schema?.[key] || { visible: false }
|
const ui = view.schema?.[key] || { visible: false }
|
||||||
schema[key] = {
|
schema[key] = {
|
||||||
...schema[key],
|
...tableSchema[key],
|
||||||
...ui,
|
...ui,
|
||||||
order: anyViewOrder ? ui?.order ?? undefined : schema[key].order,
|
order: anyViewOrder ? ui?.order ?? undefined : tableSchema[key].order,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,14 +103,6 @@ describe("table sdk", () => {
|
||||||
type: "number",
|
type: "number",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
hiddenField: {
|
|
||||||
type: "string",
|
|
||||||
name: "hiddenField",
|
|
||||||
visible: false,
|
|
||||||
constraints: {
|
|
||||||
type: "string",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -145,10 +137,6 @@ describe("table sdk", () => {
|
||||||
...basicTable.schema.id,
|
...basicTable.schema.id,
|
||||||
visible: true,
|
visible: true,
|
||||||
},
|
},
|
||||||
hiddenField: {
|
|
||||||
...basicTable.schema.hiddenField,
|
|
||||||
visible: false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -183,10 +171,6 @@ describe("table sdk", () => {
|
||||||
...basicTable.schema.id,
|
...basicTable.schema.id,
|
||||||
visible: false,
|
visible: false,
|
||||||
},
|
},
|
||||||
hiddenField: {
|
|
||||||
...basicTable.schema.hiddenField,
|
|
||||||
visible: false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -211,7 +195,6 @@ describe("table sdk", () => {
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
...view,
|
...view,
|
||||||
schema: {
|
schema: {
|
||||||
...basicTable.schema,
|
|
||||||
name: {
|
name: {
|
||||||
type: "string",
|
type: "string",
|
||||||
name: "name",
|
name: "name",
|
||||||
|
@ -266,7 +249,6 @@ describe("table sdk", () => {
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
...view,
|
...view,
|
||||||
schema: {
|
schema: {
|
||||||
...basicTable.schema,
|
|
||||||
name: {
|
name: {
|
||||||
type: "string",
|
type: "string",
|
||||||
name: "name",
|
name: "name",
|
||||||
|
|
Loading…
Reference in New Issue