Fix trimming extra view fields and ensure empty views allow nothing
This commit is contained in:
parent
d1b3d033dd
commit
a7b37a4550
|
@ -23,7 +23,7 @@ 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") {
|
if (ctx?.method?.toLowerCase() !== "delete") {
|
||||||
await trimViewFields(ctx.request.body, viewId, tableId)
|
await trimViewFields(ctx.request.body, viewId)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.params.sourceId = tableId
|
ctx.params.sourceId = tableId
|
||||||
|
@ -35,17 +35,10 @@ export default async (ctx: Ctx<Row>, next: Next) => {
|
||||||
export async function trimViewFields<T extends Row>(
|
export async function trimViewFields<T extends Row>(
|
||||||
body: Row,
|
body: Row,
|
||||||
viewId: string,
|
viewId: string,
|
||||||
tableId: string
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const view = await sdk.views.get(viewId)
|
const view = await sdk.views.get(viewId)
|
||||||
if (!view?.schema || !Object.keys(view.schema).length) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const table = await sdk.tables.getTable(tableId)
|
|
||||||
const { schema } = sdk.views.enrichSchema(view!, table.schema)
|
|
||||||
const allowedKeys = [
|
const allowedKeys = [
|
||||||
...Object.keys(schema),
|
...Object.keys(view?.schema || {}),
|
||||||
...db.CONSTANT_EXTERNAL_ROW_COLS,
|
...db.CONSTANT_EXTERNAL_ROW_COLS,
|
||||||
...db.CONSTANT_INTERNAL_ROW_COLS,
|
...db.CONSTANT_INTERNAL_ROW_COLS,
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue