Fixing #4205 - making sure builder loads the correct role for the query.

This commit is contained in:
mike12345567 2022-01-26 18:59:41 +00:00
parent 9b55ba8b13
commit 412b7e5f06
1 changed files with 10 additions and 8 deletions

View File

@ -1,16 +1,14 @@
<script>
import { Label, Select } from "@budibase/bbui"
import { permissions, roles } from "stores/backend"
import { onMount } from "svelte"
import { Roles } from "constants/backend"
export let query
export let saveId
export let label
$: updateRole(roleId, saveId)
$: getPermissions(query)
let roleId, loaded
let roleId, loaded, fetched
async function updateRole(role, id) {
roleId = role
@ -26,19 +24,23 @@
}
}
onMount(async () => {
if (!query || !query._id) {
async function getPermissions(queryToFetch) {
if (fetched?._id === queryToFetch?._id) {
return
}
fetched = queryToFetch
if (!queryToFetch || !queryToFetch._id) {
roleId = Roles.BASIC
loaded = true
return
}
try {
roleId = (await permissions.forResource(query._id))["read"]
roleId = (await permissions.forResource(queryToFetch._id))["read"]
} catch (err) {
roleId = Roles.BASIC
}
loaded = true
})
}
</script>
{#if loaded}