1
0
Fork 0
mirror of synced 2024-06-27 02:20:35 +12:00

Adding checks around the edit roles modal.

This commit is contained in:
Michael Drury 2021-07-25 11:46:40 +01:00
parent 88dbb17af0
commit 72e392608d
2 changed files with 26 additions and 598 deletions

View file

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

File diff suppressed because it is too large Load diff