From cd73cd3a6e2c3623efbd274ceacc44c2d210b049 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Thu, 24 May 2018 15:45:57 +0200 Subject: Fixed error throw and disablign count group update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- settings/src/store/users.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'settings/src/store/users.js') 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; + }); }, /** -- cgit v1.2.3