Prevent updating a screen role to a role for which the screen URL already exists
This commit is contained in:
parent
f81313775d
commit
89e38ce534
|
@ -3,6 +3,7 @@
|
||||||
import { roles } from "stores/backend"
|
import { roles } from "stores/backend"
|
||||||
|
|
||||||
export let value
|
export let value
|
||||||
|
export let error
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
|
@ -11,4 +12,5 @@
|
||||||
options={$roles}
|
options={$roles}
|
||||||
getOptionLabel={role => role.name}
|
getOptionLabel={role => role.name}
|
||||||
getOptionValue={role => role._id}
|
getOptionValue={role => role._id}
|
||||||
|
{error}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
let errors = {}
|
let errors = {}
|
||||||
|
|
||||||
const routeExists = url => {
|
const routeTaken = url => {
|
||||||
const roleId = get(selectedAccessRole) || "BASIC"
|
const roleId = get(selectedAccessRole) || "BASIC"
|
||||||
return get(allScreens).some(
|
return get(allScreens).some(
|
||||||
screen =>
|
screen =>
|
||||||
|
@ -24,6 +24,15 @@
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const roleTaken = roleId => {
|
||||||
|
const url = get(currentAsset)?.routing.route
|
||||||
|
return get(allScreens).some(
|
||||||
|
screen =>
|
||||||
|
screen.routing.route.toLowerCase() === url.toLowerCase() &&
|
||||||
|
screen.routing.roleId === roleId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const setAssetProps = (name, value, parser, validate) => {
|
const setAssetProps = (name, value, parser, validate) => {
|
||||||
if (parser) {
|
if (parser) {
|
||||||
value = parser(value)
|
value = parser(value)
|
||||||
|
@ -76,14 +85,25 @@
|
||||||
return sanitizeUrl(val)
|
return sanitizeUrl(val)
|
||||||
},
|
},
|
||||||
validate: val => {
|
validate: val => {
|
||||||
const exisingValue = deepGet($currentAsset, "routing.route")
|
const exisingValue = get(currentAsset)?.routing.route
|
||||||
if (val !== exisingValue && routeExists(val)) {
|
if (val !== exisingValue && routeTaken(val)) {
|
||||||
return "That URL is already in use"
|
return "That URL is already in use for this role"
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "routing.roleId",
|
||||||
|
label: "Access",
|
||||||
|
control: RoleSelect,
|
||||||
|
validate: val => {
|
||||||
|
const exisingValue = get(currentAsset)?.routing.roleId
|
||||||
|
if (val !== exisingValue && roleTaken(val)) {
|
||||||
|
return "That role is already in use for this URL"
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ key: "routing.roleId", label: "Access", control: RoleSelect },
|
|
||||||
{ key: "layoutId", label: "Layout", control: LayoutSelect },
|
{ key: "layoutId", label: "Layout", control: LayoutSelect },
|
||||||
]
|
]
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue