Remove frontend role prefixing hacks and fix 409s on role deletion

This commit is contained in:
Andrew Kingston 2024-10-18 11:56:00 +01:00
parent 761c9d3c18
commit 3d1b78623e
No known key found for this signature in database
1 changed files with 2 additions and 16 deletions

View File

@ -47,28 +47,14 @@ export function createRolesStore() {
roleId: role?._id,
roleRev: role?._rev,
})
store.update(state => state.filter(existing => existing._id !== role._id))
await actions.fetch()
},
save: async role => {
const savedRole = await API.saveRole(role)
await actions.fetch()
// When saving a role we get back an _id prefixed by role_, but the API does not want this
// in future requests
return {
...savedRole,
_id: savedRole._id.replace("role_", ""),
}
return savedRole
},
replace: (roleId, role) => {
// Remove role_ prefix
if (roleId?.startsWith("role_")) {
roleId = roleId.replace("role_", "")
}
if (role?._id.startsWith("role_")) {
role._id = role._id.replace("role_", "")
}
// Handles external updates of roles
if (!roleId) {
return