From fc5f20b442d1e53196f7069ed550cc831aa5e5ba Mon Sep 17 00:00:00 2001 From: axolotle Date: Fri, 16 Apr 2021 22:11:49 +0200 Subject: [PATCH] fix store not being updated on permissions changes --- app/src/store/data.js | 15 +++++++++++++++ app/src/views/group/GroupList.vue | 13 +++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/src/store/data.js b/app/src/store/data.js index 4a96a517..7ac1b88a 100644 --- a/app/src/store/data.js +++ b/app/src/store/data.js @@ -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) + } } }, diff --git a/app/src/views/group/GroupList.vue b/app/src/views/group/GroupList.vue index ccfe4a0d..ba32b8bb 100644 --- a/app/src/views/group/GroupList.vue +++ b/app/src/views/group/GroupList.vue @@ -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 }) {