Browse Source

Merge pull request #6974 from nocodb/nc-fix/6943-apply-filter-validation-for-v1-apis

fix: Apply filter validation on v1 list api
pull/6994/head
Raju Udava 12 months ago committed by GitHub
parent
commit
9fedf1498e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/nocodb/src/db/conditionV2.ts
  2. 5
      packages/nocodb/src/helpers/getAst.ts
  3. 3
      packages/nocodb/src/services/datas.service.ts

2
packages/nocodb/src/db/conditionV2.ts

@ -342,7 +342,7 @@ const parseConditionV2 = async (
return (qbP: Knex.QueryBuilder) => { return (qbP: Knex.QueryBuilder) => {
if (filter.comparison_op in negatedMapping) if (filter.comparison_op in negatedMapping)
qbP.where((qb) => qbP.where((qb) =>
qbP qb
.whereNotIn(childColumn.column_name, selectQb) .whereNotIn(childColumn.column_name, selectQb)
.orWhereNull(childColumn.column_name), .orWhereNull(childColumn.column_name),
); );

5
packages/nocodb/src/helpers/getAst.ts

@ -68,7 +68,10 @@ const getAst = async ({
fields = Array.isArray(fields) ? fields : fields.split(','); fields = Array.isArray(fields) ? fields : fields.split(',');
if (throwErrorIfInvalidParams) { if (throwErrorIfInvalidParams) {
const colAliasMap = await model.getColAliasMapping(); const colAliasMap = await model.getColAliasMapping();
const invalidFields = fields.filter((f) => !colAliasMap[f]); const aliasColMap = await model.getAliasColMapping();
const invalidFields = fields.filter(
(f) => !colAliasMap[f] && !aliasColMap[f],
);
if (invalidFields.length) { if (invalidFields.length) {
NcError.unprocessableEntity( NcError.unprocessableEntity(
`Following fields are invalid: ${invalidFields.join(', ')}`, `Following fields are invalid: ${invalidFields.join(', ')}`,

3
packages/nocodb/src/services/datas.service.ts

@ -27,6 +27,7 @@ export class DatasService {
model, model,
view, view,
query: param.query, query: param.query,
throwErrorIfInvalidParams: true,
}); });
} }
@ -51,7 +52,7 @@ export class DatasService {
dbDriver: await NcConnectionMgrv2.get(source), dbDriver: await NcConnectionMgrv2.get(source),
}); });
const countArgs: any = { ...param.query }; const countArgs: any = { ...param.query, throwErrorIfInvalidParams: true };
try { try {
countArgs.filterArr = JSON.parse(countArgs.filterArrJson); countArgs.filterArr = JSON.parse(countArgs.filterArrJson);
} catch (e) {} } catch (e) {}

Loading…
Cancel
Save