diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-05-24 15:45:57 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-05-24 17:52:15 +0200 |
commit | cd73cd3a6e2c3623efbd274ceacc44c2d210b049 (patch) | |
tree | 677ead0035f10c7343108159ef856ba722221113 /settings/src/store/users.js | |
parent | f5d0f140456ead25e0e8142d2c17d6d720bf4418 (diff) | |
download | nextcloud-server-cd73cd3a6e2c3623efbd274ceacc44c2d210b049.tar.gz nextcloud-server-cd73cd3a6e2c3623efbd274ceacc44c2d210b049.zip |
Fixed error throw and disablign count group update
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'settings/src/store/users.js')
-rw-r--r-- | settings/src/store/users.js | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/settings/src/store/users.js b/settings/src/store/users.js index 63a1568e048..5fac0c6f327 100644 --- a/settings/src/store/users.js +++ b/settings/src/store/users.js @@ -6,7 +6,7 @@ const orderGroups = function(groups, orderBy) { * https://github.com/nextcloud/server/blob/208e38e84e1a07a49699aa90dc5b7272d24489f0/lib/private/Group/MetaData.php#L34 */ if (orderBy === 1) { - return groups.sort((a, b) => a.usercount < b.usercount); + return groups.sort((a, b) => a.usercount-a.disabled < b.usercount - b.disabled); } else { return groups.sort((a, b) => a.name.localeCompare(b.name)); } @@ -69,19 +69,23 @@ const mutations = { }, addUserGroup(state, { userid, gid }) { let group = state.groups.find(groupSearch => groupSearch.id == gid); - if (group) { - group.usercount++; // increase count + let user = state.users.find(user => user.id == userid); + // increase count if user is enabled + if (group && user.enabled) { + group.usercount++; } - let groups = state.users.find(user => user.id == userid).groups; + let groups = user.groups; groups.push(gid); state.groups = orderGroups(state.groups, state.orderBy); }, removeUserGroup(state, { userid, gid }) { let group = state.groups.find(groupSearch => groupSearch.id == gid); - if (group) { - group.usercount--; // lower count + let user = state.users.find(user => user.id == userid); + // lower count if user is enabled + if (group && user.enabled) { + group.usercount--; } - let groups = state.users.find(user => user.id == userid).groups; + let groups = user.groups; groups.splice(groups.indexOf(gid),1); state.groups = orderGroups(state.groups, state.orderBy); }, @@ -251,7 +255,12 @@ const actions = { return api.post(OC.linkToOCS(`cloud/groups`, 2), {groupid: gid}) .then((response) => context.commit('addGroup', gid)) .catch((error) => {throw error;}); - }).catch((error) => context.commit('API_FAILURE', { userid, error })); + }).catch((error) => { + context.commit('API_FAILURE', { gid, error }); + // let's throw one more time to prevent the view + // from adding the user to a group that doesn't exists + throw error; + }); }, /** @@ -300,7 +309,12 @@ const actions = { return api.delete(OC.linkToOCS(`cloud/users/${userid}/groups`, 2), { groupid: gid }) .then((response) => context.commit('removeUserGroup', { userid, gid })) .catch((error) => {throw error;}); - }).catch((error) => context.commit('API_FAILURE', { userid, error })); + }).catch((error) => { + context.commit('API_FAILURE', { userid, error }); + // let's throw one more time to prevent + // the view from removing the user row on failure + throw error; + }); }, /** |