diff --git a/packages/builder/src/components/backend/DataTable/buttons/ManageAccessButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/ManageAccessButton.svelte index 1de31bf83b..8742eaef76 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/ManageAccessButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/ManageAccessButton.svelte @@ -11,7 +11,7 @@ let resourcePermissions async function openModal() { - resourcePermissions = await permissions.forResource(resourceId) + resourcePermissions = await permissions.forResourceDetailed(resourceId) modal.show() } diff --git a/packages/builder/src/components/backend/DataTable/modals/ManageAccessModal.svelte b/packages/builder/src/components/backend/DataTable/modals/ManageAccessModal.svelte index ff2db2088e..0e792410ca 100644 --- a/packages/builder/src/components/backend/DataTable/modals/ManageAccessModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/ManageAccessModal.svelte @@ -11,6 +11,7 @@ Tag, } from "@budibase/bbui" import { capitalise } from "helpers" + import { get } from "svelte/store" export let resourceId export let permissions @@ -18,19 +19,53 @@ async function changePermission(level, role) { try { - await permissionsStore.save({ - level, - role, - resource: resourceId, - }) + if (role === "inherited") { + await permissionsStore.remove({ + level, + role, + resource: resourceId, + }) + } else { + await permissionsStore.save({ + level, + role, + resource: resourceId, + }) + } // Show updated permissions in UI: REMOVE - permissions = await permissionsStore.forResource(resourceId) + permissions = await permissionsStore.forResourceDetailed(resourceId) notifications.success("Updated permissions") } catch (error) { notifications.error("Error updating permissions") } } + + $: computedPermissions = Object.keys(permissions.permissions).reduce( + (p, c) => { + p[c] = { + selected: + permissions.permissionType[c] === "INHERITED" + ? "inherited" + : permissions.permissions[c], + options: [...get(roles)], + } + + if (permissions.inheritablePermissions) { + p[c].inheritOption = permissions.inheritablePermissions[c] + p[c].options.unshift({ + _id: "inherited", + name: `Inherit (${ + get(roles).find( + x => x._id === permissions.inheritablePermissions[c] + ).name + })`, + }) + } + return p + }, + {} + ) @@ -51,12 +86,13 @@
- {#each Object.keys(permissions) as level} + {#each Object.keys(computedPermissions) as level}