From 11bdcbec86f34d0401fd72621fef182a687b09e5 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 14 May 2025 19:50:17 +0200 Subject: [PATCH] fix: correctly unset account manager Signed-off-by: Ferdinand Thiessen --- .../settings/src/components/Users/UserRow.vue | 22 ++++++++++------- apps/settings/src/store/users.js | 24 +++++++++---------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/apps/settings/src/components/Users/UserRow.vue b/apps/settings/src/components/Users/UserRow.vue index b6af13c7300..20fc4a63cd7 100644 --- a/apps/settings/src/components/Users/UserRow.vue +++ b/apps/settings/src/components/Users/UserRow.vue @@ -264,8 +264,7 @@ :placeholder="managerLabel" clearable @open="searchInitialUserManager" - @search="searchUserManager" - @option:selected="updateUserManager" /> + @search="searchUserManager" /> {{ 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 diff --git a/apps/settings/src/store/users.js b/apps/settings/src/store/users.js index 39ff43346d8..66b5f5890fc 100644 --- a/apps/settings/src/store/users.js +++ b/apps/settings/src/store/users.js @@ -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')) }, /**