moves permissions to a separate store
This commit is contained in:
parent
f4c30bd360
commit
4b3891f68a
|
@ -1,6 +1,7 @@
|
|||
import { writable, get } from "svelte/store"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
import api from "../api"
|
||||
import { permissions } from './backend/permissions'
|
||||
|
||||
const INITIAL_BACKEND_UI_STATE = {
|
||||
tables: [],
|
||||
|
@ -26,18 +27,15 @@ export const getBackendUiStore = () => {
|
|||
api.get(`/api/tables`).then(r => r.json()),
|
||||
api.get(`/api/datasources`).then(r => r.json()),
|
||||
api.get(`/api/queries`).then(r => r.json()),
|
||||
api.get("/api/integrations").then(r => r.json())
|
||||
api.get("/api/integrations").then(r => r.json()),
|
||||
])
|
||||
|
||||
const permissionLevels = await store.actions.permissions.fetchLevels()
|
||||
|
||||
store.update(state => {
|
||||
state.selectedDatabase = db
|
||||
state.tables = tables
|
||||
state.datasources = datasources
|
||||
state.queries = queries
|
||||
state.integrations = integrations
|
||||
state.permissionLevels = permissionLevels
|
||||
return state
|
||||
})
|
||||
},
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export { permissions } from "./permissions"
|
|
@ -0,0 +1,29 @@
|
|||
import { writable } from "svelte/store"
|
||||
import api from "../../api"
|
||||
|
||||
function createPermissionStore() {
|
||||
const { subscribe, set } = writable([])
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
fetchLevels: async () => {
|
||||
const response = await api.get("/api/permission/levels")
|
||||
const json = await response.json()
|
||||
set(json)
|
||||
},
|
||||
forResource: async resourceId => {
|
||||
const response = await api.get(`/api/permission/${resourceId}`)
|
||||
const json = await response.json()
|
||||
return json
|
||||
},
|
||||
save: async ({ role, resource, level }) => {
|
||||
const response = await api.post(
|
||||
`/api/permission/${role}/${resource}/${level}`
|
||||
)
|
||||
const json = await response.json()
|
||||
return json
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export const permissions = createPermissionStore()
|
|
@ -1,22 +1,18 @@
|
|||
<script>
|
||||
import { TextButton, Icon, Popover } from "@budibase/bbui"
|
||||
import { backendUiStore } from "builderStore"
|
||||
import { Roles } from "constants/backend"
|
||||
import api from "builderStore/api"
|
||||
import { TextButton, Popover } from "@budibase/bbui"
|
||||
import { permissions } from 'builderStore/store/backend/'
|
||||
import ManageAccessPopover from "../popovers/ManageAccessPopover.svelte"
|
||||
|
||||
export let resourceId
|
||||
|
||||
let anchor
|
||||
let dropdown
|
||||
let levels
|
||||
let permissions
|
||||
let resourcePermissions
|
||||
|
||||
async function openDropdown() {
|
||||
permissions = await backendUiStore.actions.permissions.forResource(
|
||||
resourcePermissions = await permissions.forResource(
|
||||
resourceId
|
||||
)
|
||||
levels = await backendUiStore.actions.permissions.fetchLevels()
|
||||
dropdown.show()
|
||||
}
|
||||
</script>
|
||||
|
@ -30,8 +26,8 @@
|
|||
<Popover bind:this={dropdown} {anchor} align="left">
|
||||
<ManageAccessPopover
|
||||
{resourceId}
|
||||
{levels}
|
||||
{permissions}
|
||||
levels={$permissions}
|
||||
permissions={resourcePermissions}
|
||||
onClosed={dropdown.hide} />
|
||||
</Popover>
|
||||
|
||||
|
|
Loading…
Reference in New Issue