Browse Source

fix(settings): Send update request when clearing user manager

- Update setUserData to send PUT request for empty manager values
- Remove clear button from manager select in UserRow
- Simplify manager update logic in UserRow
- Ensure consistent API behavior for empty values in allowedEmpty fields

Signed-off-by: nfebe <fenn25.fn@gmail.com>
pull/53050/head
nfebe 6 months ago
committed by F. E Noel Nfebe
parent
commit
b20c6e99ab
  1. 16
      apps/settings/src/components/Users/UserRow.vue
  2. 24
      apps/settings/src/store/users.js

16
apps/settings/src/components/Users/UserRow.vue

@ -256,6 +256,7 @@
label="displayname"
:options="possibleManagers"
:placeholder="managerLabel"
clearable
@open="searchInitialUserManager"
@search="searchUserManager"
@option:selected="updateUserManager" />
@ -630,20 +631,25 @@ export default {
},
async updateUserManager(manager) {
if (manager === null) {
this.currentManager = ''
}
// Update the local state immediately for better UX
const previousManager = this.currentManager
this.currentManager = manager || ''
this.loading.manager = true
try {
await this.$store.dispatch('setUserData', {
userid: this.user.id,
key: 'manager',
value: this.currentManager ? this.currentManager.id : '',
value: manager ? manager.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(error)
console.error('Failed to update manager:', error)
// Revert to the previous manager in the UI on error
this.currentManager = previousManager
} finally {
this.loading.manager = false
}

24
apps/settings/src/store/users.js

@ -766,23 +766,27 @@ const actions = {
*/
async setUserData(context, { userid, key, value }) {
const allowedEmpty = ['email', 'displayname', 'manager']
if (['email', 'language', 'quota', 'displayname', 'password', 'manager'].indexOf(key) !== -1) {
// We allow empty email or displayname
if (typeof value === 'string'
&& (
(allowedEmpty.indexOf(key) === -1 && value.length > 0)
|| allowedEmpty.indexOf(key) !== -1
)
) {
const validKeys = ['email', 'language', 'quota', 'displayname', 'password', 'manager']
if (!validKeys.includes(key)) {
return Promise.reject(new Error('Invalid request data'))
}
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 })
}
} catch (error) {
context.commit('API_FAILURE', { userid, error })
}
}
}
return Promise.reject(new Error('Invalid request data'))
},

Loading…
Cancel
Save