Respond to PR comment.

This commit is contained in:
Sam Rose 2024-10-11 16:22:04 +01:00
parent 1ad371cd7a
commit b24c337834
No known key found for this signature in database
1 changed files with 9 additions and 9 deletions

View File

@ -96,10 +96,10 @@ export async function search(
// Enrich saved query with ephemeral query params. // Enrich saved query with ephemeral query params.
// We prevent searching on any fields that are saved as part of the query, as // We prevent searching on any fields that are saved as part of the query, as
// that could let users find rows they should not be allowed to access. // that could let users find rows they should not be allowed to access.
let query = await enrichSearchContext(view.query || {}, context) let viewQuery = await enrichSearchContext(view.query || {}, context)
query = dataFilters.buildQueryLegacy(query) || {} viewQuery = dataFilters.buildQueryLegacy(viewQuery) || {}
query = checkFilters(table, query) viewQuery = checkFilters(table, viewQuery)
delete query?.onEmptyFilter delete viewQuery?.onEmptyFilter
const sqsEnabled = await features.flags.isEnabled("SQS") const sqsEnabled = await features.flags.isEnabled("SQS")
const supportsLogicalOperators = const supportsLogicalOperators =
@ -125,20 +125,20 @@ export async function search(
const operator = key as Exclude<SearchFilterKey, LogicalOperator> const operator = key as Exclude<SearchFilterKey, LogicalOperator>
Object.keys(options.query[operator] || {}).forEach(field => { Object.keys(options.query[operator] || {}).forEach(field => {
if (!existingFields.includes(db.removeKeyNumbering(field))) { if (!existingFields.includes(db.removeKeyNumbering(field))) {
query[operator]![field] = options.query[operator]![field] viewQuery[operator]![field] = options.query[operator]![field]
} }
}) })
}) })
options.query = query options.query = viewQuery
} else { } else {
const conditions = query ? [query] : [] const conditions = viewQuery ? [viewQuery] : []
options.query = { options.query = {
$and: { $and: {
conditions: [...conditions, options.query], conditions: [...conditions, options.query],
}, },
} }
if (query.onEmptyFilter) { if (viewQuery.onEmptyFilter) {
options.query.onEmptyFilter = query.onEmptyFilter options.query.onEmptyFilter = viewQuery.onEmptyFilter
} }
} }
} }