Skip to content

Commit

Permalink
Merge branch 'develop' into budi-6158/allow_searching_users
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/pro
  • Loading branch information
adrinr committed May 15, 2023
2 parents ae180fc + 12b06c8 commit eaec5e7
Show file tree
Hide file tree
Showing 22 changed files with 459 additions and 61 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.6.8-alpha.7",
"version": "2.6.8-alpha.11",
"npmClient": "yarn",
"packages": [
"packages/backend-core",
Expand Down
82 changes: 82 additions & 0 deletions packages/backend-core/src/utils/tests/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as db from "../../db"
import { Header } from "../../constants"
import { newid } from "../../utils"
import env from "../../environment"
import { BBContext } from "@budibase/types"

describe("utils", () => {
const config = new DBTestConfiguration()
Expand Down Expand Up @@ -106,4 +107,85 @@ describe("utils", () => {
expect(actual).toBe(undefined)
})
})

describe("isServingBuilder", () => {
let ctx: BBContext

const expectResult = (result: boolean) =>
expect(utils.isServingBuilder(ctx)).toBe(result)

beforeEach(() => {
ctx = structures.koa.newContext()
})

it("returns true if current path is in builder", async () => {
ctx.path = "/builder/app/app_"
expectResult(true)
})

it("returns false if current path doesn't have '/' suffix", async () => {
ctx.path = "/builder/app"
expectResult(false)

ctx.path = "/xx"
expectResult(false)
})
})

describe("isServingBuilderPreview", () => {
let ctx: BBContext

const expectResult = (result: boolean) =>
expect(utils.isServingBuilderPreview(ctx)).toBe(result)

beforeEach(() => {
ctx = structures.koa.newContext()
})

it("returns true if current path is in builder preview", async () => {
ctx.path = "/app/preview/xx"
expectResult(true)
})

it("returns false if current path is not in builder preview", async () => {
ctx.path = "/builder"
expectResult(false)

ctx.path = "/xx"
expectResult(false)
})
})

describe("isPublicAPIRequest", () => {
let ctx: BBContext

const expectResult = (result: boolean) =>
expect(utils.isPublicApiRequest(ctx)).toBe(result)

beforeEach(() => {
ctx = structures.koa.newContext()
})

it("returns true if current path remains to public API", async () => {
ctx.path = "/api/public/v1/invoices"
expectResult(true)

ctx.path = "/api/public/v1"
expectResult(true)

ctx.path = "/api/public/v2"
expectResult(true)

ctx.path = "/api/public/v21"
expectResult(true)
})

it("returns false if current path doesn't remain to public API", async () => {
ctx.path = "/api/public"
expectResult(false)

ctx.path = "/xx"
expectResult(false)
})
})
})
28 changes: 18 additions & 10 deletions packages/backend-core/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { getAllApps, queryGlobalView } from "../db"
import {
Header,
MAX_VALID_DATE,
DocumentType,
SEPARATOR,
ViewName,
} from "../constants"
import { getAllApps } from "../db"
import { Header, MAX_VALID_DATE, DocumentType, SEPARATOR } from "../constants"
import env from "../environment"
import * as tenancy from "../tenancy"
import * as context from "../context"
Expand All @@ -23,7 +17,9 @@ const APP_PREFIX = DocumentType.APP + SEPARATOR
const PROD_APP_PREFIX = "/app/"

const BUILDER_PREVIEW_PATH = "/app/preview"
const BUILDER_REFERER_PREFIX = "/builder/app/"
const BUILDER_PREFIX = "/builder"
const BUILDER_APP_PREFIX = `${BUILDER_PREFIX}/app/`
const PUBLIC_API_PREFIX = "/api/public/v"

function confirmAppId(possibleAppId: string | undefined) {
return possibleAppId && possibleAppId.startsWith(APP_PREFIX)
Expand Down Expand Up @@ -69,6 +65,18 @@ export function isServingApp(ctx: Ctx) {
return false
}

export function isServingBuilder(ctx: Ctx): boolean {
return ctx.path.startsWith(BUILDER_APP_PREFIX)
}

export function isServingBuilderPreview(ctx: Ctx): boolean {
return ctx.path.startsWith(BUILDER_PREVIEW_PATH)
}

export function isPublicApiRequest(ctx: Ctx): boolean {
return ctx.path.startsWith(PUBLIC_API_PREFIX)
}

/**
* Given a request tries to find the appId, which can be located in various places
* @param {object} ctx The main request body to look through.
Expand Down Expand Up @@ -110,7 +118,7 @@ export async function getAppIdFromCtx(ctx: Ctx) {
// make sure this is performed after prod app url resolution, in case the
// referer header is present from a builder redirect
const referer = ctx.request.headers.referer
if (!appId && referer?.includes(BUILDER_REFERER_PREFIX)) {
if (!appId && referer?.includes(BUILDER_APP_PREFIX)) {
const refererId = parseAppIdFromUrl(ctx.request.headers.referer)
appId = confirmAppId(refererId)
}
Expand Down
16 changes: 13 additions & 3 deletions packages/bbui/src/Form/Core/DatePicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
export let ignoreTimezones = false
export let time24hr = false
export let range = false
export let flatpickr
export let useKeyboardShortcuts = true
const dispatch = createEventDispatcher()
const flatpickrId = `${uuid()}-wrapper`
let open = false
let flatpickr, flatpickrOptions
let flatpickrOptions
// Another classic flatpickr issue. Errors were randomly being thrown due to
// flatpickr internal code. Making sure that "destroy" is a valid function
Expand Down Expand Up @@ -59,6 +63,8 @@
dispatch("change", timestamp.toISOString())
}
},
onOpen: () => dispatch("open"),
onClose: () => dispatch("close"),
}
$: redrawOptions = {
Expand Down Expand Up @@ -113,12 +119,16 @@
const onOpen = () => {
open = true
document.addEventListener("keyup", clearDateOnBackspace)
if (useKeyboardShortcuts) {
document.addEventListener("keyup", clearDateOnBackspace)
}
}
const onClose = () => {
open = false
document.removeEventListener("keyup", clearDateOnBackspace)
if (useKeyboardShortcuts) {
document.removeEventListener("keyup", clearDateOnBackspace)
}
// Manually blur all input fields since flatpickr creates a second
// duplicate input field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,63 @@
$: isTrigger = block?.type === "TRIGGER"
$: isUpdateRow = stepId === ActionStepID.UPDATE_ROW
/**
* TODO - Remove after November 2023
* *******************************
* Code added to provide backwards compatibility between Values 1,2,3,4,5
* and the new JSON body.
*/
let deprecatedSchemaProperties
$: {
if (block?.stepId === "integromat" || block?.stepId === "zapier") {
deprecatedSchemaProperties = schemaProperties.filter(
prop => !prop[0].startsWith("value")
)
if (!deprecatedSchemaProperties.map(entry => entry[0]).includes("body")) {
deprecatedSchemaProperties.push([
"body",
{
title: "Payload",
type: "json",
},
])
}
} else {
deprecatedSchemaProperties = schemaProperties
}
}
/****************************************************/
const getInputData = (testData, blockInputs) => {
let newInputData = testData || blockInputs
if (block.event === "app:trigger" && !newInputData?.fields) {
newInputData = cloneDeep(blockInputs)
}
/**
* TODO - Remove after November 2023
* *******************************
* Code added to provide backwards compatibility between Values 1,2,3,4,5
* and the new JSON body.
*/
if (
(block?.stepId === "integromat" || block?.stepId === "zapier") &&
!newInputData?.body?.value
) {
let deprecatedValues = {
...newInputData,
}
delete deprecatedValues.url
delete deprecatedValues.body
newInputData = {
url: newInputData.url,
body: {
value: JSON.stringify(deprecatedValues),
},
}
}
/**********************************/
inputData = newInputData
setDefaultEnumValues()
}
Expand Down Expand Up @@ -239,7 +291,7 @@
</script>
<div class="fields">
{#each schemaProperties as [key, value]}
{#each deprecatedSchemaProperties as [key, value]}
<div class="block-field">
{#if key !== "fields"}
<Label
Expand All @@ -256,6 +308,28 @@
options={value.enum}
getOptionLabel={(x, idx) => (value.pretty ? value.pretty[idx] : x)}
/>
{:else if value.type === "json"}
<Editor
editorHeight="250"
editorWidth="448"
mode="json"
value={inputData[key]?.value}
on:change={e => {
/**
* TODO - Remove after November 2023
* *******************************
* Code added to provide backwards compatibility between Values 1,2,3,4,5
* and the new JSON body.
*/
delete inputData.value1
delete inputData.value2
delete inputData.value3
delete inputData.value4
delete inputData.value5
/***********************/
onChange(e, key)
}}
/>
{:else if value.customType === "column"}
<Select
on:change={e => onChange(e, key)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
export let rowCount
export let disableSorting = false
export let customPlaceholder = false
export let allowClickRows
const dispatch = createEventDispatcher()
Expand Down Expand Up @@ -110,6 +111,7 @@
{disableSorting}
{customPlaceholder}
showAutoColumns={!hideAutocolumns}
{allowClickRows}
on:clickrelationship={e => selectRelationship(e.detail)}
on:sort
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
export let tab = true
export let mode
export let editorHeight = 500
export let editorWidth = 640
// export let parameters = []
let width
Expand Down Expand Up @@ -169,7 +170,9 @@
{#if label}
<Label small>{label}</Label>
{/if}
<div style={`--code-mirror-height: ${editorHeight}px`}>
<div
style={`--code-mirror-height: ${editorHeight}px; --code-mirror-width: ${editorWidth}px;`}
>
<textarea tabindex="0" bind:this={refs.editor} readonly {value} />
</div>

Expand All @@ -183,6 +186,7 @@
}
div :global(.CodeMirror) {
width: var(--code-mirror-width) !important;
height: var(--code-mirror-height) !important;
border-radius: var(--border-radius-s);
font-family: var(--font-mono);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@
{#if filteredUsers?.length}
<div class="auth-entity-section">
<div class="auth-entity-header ">
<div class="auth-entity-header">
<div class="auth-entity-title">Users</div>
<div class="auth-entity-access-title">Access</div>
</div>
Expand Down Expand Up @@ -696,7 +696,7 @@
max-width: calc(100vw - 40px);
background: var(--background);
border-left: var(--border-light);
z-index: 3;
z-index: 999;
display: flex;
flex-direction: column;
overflow-y: auto;
Expand Down
Loading

0 comments on commit eaec5e7

Please sign in to comment.