1
0
Fork 0
mirror of synced 2024-09-10 06:26:02 +12:00

PR comments

This commit is contained in:
Adria Navarro 2024-05-29 15:50:10 +02:00
parent 05544d3082
commit 2d5ecb6e3e
2 changed files with 27 additions and 27 deletions

View file

@ -386,7 +386,8 @@ describe.each([
await config.api.viewV2.create(newView, { await config.api.viewV2.create(newView, {
status: 400, status: 400,
body: { body: {
message: 'Field "name" cannot be readonly and not visible', message:
'Field "name" must be visible if you want to make it readonly',
status: 400, status: 400,
}, },
}) })
@ -686,7 +687,7 @@ describe.each([
}) })
mocks.licenses.useCloudFree() mocks.licenses.useCloudFree()
await config.api.viewV2.create(view, { await config.api.viewV2.update(view, {
status: 400, status: 400,
body: { body: {
message: "Readonly fields are not enabled for your tenant", message: "Readonly fields are not enabled for your tenant",

View file

@ -43,37 +43,36 @@ async function guardViewSchema(
return return
} }
const table = await sdk.tables.getTable(tableId) const table = await sdk.tables.getTable(tableId)
if (viewSchema) {
for (const field of Object.keys(viewSchema)) { for (const field of Object.keys(viewSchema)) {
const tableSchemaField = table.schema[field] const tableSchemaField = table.schema[field]
if (!tableSchemaField) { if (!tableSchemaField) {
throw new HTTPError(
`Field "${field}" is not valid for the requested table`,
400
)
}
if (viewSchema[field].readonly) {
if (!(await features.isViewReadonlyColumnsEnabled())) {
throw new HTTPError( throw new HTTPError(
`Field "${field}" is not valid for the requested table`, `Readonly fields are not enabled for your tenant`,
400 400
) )
} }
if (viewSchema[field].readonly) { if (isRequired(tableSchemaField.constraints)) {
if (!(await features.isViewReadonlyColumnsEnabled())) { throw new HTTPError(
throw new HTTPError( `Field "${field}" cannot be readonly as it is a required field`,
`Readonly fields are not enabled for your tenant`, 400
400 )
) }
}
if (isRequired(tableSchemaField.constraints)) { if (!viewSchema[field].visible) {
throw new HTTPError( throw new HTTPError(
`Field "${field}" cannot be readonly as it is a required field`, `Field "${field}" must be visible if you want to make it readonly`,
400 400
) )
}
if (!viewSchema[field].visible) {
throw new HTTPError(
`Field "${field}" cannot be readonly and not visible`,
400
)
}
} }
} }
} }