|
|
|
@ -19,15 +19,24 @@ |
|
|
|
import IntegrationQueryEditor from "components/integration/index.svelte" |
|
|
|
import ExternalDataSourceTable from "components/backend/DataTable/ExternalDataSourceTable.svelte" |
|
|
|
import ParameterBuilder from "components/integration/QueryParameterBuilder.svelte" |
|
|
|
import { datasources, integrations, queries } from "stores/backend" |
|
|
|
import { |
|
|
|
datasources, |
|
|
|
integrations, |
|
|
|
queries, |
|
|
|
roles, |
|
|
|
permissions, |
|
|
|
} from "stores/backend" |
|
|
|
import { capitalise } from "../../helpers" |
|
|
|
import CodeMirrorEditor from "components/common/CodeMirrorEditor.svelte" |
|
|
|
import { Roles } from "constants/backend" |
|
|
|
import { onMount } from "svelte" |
|
|
|
|
|
|
|
export let query |
|
|
|
export let fields = [] |
|
|
|
|
|
|
|
let parameters |
|
|
|
let data = [] |
|
|
|
let roleId |
|
|
|
const transformerDocs = |
|
|
|
"https://docs.budibase.com/building-apps/data/transformers" |
|
|
|
const typeOptions = [ |
|
|
|
@ -70,7 +79,22 @@ |
|
|
|
} |
|
|
|
|
|
|
|
function resetDependentFields() { |
|
|
|
if (query.fields.extra) query.fields.extra = {} |
|
|
|
if (query.fields.extra) { |
|
|
|
query.fields.extra = {} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async function updateRole(role, id = null) { |
|
|
|
roleId = role |
|
|
|
if (query?._id || id) { |
|
|
|
for (let level of ["read", "write"]) { |
|
|
|
await permissions.save({ |
|
|
|
level, |
|
|
|
role, |
|
|
|
resource: query?._id || id, |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function populateExtraQuery(extraQueryFields) { |
|
|
|
@ -122,6 +146,7 @@ |
|
|
|
async function saveQuery() { |
|
|
|
try { |
|
|
|
const { _id } = await queries.save(query.datasourceId, query) |
|
|
|
await updateRole(roleId, _id) |
|
|
|
notifications.success(`Query saved successfully.`) |
|
|
|
$goto(`../${_id}`) |
|
|
|
} catch (err) { |
|
|
|
@ -129,6 +154,17 @@ |
|
|
|
notifications.error(`Error creating query. ${err.message}`) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onMount(async () => { |
|
|
|
if (!query || !query._id) { |
|
|
|
return |
|
|
|
} |
|
|
|
try { |
|
|
|
roleId = (await permissions.forResource(query._id))["read"] |
|
|
|
} catch (err) { |
|
|
|
roleId = Roles.BASIC |
|
|
|
} |
|
|
|
}) |
|
|
|
</script> |
|
|
|
|
|
|
|
<Layout gap="S" noPadding> |
|
|
|
@ -151,6 +187,16 @@ |
|
|
|
queryConfig[verb]?.displayName || capitalise(verb)} |
|
|
|
/> |
|
|
|
</div> |
|
|
|
<div class="config-field"> |
|
|
|
<Label>Access level</Label> |
|
|
|
<Select |
|
|
|
value={roleId} |
|
|
|
on:change={e => updateRole(e.detail)} |
|
|
|
options={$roles} |
|
|
|
getOptionLabel={x => x.name} |
|
|
|
getOptionValue={x => x._id} |
|
|
|
/> |
|
|
|
</div> |
|
|
|
{#if integrationInfo?.extra && query.queryVerb} |
|
|
|
<ExtraQueryConfig |
|
|
|
{query} |
|
|
|
|