Merge branch 'master' into fix/self-host-missed-tenantId

This commit is contained in:
jvcalderon 2024-04-12 12:04:25 +02:00
commit 7ba041cdbf
9 changed files with 220 additions and 226 deletions

View File

@ -64,10 +64,11 @@ jobs:
- run: yarn --frozen-lockfile - run: yarn --frozen-lockfile
# Run build all the projects # Run build all the projects
- name: Build - name: Build OSS
run: | run: yarn build:oss
yarn build:oss - name: Build account portal
yarn build:account-portal run: yarn build:account-portal
if: ${{ env.IS_OSS_CONTRIBUTOR == 'false' }}
# Check the types of the projects built via esbuild # Check the types of the projects built via esbuild
- name: Check types - name: Check types
run: | run: |

View File

@ -488,7 +488,7 @@ services:
# do this. # do this.
url: "http://minio-service:9000" url: "http://minio-service:9000"
# -- How much storage to give Minio in its PersistentVolumeClaim. # -- How much storage to give Minio in its PersistentVolumeClaim.
storage: 100Mi storage: 2Gi
# -- If defined, storageClassName: <storageClass> If set to "-", # -- If defined, storageClassName: <storageClass> If set to "-",
# storageClassName: "", which disables dynamic provisioning If undefined # storageClassName: "", which disables dynamic provisioning If undefined
# (the default) or set to null, no storageClassName spec is set, choosing # (the default) or set to null, no storageClassName spec is set, choosing

View File

@ -51,7 +51,7 @@ http {
proxy_buffering off; proxy_buffering off;
set $csp_default "default-src 'self'"; set $csp_default "default-src 'self'";
set $csp_script "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://*.budibase.net https://cdn.budi.live https://js.intercomcdn.com https://widget.intercom.io https://d2l5prqdbvm3op.cloudfront.net"; set $csp_script "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://*.budibase.net https://cdn.budi.live https://js.intercomcdn.com https://widget.intercom.io https://d2l5prqdbvm3op.cloudfront.net https://us-assets.i.posthog.com";
set $csp_style "style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://fonts.googleapis.com https://rsms.me https://maxcdn.bootstrapcdn.com"; set $csp_style "style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://fonts.googleapis.com https://rsms.me https://maxcdn.bootstrapcdn.com";
set $csp_object "object-src 'none'"; set $csp_object "object-src 'none'";
set $csp_base_uri "base-uri 'self'"; set $csp_base_uri "base-uri 'self'";

View File

@ -1,5 +1,5 @@
{ {
"version": "2.23.0", "version": "2.23.4",
"npmClient": "yarn", "npmClient": "yarn",
"packages": [ "packages": [
"packages/*", "packages/*",

View File

@ -137,8 +137,12 @@
const activeTag = document.activeElement?.tagName.toLowerCase() const activeTag = document.activeElement?.tagName.toLowerCase()
const inCodeEditor = const inCodeEditor =
document.activeElement?.classList?.contains("cm-content") document.activeElement?.classList?.contains("cm-content")
const inPosthogSurvey =
document.activeElement?.classList?.[0]?.startsWith("PostHogSurvey")
if ( if (
(inCodeEditor || ["input", "textarea"].indexOf(activeTag) !== -1) && (inCodeEditor ||
inPosthogSurvey ||
["input", "textarea"].indexOf(activeTag) !== -1) &&
e.key !== "Escape" e.key !== "Escape"
) { ) {
return return

View File

@ -17,11 +17,9 @@ import {
Row, Row,
Table, Table,
UserCtx, UserCtx,
EmptyFilterOption,
} from "@budibase/types" } from "@budibase/types"
import sdk from "../../../sdk" import sdk from "../../../sdk"
import * as utils from "./utils" import * as utils from "./utils"
import { dataFilters } from "@budibase/shared-core"
import { import {
inputProcessing, inputProcessing,
outputProcessing, outputProcessing,
@ -33,17 +31,6 @@ export async function handleRequest<T extends Operation>(
tableId: string, tableId: string,
opts?: RunConfig opts?: RunConfig
): Promise<ExternalRequestReturnType<T>> { ): Promise<ExternalRequestReturnType<T>> {
// make sure the filters are cleaned up, no empty strings for equals, fuzzy or string
if (opts && opts.filters) {
opts.filters = sdk.rows.removeEmptyFilters(opts.filters)
}
if (
!dataFilters.hasFilters(opts?.filters) &&
opts?.filters?.onEmptyFilter === EmptyFilterOption.RETURN_NONE
) {
return [] as any
}
return new ExternalRequest<T>(operation, tableId, opts?.datasource).run( return new ExternalRequest<T>(operation, tableId, opts?.datasource).run(
opts || {} opts || {}
) )

View File

@ -6,9 +6,12 @@ import {
Datasource, Datasource,
EmptyFilterOption, EmptyFilterOption,
FieldType, FieldType,
RowSearchParams,
SearchFilters, SearchFilters,
Table, Table,
TableSchema,
} from "@budibase/types" } from "@budibase/types"
import _ from "lodash"
jest.unmock("mssql") jest.unmock("mssql")
@ -24,8 +27,8 @@ describe.each([
const config = setup.getConfig() const config = setup.getConfig()
let envCleanup: (() => void) | undefined let envCleanup: (() => void) | undefined
let table: Table
let datasource: Datasource | undefined let datasource: Datasource | undefined
let table: Table
beforeAll(async () => { beforeAll(async () => {
if (isSqs) { if (isSqs) {
@ -46,231 +49,217 @@ describe.each([
} }
}) })
async function createTable(schema: TableSchema) {
table = await config.api.table.save(
tableForDatasource(datasource, { schema })
)
}
async function createRows(rows: Record<string, any>[]) {
await Promise.all(rows.map(r => config.api.row.save(table._id!, r)))
}
class SearchAssertion {
constructor(private readonly query: RowSearchParams) {}
async toFind(expectedRows: any[]) {
const { rows: foundRows } = await config.api.row.search(table._id!, {
...this.query,
tableId: table._id!,
})
// eslint-disable-next-line jest/no-standalone-expect
expect(foundRows).toHaveLength(expectedRows.length)
// eslint-disable-next-line jest/no-standalone-expect
expect(foundRows).toEqual(
expect.arrayContaining(
expectedRows.map((expectedRow: any) =>
expect.objectContaining(
foundRows.find(foundRow => _.isMatch(foundRow, expectedRow))
)
)
)
)
}
async toFindNothing() {
await this.toFind([])
}
}
function expectSearch(query: Omit<RowSearchParams, "tableId">) {
return new SearchAssertion({ ...query, tableId: table._id! })
}
function expectQuery(query: SearchFilters) {
return expectSearch({ query })
}
describe("strings", () => { describe("strings", () => {
beforeEach(async () => { beforeAll(async () => {
table = await config.api.table.save( await createTable({
tableForDatasource(datasource, { name: { name: "name", type: FieldType.STRING },
schema: {
name: {
name: "name",
type: FieldType.STRING,
},
},
}) })
) await createRows([{ name: "foo" }, { name: "bar" }])
}) })
const rows = [{ name: "foo" }, { name: "bar" }] describe("misc", () => {
it("should return all if no query is passed", () =>
expectSearch({} as RowSearchParams).toFind([
{ name: "foo" },
{ name: "bar" },
]))
interface StringSearchTest { it("should return all if empty query is passed", () =>
query: SearchFilters expectQuery({}).toFind([{ name: "foo" }, { name: "bar" }]))
expected: (typeof rows)[number][]
}
const stringSearchTests: StringSearchTest[] = [ it("should return all if onEmptyFilter is RETURN_ALL", () =>
{ query: {}, expected: rows }, expectQuery({
{ onEmptyFilter: EmptyFilterOption.RETURN_ALL,
query: { onEmptyFilter: EmptyFilterOption.RETURN_ALL }, }).toFind([{ name: "foo" }, { name: "bar" }]))
expected: rows,
},
{
query: { onEmptyFilter: EmptyFilterOption.RETURN_NONE },
expected: [],
},
{ query: { string: { name: "foo" } }, expected: [rows[0]] },
{ query: { string: { name: "none" } }, expected: [] },
{ query: { fuzzy: { name: "oo" } }, expected: [rows[0]] },
{ query: { equal: { name: "foo" } }, expected: [rows[0]] },
{ query: { notEqual: { name: "foo" } }, expected: [rows[1]] },
{ query: { oneOf: { name: ["foo"] } }, expected: [rows[0]] },
]
it.each(stringSearchTests)( it("should return nothing if onEmptyFilter is RETURN_NONE", () =>
`should be able to run query: $query`, expectQuery({
async ({ query, expected }) => { onEmptyFilter: EmptyFilterOption.RETURN_NONE,
const savedRows = await Promise.all( }).toFindNothing())
rows.map(r => config.api.row.save(table._id!, r))
)
const { rows: foundRows } = await config.api.row.search(table._id!, {
tableId: table._id!,
query,
})
expect(foundRows).toEqual(
expect.arrayContaining(
expected.map(r =>
expect.objectContaining(savedRows.find(sr => sr.name === r.name)!)
)
)
)
}
)
}) })
describe("number", () => { describe("equal", () => {
beforeEach(async () => { it("successfully finds a row", () =>
table = await config.api.table.save( expectQuery({ equal: { name: "foo" } }).toFind([{ name: "foo" }]))
tableForDatasource(datasource, {
schema: { it("fails to find nonexistent row", () =>
age: { expectQuery({ equal: { name: "none" } }).toFindNothing())
name: "age",
type: FieldType.NUMBER,
},
},
})
)
}) })
const rows = [{ age: 1 }, { age: 10 }] describe("notEqual", () => {
it("successfully finds a row", () =>
expectQuery({ notEqual: { name: "foo" } }).toFind([{ name: "bar" }]))
interface NumberSearchTest { it("fails to find nonexistent row", () =>
query: SearchFilters expectQuery({ notEqual: { name: "bar" } }).toFind([{ name: "foo" }]))
expected: (typeof rows)[number][] })
}
describe("oneOf", () => {
const numberSearchTests: NumberSearchTest[] = [ it("successfully finds a row", () =>
{ query: {}, expected: rows }, expectQuery({ oneOf: { name: ["foo"] } }).toFind([{ name: "foo" }]))
{
query: { onEmptyFilter: EmptyFilterOption.RETURN_ALL }, it("fails to find nonexistent row", () =>
expected: rows, expectQuery({ oneOf: { name: ["none"] } }).toFindNothing())
}, })
{
query: { onEmptyFilter: EmptyFilterOption.RETURN_NONE }, describe("fuzzy", () => {
expected: [], it("successfully finds a row", () =>
}, expectQuery({ fuzzy: { name: "oo" } }).toFind([{ name: "foo" }]))
{ query: { equal: { age: 1 } }, expected: [rows[0]] },
{ query: { equal: { age: 2 } }, expected: [] }, it("fails to find nonexistent row", () =>
{ query: { notEqual: { age: 1 } }, expected: [rows[1]] }, expectQuery({ fuzzy: { name: "none" } }).toFindNothing())
{ query: { oneOf: { age: [1] } }, expected: [rows[0]] }, })
{ query: { range: { age: { low: 1, high: 5 } } }, expected: [rows[0]] }, })
{ query: { range: { age: { low: 0, high: 1 } } }, expected: [rows[0]] },
{ query: { range: { age: { low: 3, high: 4 } } }, expected: [] }, describe("numbers", () => {
{ query: { range: { age: { low: 0, high: 11 } } }, expected: rows }, beforeAll(async () => {
] await createTable({
age: { name: "age", type: FieldType.NUMBER },
it.each(numberSearchTests)( })
`should be able to run query: $query`, await createRows([{ age: 1 }, { age: 10 }])
async ({ query, expected }) => { })
const savedRows = await Promise.all(
rows.map(r => config.api.row.save(table._id!, r)) describe("equal", () => {
) it("successfully finds a row", () =>
const { rows: foundRows } = await config.api.row.search(table._id!, { expectQuery({ equal: { age: 1 } }).toFind([{ age: 1 }]))
tableId: table._id!,
query, it("fails to find nonexistent row", () =>
expectQuery({ equal: { age: 2 } }).toFindNothing())
})
describe("notEqual", () => {
it("successfully finds a row", () =>
expectQuery({ notEqual: { age: 1 } }).toFind([{ age: 10 }]))
it("fails to find nonexistent row", () =>
expectQuery({ notEqual: { age: 10 } }).toFind([{ age: 1 }]))
})
describe("oneOf", () => {
it("successfully finds a row", () =>
expectQuery({ oneOf: { age: [1] } }).toFind([{ age: 1 }]))
it("fails to find nonexistent row", () =>
expectQuery({ oneOf: { age: [2] } }).toFindNothing())
})
describe("range", () => {
it("successfully finds a row", () =>
expectQuery({
range: { age: { low: 1, high: 5 } },
}).toFind([{ age: 1 }]))
it("successfully finds multiple rows", () =>
expectQuery({
range: { age: { low: 1, high: 10 } },
}).toFind([{ age: 1 }, { age: 10 }]))
it("successfully finds a row with a high bound", () =>
expectQuery({
range: { age: { low: 5, high: 10 } },
}).toFind([{ age: 10 }]))
}) })
expect(foundRows).toEqual(
expect.arrayContaining(
expected.map(r =>
expect.objectContaining(savedRows.find(sr => sr.age === r.age)!)
)
)
)
}
)
}) })
describe("dates", () => { describe("dates", () => {
beforeEach(async () => { const JAN_1ST = "2020-01-01T00:00:00.000Z"
table = await config.api.table.save( const JAN_2ND = "2020-01-02T00:00:00.000Z"
tableForDatasource(datasource, { const JAN_5TH = "2020-01-05T00:00:00.000Z"
schema: { const JAN_10TH = "2020-01-10T00:00:00.000Z"
dob: {
name: "dob", beforeAll(async () => {
type: FieldType.DATETIME, await createTable({
}, dob: { name: "dob", type: FieldType.DATETIME },
},
})
)
}) })
const rows = [ await createRows([{ dob: JAN_1ST }, { dob: JAN_10TH }])
{ dob: new Date("2020-01-01").toISOString() }, })
{ dob: new Date("2020-01-10").toISOString() },
] describe("equal", () => {
it("successfully finds a row", () =>
interface DateSearchTest { expectQuery({ equal: { dob: JAN_1ST } }).toFind([{ dob: JAN_1ST }]))
query: SearchFilters
expected: (typeof rows)[number][] it("fails to find nonexistent row", () =>
} expectQuery({ equal: { dob: JAN_2ND } }).toFindNothing())
})
const dateSearchTests: DateSearchTest[] = [
{ query: {}, expected: rows }, describe("notEqual", () => {
{ it("successfully finds a row", () =>
query: { onEmptyFilter: EmptyFilterOption.RETURN_ALL }, expectQuery({ notEqual: { dob: JAN_1ST } }).toFind([{ dob: JAN_10TH }]))
expected: rows,
}, it("fails to find nonexistent row", () =>
{ expectQuery({ notEqual: { dob: JAN_10TH } }).toFind([{ dob: JAN_1ST }]))
query: { onEmptyFilter: EmptyFilterOption.RETURN_NONE }, })
expected: [],
}, describe("oneOf", () => {
{ it("successfully finds a row", () =>
query: { equal: { dob: new Date("2020-01-01").toISOString() } }, expectQuery({ oneOf: { dob: [JAN_1ST] } }).toFind([{ dob: JAN_1ST }]))
expected: [rows[0]],
}, it("fails to find nonexistent row", () =>
{ expectQuery({ oneOf: { dob: [JAN_2ND] } }).toFindNothing())
query: { equal: { dob: new Date("2020-01-02").toISOString() } }, })
expected: [],
}, describe("range", () => {
{ it("successfully finds a row", () =>
query: { notEqual: { dob: new Date("2020-01-01").toISOString() } }, expectQuery({
expected: [rows[1]], range: { dob: { low: JAN_1ST, high: JAN_5TH } },
}, }).toFind([{ dob: JAN_1ST }]))
{
query: { oneOf: { dob: [new Date("2020-01-01").toISOString()] } }, it("successfully finds multiple rows", () =>
expected: [rows[0]], expectQuery({
}, range: { dob: { low: JAN_1ST, high: JAN_10TH } },
{ }).toFind([{ dob: JAN_1ST }, { dob: JAN_10TH }]))
query: {
range: { it("successfully finds a row with a high bound", () =>
dob: { expectQuery({
low: new Date("2020-01-01").toISOString(), range: { dob: { low: JAN_5TH, high: JAN_10TH } },
high: new Date("2020-01-05").toISOString(), }).toFind([{ dob: JAN_10TH }]))
},
},
},
expected: [rows[0]],
},
{
query: {
range: {
dob: {
low: new Date("2020-01-01").toISOString(),
high: new Date("2020-01-10").toISOString(),
},
},
},
expected: rows,
},
{
query: {
range: {
dob: {
low: new Date("2020-01-05").toISOString(),
high: new Date("2020-01-10").toISOString(),
},
},
},
expected: [rows[1]],
},
]
it.each(dateSearchTests)(
`should be able to run query: $query`,
async ({ query, expected }) => {
const savedRows = await Promise.all(
rows.map(r => config.api.row.save(table._id!, r))
)
const { rows: foundRows } = await config.api.row.search(table._id!, {
tableId: table._id!,
query,
}) })
expect(foundRows).toEqual(
expect.arrayContaining(
expected.map(r =>
expect.objectContaining(savedRows.find(sr => sr.dob === r.dob)!)
)
)
)
}
)
}) })
}) })

View File

@ -334,6 +334,7 @@ class InternalBuilder {
if (filters.containsAny) { if (filters.containsAny) {
contains(filters.containsAny, true) contains(filters.containsAny, true)
} }
return query return query
} }

View File

@ -1,4 +1,5 @@
import { import {
EmptyFilterOption,
Row, Row,
RowSearchParams, RowSearchParams,
SearchFilters, SearchFilters,
@ -11,6 +12,7 @@ import { NoEmptyFilterStrings } from "../../../constants"
import * as sqs from "./search/sqs" import * as sqs from "./search/sqs"
import env from "../../../environment" import env from "../../../environment"
import { ExportRowsParams, ExportRowsResult } from "./search/types" import { ExportRowsParams, ExportRowsResult } from "./search/types"
import { dataFilters } from "@budibase/shared-core"
export { isValidFilter } from "../../../integrations/utils" export { isValidFilter } from "../../../integrations/utils"
@ -60,6 +62,16 @@ export async function search(
options: RowSearchParams options: RowSearchParams
): Promise<SearchResponse<Row>> { ): Promise<SearchResponse<Row>> {
const isExternalTable = isExternalTableID(options.tableId) const isExternalTable = isExternalTableID(options.tableId)
options.query = removeEmptyFilters(options.query || {})
if (
!dataFilters.hasFilters(options.query) &&
options.query.onEmptyFilter === EmptyFilterOption.RETURN_NONE
) {
return {
rows: [],
}
}
if (isExternalTable) { if (isExternalTable) {
return external.search(options) return external.search(options)
} else if (env.SQS_SEARCH_ENABLE) { } else if (env.SQS_SEARCH_ENABLE) {