Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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 <[email protected]>
  • Loading branch information
nfebe committed May 22, 2025
commit 03232422b4886f9842c2cc30168e98ae9c9a4666
16 changes: 11 additions & 5 deletions apps/settings/src/components/Users/UserRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
label="displayname"
:options="possibleManagers"
:placeholder="managerLabel"
clearable
@open="searchInitialUserManager"
@search="searchUserManager"
@option:selected="updateUserManager" />
Expand Down Expand Up @@ -614,20 +615,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
}
Expand Down
34 changes: 19 additions & 15 deletions apps/settings/src/store/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,23 +767,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
)
) {
try {
await api.requireAdmin()
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 })
}
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'))
},

Expand Down