Merge pull request #2086 from Budibase/fix/edit-roles-modal

Fixes for issue #2077
This commit is contained in:
Michael Drury 2021-07-25 12:14:31 +01:00 committed by GitHub
commit 8c359ca76d
2 changed files with 30 additions and 598 deletions

View File

@ -6,8 +6,10 @@
import ErrorsBox from "components/common/ErrorsBox.svelte" import ErrorsBox from "components/common/ErrorsBox.svelte"
import { roles } from "stores/backend" import { roles } from "stores/backend"
const BASE_ROLE = { _id: "", inherits: "BASIC", permissionId: "Read/Write" }
let basePermissions = [] let basePermissions = []
let selectedRole = {} let selectedRole = BASE_ROLE
let errors = [] let errors = []
let builtInRoles = ["Admin", "Power", "Basic", "Public"] let builtInRoles = ["Admin", "Power", "Basic", "Public"]
// Don't allow editing of public role // Don't allow editing of public role
@ -15,6 +17,11 @@
$: selectedRoleId = selectedRole._id $: selectedRoleId = selectedRole._id
$: otherRoles = editableRoles.filter(role => role._id !== selectedRoleId) $: otherRoles = editableRoles.filter(role => role._id !== selectedRoleId)
$: isCreating = selectedRoleId == null || selectedRoleId === "" $: isCreating = selectedRoleId == null || selectedRoleId === ""
$: valid =
selectedRole.name &&
selectedRole.inherits &&
selectedRole.permissionId &&
!builtInRoles.includes(selectedRole.name)
const fetchBasePermissions = async () => { const fetchBasePermissions = async () => {
const permissionsResponse = await api.get("/api/permission/builtin") const permissionsResponse = await api.get("/api/permission/builtin")
@ -32,7 +39,7 @@
permissionId: role.permissionId ?? "", permissionId: role.permissionId ?? "",
} }
} else { } else {
selectedRole = { _id: "", inherits: "", permissionId: "" } selectedRole = BASE_ROLE
} }
errors = [] errors = []
} }
@ -88,6 +95,7 @@
title="Edit Roles" title="Edit Roles"
confirmText={isCreating ? "Create" : "Save"} confirmText={isCreating ? "Create" : "Save"}
onConfirm={saveRole} onConfirm={saveRole}
disabled={!valid}
> >
{#if errors.length} {#if errors.length}
<ErrorsBox {errors} /> <ErrorsBox {errors} />
@ -115,7 +123,7 @@
options={otherRoles} options={otherRoles}
getOptionValue={role => role._id} getOptionValue={role => role._id}
getOptionLabel={role => role.name} getOptionLabel={role => role.name}
placeholder="None" disabled={builtInRoles.includes(selectedRole.name)}
/> />
<Select <Select
label="Base Permissions" label="Base Permissions"
@ -123,7 +131,7 @@
options={basePermissions} options={basePermissions}
getOptionValue={x => x._id} getOptionValue={x => x._id}
getOptionLabel={x => x.name} getOptionLabel={x => x.name}
placeholder="Choose permissions" disabled={builtInRoles.includes(selectedRole.name)}
/> />
{/if} {/if}
<div slot="footer"> <div slot="footer">

File diff suppressed because it is too large Load Diff