fix store not being updated on permissions changes

This commit is contained in:
axolotle 2021-04-16 22:11:49 +02:00
parent bc41d0ad9d
commit fc5f20b442
2 changed files with 20 additions and 8 deletions

View file

@ -81,12 +81,27 @@ export default {
}
},
'UPDATE_GROUPS' (state, [data, { groupName }]) {
Vue.set(state.groups, groupName, data)
},
'DEL_GROUPS' (state, [groupname]) {
Vue.delete(state.groups, groupname)
},
'SET_PERMISSIONS' (state, [permissions]) {
state.permissions = permissions
},
'UPDATE_PERMISSIONS' (state, [_, { groupName, action, permId }]) {
// FIXME hacky way to update the store
const permissions = state.groups[groupName].permissions
if (action === 'add') {
permissions.push(permId)
} else if (action === 'remove') {
const index = permissions.indexOf(permId)
if (index > -1) permissions.splice(index, 1)
}
}
},

View file

@ -202,22 +202,19 @@ export default {
onPermissionChanged ({ option, groupName, action, applyMethod }) {
const permId = this.permissions.find(perm => perm.label === option).id
api.put(
`users/permissions/${permId}/${action}/${groupName}`,
// FIXME hacky way to update the store
{ uri: `users/permissions/${permId}/${action}/${groupName}`, storeKey: 'permissions', groupName, action, permId },
{},
{ key: 'permissions.' + action, perm: option, name: groupName }
).then(() => {
applyMethod(option)
})
).then(() => applyMethod(option))
},
onUserChanged ({ option, groupName, action, applyMethod }) {
api.put(
`users/groups/${groupName}/${action}/${option}`,
{ uri: `users/groups/${groupName}/${action}/${option}`, storeKey: 'groups', groupName },
{},
{ key: 'groups.' + action, user: option, name: groupName }
).then(() => {
applyMethod(option)
})
).then(() => applyMethod(option))
},
onSpecificUserAdded ({ option: userName, action, applyMethod }) {