Add js methods for renaming a group.

Signed-off-by: Martin Jänel <spammemore@posteo.de>
Signed-off-by: Louis Chemineau <louis@chmn.me>
This commit is contained in:
ArcticFall 2021-11-18 00:46:07 +01:00 committed by Louis Chemineau
parent 1f80d767b4
commit 849d3697d3

View file

@ -96,6 +96,15 @@ const mutations = {
console.error('Can\'t create group', e)
}
},
renameGroup(state, { gid, displayname }) {
const groupIndex = state.groups.findIndex(groupSearch => groupSearch.id === gid)
if (groupIndex >= 0) {
const updatedGroup = state.groups[groupIndex]
updatedGroup.name = displayname
state.groups[groupIndex] = updatedGroup
state.groups = orderGroups(state.groups, state.orderBy)
}
},
removeGroup(state, gid) {
const groupIndex = state.groups.findIndex(groupSearch => groupSearch.id === gid)
if (groupIndex >= 0) {
@ -341,6 +350,30 @@ const actions = {
})
},
/**
* Rename group
*
* @param {Object} context store context
* @param {string} groupid Group id
* @param {string} displayName Group display name
* @returns {Promise}
*/
renameGroup(context, { groupid, displayName }) {
return api.requireAdmin().then((response) => {
return api.put(generateOcsUrl('cloud/groups/{groupId}', { groupId: encodeURIComponent(groupid) }), { key: 'displayname', value: displayName })
.then((response) => {
context.commit('renameGroup', { gid: groupid, displayname: displayName })
return { groupid, displayName }
})
.catch((error) => { throw error })
}).catch((error) => {
context.commit('API_FAILURE', { groupid, error })
// let's throw one more time to prevent the view
// from renaming the group
throw error
})
},
/**
* Remove group
*