1
0
Fork 0
mirror of synced 2024-10-05 12:34:50 +13:00

Fixing dev-tools handling of custom roles and build issue - PR comments.

This commit is contained in:
mike12345567 2023-09-27 16:52:20 +01:00
parent 395969e0f0
commit e3469ed38d
5 changed files with 39 additions and 30 deletions

View file

@ -85,7 +85,6 @@
onMount(async () => {
await initialise()
await authStore.actions.fetchUser()
await roleStore.actions.fetchAccessibleRoles()
dataLoaded = true
if (get(builderStore).inBuilder) {
builderStore.actions.notifyLoaded()

View file

@ -60,8 +60,7 @@
})
setContext("layout", store)
$: accessibleRoles = $roleStore
$: validLinks = getValidLinks(links)
$: validLinks = getValidLinks(links, $roleStore)
$: typeClass = NavigationClasses[navigation] || NavigationClasses.None
$: navWidthClass = WidthClasses[navWidth || width] || WidthClasses.Large
$: pageWidthClass = WidthClasses[pageWidth || width] || WidthClasses.Large
@ -99,12 +98,12 @@
}
}
const getValidLinks = allLinks => {
const getValidLinks = (allLinks, userRoleHierarchy) => {
// Strip links missing required info
let validLinks = (allLinks || []).filter(link => link.text && link.url)
// Filter to only links allowed by the current role
return validLinks.filter(link => {
return accessibleRoles?.find(roleId => roleId === link.roleId)
return userRoleHierarchy?.find(roleId => roleId === link.roleId)
})
}

View file

@ -1,32 +1,39 @@
<script>
import { Heading, Select, ActionButton } from "@budibase/bbui"
import { devToolsStore, appStore } from "../../stores"
import { getContext } from "svelte"
import { devToolsStore, appStore, roleStore } from "../../stores"
import { getContext, onMount } from "svelte"
const context = getContext("context")
const SELF_ROLE = "self"
$: previewOptions = [
{
let staticRoleList
$: previewOptions = buildRoleList(staticRoleList)
function buildRoleList(roleIds) {
const list = []
list.push({
label: "View as yourself",
value: "self",
},
{
label: "View as public user",
value: "PUBLIC",
},
{
label: "View as basic user",
value: "BASIC",
},
{
label: "View as power user",
value: "POWER",
},
{
label: "View as admin user",
value: "ADMIN",
},
]
value: SELF_ROLE,
})
if (!roleIds) {
return list
}
for (let roleId of roleIds) {
list.push({
label: `View as ${roleId.toLowerCase()} user`,
value: roleId,
})
}
devToolsStore.actions.changeRole(SELF_ROLE)
return list
}
onMount(async () => {
// make sure correct before starting
await devToolsStore.actions.changeRole(SELF_ROLE)
staticRoleList = await roleStore.actions.fetchAccessibleRoles()
})
</script>
<div class="dev-preview-header" class:mobile={$context.device.mobile}>
@ -34,7 +41,7 @@
<Select
quiet
options={previewOptions}
value={$devToolsStore.role || "self"}
value={$devToolsStore.role || SELF_ROLE}
placeholder={null}
autoWidth
on:change={e => devToolsStore.actions.changeRole(e.detail)}

View file

@ -1,5 +1,6 @@
import { API } from "api"
import { writable } from "svelte/store"
import { currentRole } from "./derived"
const createRoleStore = () => {
const store = writable([])
@ -9,6 +10,7 @@ const createRoleStore = () => {
const accessible = await API.getAccessibleRoles()
// Use the app self if present, otherwise fallback to the global self
store.set(accessible || [])
return accessible
}
return {
@ -18,3 +20,5 @@ const createRoleStore = () => {
}
export const roleStore = createRoleStore()
currentRole.subscribe(roleStore.actions.fetchAccessibleRoles)

View file

@ -55,7 +55,7 @@ const checkAuthorizedResource = async (
) => {
// get the user's roles
const roleId = ctx.roleId || roles.BUILTIN_ROLE_IDS.PUBLIC
const userRoles = await roles.getUserRoleIdHierarchy(roleId)
const userRoles = await roles.getUserRoleHierarchy(roleId)
const permError = "User does not have permission"
// check if the user has the required role
if (resourceRoles.length > 0) {