Merge branch 'csp-whitelist' of github.com:Budibase/budibase into csp-whitelist
This commit is contained in:
commit
95e3f17d8f
|
@ -1,15 +1,16 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import "@spectrum-css/switch/dist/index-vars.css"
|
||||
import { createEventDispatcher } from "svelte"
|
||||
|
||||
export let value = false
|
||||
export let id = null
|
||||
export let text = null
|
||||
export let disabled = false
|
||||
export let value: boolean = false
|
||||
export let id: string | null = null
|
||||
export let text: string | null = null
|
||||
export let disabled: boolean = false
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
const onChange = event => {
|
||||
dispatch("change", event.target.checked)
|
||||
const onChange = (event: Event) => {
|
||||
const target = event.target as HTMLInputElement
|
||||
dispatch("change", target.checked)
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -1,23 +1,29 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import Field from "./Field.svelte"
|
||||
import Switch from "./Core/Switch.svelte"
|
||||
import { createEventDispatcher } from "svelte"
|
||||
|
||||
export let value = undefined
|
||||
export let label = null
|
||||
export let labelPosition = "above"
|
||||
export let text = undefined
|
||||
export let disabled = false
|
||||
export let error = null
|
||||
export let helpText = null
|
||||
export let value: boolean | null | undefined = undefined
|
||||
export let label: string | undefined = undefined
|
||||
export let labelPosition: "above" = "above"
|
||||
export let text: string | undefined = undefined
|
||||
export let disabled: boolean | undefined = false
|
||||
export let error: string | undefined = undefined
|
||||
export let helpText: string | undefined = undefined
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
const onChange = e => {
|
||||
const onChange = (e: CustomEvent<boolean>) => {
|
||||
value = e.detail
|
||||
dispatch("change", e.detail)
|
||||
}
|
||||
</script>
|
||||
|
||||
<Field {helpText} {label} {labelPosition} {error}>
|
||||
<Switch {error} {disabled} {text} {value} on:change={onChange} on:click />
|
||||
<Switch
|
||||
{disabled}
|
||||
{text}
|
||||
value={value ?? undefined}
|
||||
on:change={onChange}
|
||||
on:click
|
||||
/>
|
||||
</Field>
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import { Select } from "@budibase/bbui"
|
||||
import { roles } from "@/stores/builder"
|
||||
|
||||
export let value
|
||||
export let error
|
||||
export let placeholder = null
|
||||
export let autoWidth = false
|
||||
export let value: string
|
||||
export let error: string | undefined = undefined
|
||||
export let placeholder: string | undefined = undefined
|
||||
export let autoWidth: boolean = false
|
||||
</script>
|
||||
|
||||
<Select
|
||||
bind:value
|
||||
on:change
|
||||
options={$roles}
|
||||
getOptionLabel={role => role.uiMetadata.displayName}
|
||||
getOptionLabel={role => role.uiMetadata?.displayName}
|
||||
getOptionValue={role => role._id}
|
||||
getOptionColour={role => role.uiMetadata.color}
|
||||
getOptionColour={role => role.uiMetadata?.color}
|
||||
{placeholder}
|
||||
{error}
|
||||
{autoWidth}
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import { Label, notifications } from "@budibase/bbui"
|
||||
import { permissions } from "@/stores/builder"
|
||||
import { Constants } from "@budibase/frontend-core"
|
||||
import RoleSelect from "@/components/design/settings/controls/RoleSelect.svelte"
|
||||
import { PermissionLevel, type Query } from "@budibase/types"
|
||||
|
||||
export let query
|
||||
export let query: Query
|
||||
export let label
|
||||
|
||||
$: getPermissions(query)
|
||||
|
||||
let roleId, loaded, fetched
|
||||
let roleId: string, loaded: boolean, fetched: Query | undefined
|
||||
|
||||
async function updateRole(role, id) {
|
||||
async function updateRole(role: string) {
|
||||
try {
|
||||
roleId = role
|
||||
const queryId = query?._id || id
|
||||
const queryId = query._id
|
||||
if (roleId && queryId) {
|
||||
for (let level of ["read", "write"]) {
|
||||
for (let level of [PermissionLevel.READ, PermissionLevel.WRITE]) {
|
||||
await permissions.save({
|
||||
level,
|
||||
role,
|
||||
|
@ -29,7 +30,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
async function getPermissions(queryToFetch) {
|
||||
async function getPermissions(queryToFetch: Query) {
|
||||
if (fetched?._id === queryToFetch?._id) {
|
||||
loaded = true
|
||||
return
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<script>
|
||||
<script lang="ts" generics="O">
|
||||
import {
|
||||
Icon,
|
||||
ActionButton,
|
||||
|
@ -15,30 +15,30 @@
|
|||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
export let defaults = undefined
|
||||
export let object = defaults || {}
|
||||
export let activity = {}
|
||||
export let readOnly = false
|
||||
export let noAddButton = false
|
||||
export let name = ""
|
||||
export let headings = false
|
||||
export let options = undefined
|
||||
export let toggle = false
|
||||
export let keyPlaceholder = "Key"
|
||||
export let valuePlaceholder = "Value"
|
||||
export let valueHeading = ""
|
||||
export let keyHeading = ""
|
||||
export let tooltip = ""
|
||||
export let menuItems = []
|
||||
export let showMenu = false
|
||||
export let bindings = []
|
||||
export let allowHelpers = true
|
||||
export let defaults: Record<string, string> | undefined = undefined
|
||||
export let object: Record<string, string> = defaults || {}
|
||||
export let activity: Record<string, boolean> = {}
|
||||
export let readOnly: boolean = false
|
||||
export let noAddButton: boolean = false
|
||||
export let name: string = ""
|
||||
export let headings: boolean = false
|
||||
export let options: O[] | undefined = undefined
|
||||
export let toggle: boolean = false
|
||||
export let keyPlaceholder: string = "Key"
|
||||
export let valuePlaceholder: string = "Value"
|
||||
export let valueHeading: string = ""
|
||||
export let keyHeading: string = ""
|
||||
export let tooltip: string = ""
|
||||
export let menuItems: any[] = []
|
||||
export let showMenu: boolean = false
|
||||
export let bindings: any[] = []
|
||||
export let allowHelpers: boolean = true
|
||||
export let customButtonText = null
|
||||
export let keyBindings = false
|
||||
export let allowJS = false
|
||||
export let actionButtonDisabled = false
|
||||
export let compare = (option, value) => option === value
|
||||
export let context = null
|
||||
export let keyBindings: boolean = false
|
||||
export let allowJS: boolean = false
|
||||
export let actionButtonDisabled: boolean = false
|
||||
export let compare = (option: O, value: O) => option === value
|
||||
export let context: any = null
|
||||
|
||||
let fields = Object.entries(object || {}).map(([name, value]) => ({
|
||||
name,
|
||||
|
@ -46,27 +46,32 @@
|
|||
}))
|
||||
let fieldActivity = buildFieldActivity(activity)
|
||||
|
||||
$: fullObject = fields.reduce((acc, next) => {
|
||||
$: fullObject = fields.reduce<Record<string, string>>((acc, next) => {
|
||||
acc[next.name] = next.value
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
$: object = Object.entries(fullObject).reduce((acc, [key, next]) => {
|
||||
if (key) {
|
||||
acc[key] = next
|
||||
}
|
||||
return acc
|
||||
}, {})
|
||||
$: object = Object.entries(fullObject).reduce<Record<string, string>>(
|
||||
(acc, [key, next]) => {
|
||||
if (key) {
|
||||
acc[key] = next
|
||||
}
|
||||
return acc
|
||||
},
|
||||
{}
|
||||
)
|
||||
|
||||
function buildFieldActivity(obj) {
|
||||
function buildFieldActivity(obj: Record<string, boolean>) {
|
||||
if (!obj || typeof obj !== "object") {
|
||||
return []
|
||||
}
|
||||
const array = Array(fields.length)
|
||||
const array: boolean[] = Array(fields.length)
|
||||
for (let [key, value] of Object.entries(obj)) {
|
||||
const field = fields.find(el => el.name === key)
|
||||
const idx = fields.indexOf(field)
|
||||
array[idx] = idx !== -1 ? value : true
|
||||
if (field) {
|
||||
const idx = fields.indexOf(field)
|
||||
array[idx] = idx !== -1 ? value : true
|
||||
}
|
||||
}
|
||||
return array
|
||||
}
|
||||
|
@ -77,7 +82,7 @@
|
|||
changed()
|
||||
}
|
||||
|
||||
function deleteEntry(idx) {
|
||||
function deleteEntry(idx: number) {
|
||||
fields.splice(idx, 1)
|
||||
fieldActivity.splice(idx, 1)
|
||||
changed()
|
||||
|
@ -86,7 +91,7 @@
|
|||
function changed() {
|
||||
// Required for reactivity
|
||||
fields = fields
|
||||
const newActivity = {}
|
||||
const newActivity: Record<string, boolean> = {}
|
||||
for (let idx = 0; idx < fields.length; idx++) {
|
||||
const fieldName = fields[idx].name
|
||||
if (fieldName) {
|
||||
|
@ -97,7 +102,7 @@
|
|||
dispatch("change", fields)
|
||||
}
|
||||
|
||||
function isJsonArray(value) {
|
||||
function isJsonArray(value: any) {
|
||||
if (!value || typeof value === "string") {
|
||||
return false
|
||||
}
|
||||
|
@ -181,7 +186,7 @@
|
|||
{#if !readOnly}
|
||||
<Icon hoverable name="Close" on:click={() => deleteEntry(idx)} />
|
||||
{/if}
|
||||
{#if menuItems?.length > 0 && showMenu}
|
||||
{#if menuItems?.length && showMenu}
|
||||
<ActionMenu>
|
||||
<div slot="control" class="control icon">
|
||||
<Icon size="S" hoverable name="MoreSmallList" />
|
||||
|
@ -201,9 +206,6 @@
|
|||
<ActionButton
|
||||
disabled={actionButtonDisabled}
|
||||
icon="Add"
|
||||
secondary
|
||||
thin
|
||||
outline
|
||||
on:click={addEntry}
|
||||
>
|
||||
{#if customButtonText}
|
||||
|
|
|
@ -764,6 +764,7 @@ if (descriptions.length) {
|
|||
const verbs = ["read", "create", "update", "delete"]
|
||||
for (const verb of verbs) {
|
||||
const query = await createQuery({
|
||||
// @ts-expect-error
|
||||
fields: { json: {}, extra: { actionType: "invalid" } },
|
||||
queryVerb: verb,
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as setup from "../utilities"
|
||||
import TestConfiguration from "../../../../tests/utilities/TestConfiguration"
|
||||
import { Datasource, SourceName } from "@budibase/types"
|
||||
import { BodyType, Datasource, SourceName } from "@budibase/types"
|
||||
import { getCachedVariable } from "../../../../threads/utils"
|
||||
import nock from "nock"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
|
@ -259,7 +259,7 @@ describe("rest", () => {
|
|||
readable: true,
|
||||
fields: {
|
||||
path: "www.example.com",
|
||||
bodyType: "text",
|
||||
bodyType: BodyType.TEXT,
|
||||
queryString: "&testParam={{testParam}}",
|
||||
requestBody:
|
||||
"This is plain text and this is my email: {{[user].[email]}}. This is a test param: {{testParam}}",
|
||||
|
@ -305,7 +305,7 @@ describe("rest", () => {
|
|||
readable: true,
|
||||
fields: {
|
||||
path: "www.example.com",
|
||||
bodyType: "json",
|
||||
bodyType: BodyType.JSON,
|
||||
queryString: "&testParam={{testParam}}",
|
||||
requestBody:
|
||||
'{"email":"{{[user].[email]}}","queryCode":{{testParam}},"userRef":"{{userRef}}"}',
|
||||
|
@ -350,7 +350,7 @@ describe("rest", () => {
|
|||
readable: true,
|
||||
fields: {
|
||||
path: "www.example.com",
|
||||
bodyType: "xml",
|
||||
bodyType: BodyType.XML,
|
||||
queryString: "&testParam={{testParam}}",
|
||||
requestBody:
|
||||
"<note> <email>{{[user].[email]}}</email> <code>{{testParam}}</code> " +
|
||||
|
@ -399,7 +399,7 @@ describe("rest", () => {
|
|||
readable: true,
|
||||
fields: {
|
||||
path: "www.example.com",
|
||||
bodyType: "form",
|
||||
bodyType: BodyType.FORM_DATA,
|
||||
queryString: "&testParam={{testParam}}",
|
||||
requestBody:
|
||||
'{"email":"{{[user].[email]}}","queryCode":{{testParam}},"userRef":"{{userRef}}"}',
|
||||
|
@ -445,7 +445,7 @@ describe("rest", () => {
|
|||
readable: true,
|
||||
fields: {
|
||||
path: "www.example.com",
|
||||
bodyType: "encoded",
|
||||
bodyType: BodyType.ENCODED,
|
||||
queryString: "&testParam={{testParam}}",
|
||||
requestBody:
|
||||
'{"email":"{{[user].[email]}}","queryCode":{{testParam}},"userRef":"{{userRef}}"}',
|
||||
|
|
|
@ -12,7 +12,7 @@ export interface Query extends Document {
|
|||
datasourceId: string
|
||||
name: string
|
||||
parameters: QueryParameter[]
|
||||
fields: RestQueryFields | any
|
||||
fields: RestQueryFields & SQLQueryFields & MongoQueryFields
|
||||
transformer: string | null
|
||||
schema: Record<string, QuerySchema | string>
|
||||
nestedSchemaFields?: Record<string, Record<string, QuerySchema | string>>
|
||||
|
@ -61,6 +61,27 @@ export interface RestQueryFields {
|
|||
pagination?: PaginationConfig
|
||||
paginationValues?: PaginationValues
|
||||
}
|
||||
export interface SQLQueryFields {
|
||||
sql?: string
|
||||
}
|
||||
|
||||
export interface MongoQueryFields {
|
||||
extra?: {
|
||||
collection?: string
|
||||
actionType:
|
||||
| "findOne"
|
||||
| "find"
|
||||
| "updateOne"
|
||||
| "updateMany"
|
||||
| "findOneAndUpdate"
|
||||
| "count"
|
||||
| "distinct"
|
||||
| "insertOne"
|
||||
| "deleteOne"
|
||||
| "deleteMany"
|
||||
}
|
||||
json?: object | string
|
||||
}
|
||||
|
||||
export interface PaginationConfig {
|
||||
type: string
|
||||
|
|
Loading…
Reference in New Issue