Display inherit option
This commit is contained in:
parent
bdaf179f20
commit
466f1e6132
|
@ -11,7 +11,7 @@
|
|||
let resourcePermissions
|
||||
|
||||
async function openModal() {
|
||||
resourcePermissions = await permissions.forResource(resourceId)
|
||||
resourcePermissions = await permissions.forResourceDetailed(resourceId)
|
||||
modal.show()
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -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 {
|
||||
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
|
||||
},
|
||||
{}
|
||||
)
|
||||
</script>
|
||||
|
||||
<ModalContent showCancelButton={false} confirmText="Done">
|
||||
|
@ -51,12 +86,13 @@
|
|||
<div class="row">
|
||||
<Label extraSmall grey>Level</Label>
|
||||
<Label extraSmall grey>Role</Label>
|
||||
{#each Object.keys(permissions) as level}
|
||||
{#each Object.keys(computedPermissions) as level}
|
||||
<Input value={capitalise(level)} disabled />
|
||||
<Select
|
||||
placeholder={false}
|
||||
value={computedPermissions[level].selected}
|
||||
on:change={e => changePermission(level, e.detail)}
|
||||
options={$roles}
|
||||
options={computedPermissions[level].options}
|
||||
getOptionLabel={x => x.name}
|
||||
getOptionValue={x => x._id}
|
||||
/>
|
||||
|
|
|
@ -23,6 +23,9 @@ export function createPermissionStore() {
|
|||
forResource: async resourceId => {
|
||||
return (await API.getPermissionForResource(resourceId)).permissions
|
||||
},
|
||||
forResourceDetailed: async resourceId => {
|
||||
return await API.getPermissionForResource(resourceId)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,11 @@ export async function getResourcePerms(
|
|||
role: roles.getExternalRoleID(role._id!, role.version),
|
||||
type: PermissionSource.EXPLICIT,
|
||||
}
|
||||
} else if (permsToInherit && permsToInherit[level]) {
|
||||
} else if (
|
||||
!permissions[level] &&
|
||||
permsToInherit &&
|
||||
permsToInherit[level]
|
||||
) {
|
||||
permissions[level] = {
|
||||
role: permsToInherit[level].role,
|
||||
type: PermissionSource.INHERITED,
|
||||
|
|
Loading…
Reference in New Issue