Skip to content

Commit 1af827f

Browse files
committed
fix(users): Improve error handling of some fields update
Signed-off-by: Louis Chemineau <[email protected]>
1 parent 1768bd6 commit 1af827f

File tree

2 files changed

+48
-35
lines changed

2 files changed

+48
-35
lines changed

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

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -624,40 +624,45 @@ export default {
624624
*
625625
* @param {string} displayName The display name
626626
*/
627-
updateDisplayName() {
627+
async updateDisplayName() {
628628
this.loading.displayName = true
629-
this.$store.dispatch('setUserData', {
630-
userid: this.user.id,
631-
key: 'displayname',
632-
value: this.editedDisplayName,
633-
}).then(() => {
634-
this.loading.displayName = false
629+
try {
630+
await this.$store.dispatch('setUserData', {
631+
userid: this.user.id,
632+
key: 'displayname',
633+
value: this.editedDisplayName,
634+
})
635+
635636
if (this.editedDisplayName === this.user.displayname) {
636637
showSuccess(t('setting', 'Display name was successfully changed'))
637638
}
638-
})
639+
} finally {
640+
this.loading.displayName = false
641+
}
639642
},
640643
641644
/**
642645
* Set user password
643646
*
644647
* @param {string} password The email address
645648
*/
646-
updatePassword() {
649+
async updatePassword() {
647650
this.loading.password = true
648651
if (this.editedPassword.length === 0) {
649652
showError(t('setting', "Password can't be empty"))
650653
this.loading.password = false
651654
} else {
652-
this.$store.dispatch('setUserData', {
653-
userid: this.user.id,
654-
key: 'password',
655-
value: this.editedPassword,
656-
}).then(() => {
657-
this.loading.password = false
655+
try {
656+
await this.$store.dispatch('setUserData', {
657+
userid: this.user.id,
658+
key: 'password',
659+
value: this.editedPassword,
660+
})
658661
this.editedPassword = ''
659662
showSuccess(t('setting', 'Password was successfully changed'))
660-
})
663+
} finally {
664+
this.loading.password = false
665+
}
661666
}
662667
},
663668
@@ -666,23 +671,26 @@ export default {
666671
*
667672
* @param {string} mailAddress The email address
668673
*/
669-
updateEmail() {
674+
async updateEmail() {
670675
this.loading.mailAddress = true
671676
if (this.editedMail === '') {
672677
showError(t('setting', "Email can't be empty"))
673678
this.loading.mailAddress = false
674679
this.editedMail = this.user.email
675680
} else {
676-
this.$store.dispatch('setUserData', {
677-
userid: this.user.id,
678-
key: 'email',
679-
value: this.editedMail,
680-
}).then(() => {
681-
this.loading.mailAddress = false
681+
try {
682+
await this.$store.dispatch('setUserData', {
683+
userid: this.user.id,
684+
key: 'email',
685+
value: this.editedMail,
686+
})
687+
682688
if (this.editedMail === this.user.email) {
683689
showSuccess(t('setting', 'Email was successfully changed'))
684690
}
685-
})
691+
} finally {
692+
this.loading.mailAddress = false
693+
}
686694
}
687695
},
688696

apps/settings/src/store/users.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -641,11 +641,14 @@ const actions = {
641641
* @param {string} userid User id
642642
* @return {Promise}
643643
*/
644-
wipeUserDevices(context, userid) {
645-
return api.requireAdmin().then((response) => {
646-
return api.post(generateOcsUrl('cloud/users/{userid}/wipe', { userid }))
647-
.catch((error) => { throw error })
648-
}).catch((error) => context.commit('API_FAILURE', { userid, error }))
644+
async wipeUserDevices(context, userid) {
645+
try {
646+
await api.requireAdmin()
647+
return await api.post(generateOcsUrl('cloud/users/{userid}/wipe', { userid }))
648+
} catch (error) {
649+
context.commit('API_FAILURE', { userid, error })
650+
return Promise.reject(new Error('Failed to wipe user devices'))
651+
}
649652
},
650653

651654
/**
@@ -735,7 +738,7 @@ const actions = {
735738
* @param {string} options.value Value of the change
736739
* @return {Promise}
737740
*/
738-
setUserData(context, { userid, key, value }) {
741+
async setUserData(context, { userid, key, value }) {
739742
const allowedEmpty = ['email', 'displayname', 'manager']
740743
if (['email', 'language', 'quota', 'displayname', 'password', 'manager'].indexOf(key) !== -1) {
741744
// We allow empty email or displayname
@@ -745,11 +748,13 @@ const actions = {
745748
|| allowedEmpty.indexOf(key) !== -1
746749
)
747750
) {
748-
return api.requireAdmin().then((response) => {
749-
return api.put(generateOcsUrl('cloud/users/{userid}', { userid }), { key, value })
750-
.then((response) => context.commit('setUserData', { userid, key, value }))
751-
.catch((error) => { throw error })
752-
}).catch((error) => context.commit('API_FAILURE', { userid, error }))
751+
try {
752+
await api.requireAdmin()
753+
await api.put(generateOcsUrl('cloud/users/{userid}', { userid }), { key, value })
754+
return context.commit('setUserData', { userid, key, value })
755+
} catch (error) {
756+
context.commit('API_FAILURE', { userid, error })
757+
}
753758
}
754759
}
755760
return Promise.reject(new Error('Invalid request data'))

0 commit comments

Comments
 (0)