option.email}
- getOptionValue={option => option._id}
- {disabled}
-/>
+
+ option.email}
+ getOptionValue={option => option._id}
+ {disabled}
+ />
+
diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts
index c3d1f2cb47..7f99105ea4 100644
--- a/packages/server/src/api/controllers/row/index.ts
+++ b/packages/server/src/api/controllers/row/index.ts
@@ -2,7 +2,7 @@ import stream from "stream"
import archiver from "archiver"
import { quotas } from "@budibase/pro"
-import { objectStore } from "@budibase/backend-core"
+import { objectStore, context } from "@budibase/backend-core"
import * as internal from "./internal"
import * as external from "./external"
import { isExternalTableID } from "../../../integrations/utils"
@@ -198,8 +198,21 @@ export async function destroy(ctx: UserCtx) {
export async function search(ctx: Ctx) {
const tableId = utils.getTableId(ctx)
+ // Current user context for bindable search
+ const { _id, _rev, firstName, lastName, email, status, roleId } = ctx.user
+
+ await context.ensureSnippetContext()
+
+ const enrichedQuery = await utils.enrichSearchContext(
+ { ...ctx.request.body.query },
+ {
+ user: { _id, _rev, firstName, lastName, email, status, roleId },
+ }
+ )
+
const searchParams: RowSearchParams = {
...ctx.request.body,
+ query: enrichedQuery,
tableId,
}
diff --git a/packages/server/src/api/controllers/row/utils/utils.ts b/packages/server/src/api/controllers/row/utils/utils.ts
index f387a468cf..503f139783 100644
--- a/packages/server/src/api/controllers/row/utils/utils.ts
+++ b/packages/server/src/api/controllers/row/utils/utils.ts
@@ -7,6 +7,8 @@ import {
FieldType,
RelationshipsJson,
Row,
+ SearchRowRequest,
+ SearchRowResponse,
Table,
UserCtx,
} from "@budibase/types"
@@ -22,7 +24,7 @@ import {
getInternalRowId,
} from "./basic"
import sdk from "../../../../sdk"
-
+import { processStringSync } from "@budibase/string-templates"
import validateJs from "validate.js"
validateJs.extend(validateJs.validators.datetime, {
@@ -187,3 +189,40 @@ export async function sqlOutputProcessing(
export function isUserMetadataTable(tableId: string) {
return tableId === InternalTables.USER_METADATA
}
+
+export async function enrichSearchContext(
+ fields: Record,
+ inputs = {},
+ helpers = true
+): Promise> {
+ const enrichedQuery: Record = {}
+ if (!fields || !inputs) {
+ return enrichedQuery
+ }
+ const parameters = { ...inputs }
+ // enrich the fields with dynamic parameters
+ for (let key of Object.keys(fields)) {
+ if (fields[key] == null) {
+ continue
+ }
+ if (typeof fields[key] === "object") {
+ // enrich nested fields object
+ enrichedQuery[key] = await enrichSearchContext(
+ fields[key],
+ parameters,
+ helpers
+ )
+ } else if (typeof fields[key] === "string") {
+ // enrich string value as normal
+ enrichedQuery[key] = processStringSync(fields[key], parameters, {
+ noEscaping: true,
+ noHelpers: !helpers,
+ escapeNewlines: true,
+ })
+ } else {
+ enrichedQuery[key] = fields[key]
+ }
+ }
+
+ return enrichedQuery
+}
diff --git a/packages/server/src/api/controllers/row/views.ts b/packages/server/src/api/controllers/row/views.ts
index 2644446d82..18953ebe88 100644
--- a/packages/server/src/api/controllers/row/views.ts
+++ b/packages/server/src/api/controllers/row/views.ts
@@ -9,7 +9,8 @@ import {
} from "@budibase/types"
import { dataFilters } from "@budibase/shared-core"
import sdk from "../../../sdk"
-import { db } from "@budibase/backend-core"
+import { db, context } from "@budibase/backend-core"
+import { enrichSearchContext, userSearchFromContext } from "./utils"
export async function searchView(
ctx: UserCtx
@@ -56,10 +57,19 @@ export async function searchView(
})
}
+ // Current user search context.
+ const { _id, _rev, firstName, lastName, email, status, roleId } = ctx.user
+
+ await context.ensureSnippetContext()
+
+ const enrichedQuery = await enrichSearchContext(query, {
+ user: { _id, _rev, firstName, lastName, email, status, roleId },
+ })
+
const searchOptions: RequiredKeys &
RequiredKeys> = {
tableId: view.tableId,
- query,
+ query: enrichedQuery,
fields: viewFields,
...getSortOptions(body, view),
limit: body.limit,