Fixed error throw and disablign count group update

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-05-24 15:45:57 +02:00
parent f5d0f14045
commit cd73cd3a6e
No known key found for this signature in database
GPG key ID: 60C25B8C072916CF
5 changed files with 41 additions and 20 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -326,18 +326,22 @@ export default {
},
/**
* Create a new group
* Create a new group and add user to it
*
* @param {string} groups Group id
* @returns {Promise}
*/
createGroup(gid) {
this.loading = {groups:true, subadmins:true}
this.$store.dispatch('addGroup', gid).then(() => {
this.loading = {groups:false, subadmins:false};
let userid = this.user.id;
this.$store.dispatch('addUserGroup', {userid, gid});
});
this.$store.dispatch('addGroup', gid)
.then(() => {
this.loading = {groups:false, subadmins:false};
let userid = this.user.id;
this.$store.dispatch('addUserGroup', {userid, gid});
})
.catch(() => {
this.loading = {groups:false, subadmins:false};
});
return this.$store.getters.getGroups[this.groups.length];
},
@ -372,6 +376,9 @@ export default {
if (this.$route.params.selectedGroup === gid) {
this.$store.commit('deleteUser', userid);
}
})
.catch(() => {
this.loading.groups = false
});
},

View file

@ -12,10 +12,10 @@ const mutations = {
API_FAILURE(state, error) {
try {
let message = error.error.response.data.ocs.meta.message;
OC.Notification.showHtml(t('settings','An error occured during the request. Unable to proceed.')+'<br>'+message, {timeout: 7});
} catch(e) {
let message = error;
OC.Notification.showTemporary(t('settings','An error occured during the request. Unable to proceed.'));
}
OC.Notification.showHtml(t('settings','An error occured during the request. Unable to proceed.')+'<br>'+message, {timeout: 7});
console.log(state, error);
}
};

View file

@ -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;
});
},
/**