mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 01:30:50 -04:00
fix: correctly unset account manager
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
98c055f9e5
commit
11bdcbec86
2 changed files with 24 additions and 22 deletions
|
|
@ -264,8 +264,7 @@
|
|||
:placeholder="managerLabel"
|
||||
clearable
|
||||
@open="searchInitialUserManager"
|
||||
@search="searchUserManager"
|
||||
@option:selected="updateUserManager" />
|
||||
@search="searchUserManager" />
|
||||
</template>
|
||||
<span v-else-if="!isObfuscated">
|
||||
{{ user.manager }}
|
||||
|
|
@ -516,6 +515,12 @@ export default {
|
|||
},
|
||||
},
|
||||
|
||||
watch: {
|
||||
currentManager() {
|
||||
this.updateUserManager()
|
||||
},
|
||||
},
|
||||
|
||||
async beforeMount() {
|
||||
if (this.user.manager) {
|
||||
await this.initManager(this.user.manager)
|
||||
|
|
@ -636,23 +641,22 @@ export default {
|
|||
})
|
||||
},
|
||||
|
||||
async updateUserManager(manager) {
|
||||
// Update the local state immediately for better UX
|
||||
const previousManager = this.currentManager
|
||||
this.currentManager = manager || ''
|
||||
async updateUserManager() {
|
||||
this.loading.manager = true
|
||||
|
||||
// Store the current manager before making changes
|
||||
const previousManager = this.currentManager
|
||||
|
||||
try {
|
||||
await this.$store.dispatch('setUserData', {
|
||||
userid: this.user.id,
|
||||
key: 'manager',
|
||||
value: manager ? manager.id : '',
|
||||
value: this.currentManager ? this.currentManager.id : '',
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
// TRANSLATORS This string describes a line manager in the context of an organization
|
||||
showError(t('settings', 'Failed to update line manager'))
|
||||
console.error('Failed to update manager:', error)
|
||||
logger.error('Failed to update manager:', error)
|
||||
|
||||
// Revert to the previous manager in the UI on error
|
||||
this.currentManager = previousManager
|
||||
|
|
|
|||
|
|
@ -768,27 +768,25 @@ const actions = {
|
|||
async setUserData(context, { userid, key, value }) {
|
||||
const allowedEmpty = ['email', 'displayname', 'manager']
|
||||
const validKeys = ['email', 'language', 'quota', 'displayname', 'password', 'manager']
|
||||
|
||||
if (!validKeys.includes(key)) {
|
||||
return Promise.reject(new Error('Invalid request data'))
|
||||
throw new Error('Invalid request data')
|
||||
}
|
||||
|
||||
// If value is empty and the key doesn't allow empty values, throw error
|
||||
if (value === '' && !allowedEmpty.includes(key)) {
|
||||
throw new Error('Value cannot be empty for this field')
|
||||
}
|
||||
|
||||
try {
|
||||
await api.requireAdmin()
|
||||
if (typeof value === 'string' && value.length === 0 && allowedEmpty.includes(key)) {
|
||||
// If value is empty and allowed to be empty, send DELETE request
|
||||
await api.delete(generateOcsUrl('cloud/users/{userid}', { userid }), { key })
|
||||
return context.commit('setUserData', { userid, key, value: '' })
|
||||
}
|
||||
|
||||
if (typeof value === 'string' && (value.length > 0 || allowedEmpty.includes(key))) {
|
||||
await api.put(generateOcsUrl('cloud/users/{userid}', { userid }), { key, value })
|
||||
return context.commit('setUserData', { userid, key, value })
|
||||
}
|
||||
const commitValue = value === '' ? '' : value
|
||||
await api.put(generateOcsUrl('cloud/users/{userid}', { userid }), { key, value })
|
||||
return context.commit('setUserData', { userid, key, value: commitValue })
|
||||
} catch (error) {
|
||||
context.commit('API_FAILURE', { userid, error })
|
||||
throw error
|
||||
}
|
||||
|
||||
return Promise.reject(new Error('Invalid request data'))
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue