Skip to content
Snippets Groups Projects
Commit 547b4046 authored by Angelina Filippova's avatar Angelina Filippova
Browse files

Add proper error handling in users and invites modules

parent b05b8a86
No related branches found
No related tags found
1 merge request!45Generate invite tokens from admin-fe
This commit is part of merge request !45. Comments created here will be created in the context of that merge request.
...@@ -226,7 +226,8 @@ export default { ...@@ -226,7 +226,8 @@ export default {
emptyNicknameError: 'Please input the username', emptyNicknameError: 'Please input the username',
invalidNicknameError: 'Username can include "a-z", "A-Z" and "0-9" characters', invalidNicknameError: 'Username can include "a-z", "A-Z" and "0-9" characters',
getPasswordResetToken: 'Get password reset token', getPasswordResetToken: 'Get password reset token',
passwordResetTokenCreated: 'Password reset token was created' passwordResetTokenCreated: 'Password reset token was created',
accountCreated: 'New account was created!'
}, },
userProfile: { userProfile: {
tags: 'Tags', tags: 'Tags',
......
...@@ -24,7 +24,9 @@ const users = { ...@@ -24,7 +24,9 @@ const users = {
}, },
SWAP_USER: (state, updatedUser) => { SWAP_USER: (state, updatedUser) => {
const updated = state.fetchedUsers.map(user => user.id === updatedUser.id ? updatedUser : user) const updated = state.fetchedUsers.map(user => user.id === updatedUser.id ? updatedUser : user)
state.fetchedUsers = updated.sort((a, b) => a.nickname.localeCompare(b.nickname)) state.fetchedUsers = updated
.map(user => user.nickname ? user : { ...user, nickname: '' })
.sort((a, b) => a.nickname.localeCompare(b.nickname))
}, },
SWAP_USERS: (state, users) => { SWAP_USERS: (state, users) => {
const usersWithoutSwapped = users.reduce((acc, user) => { const usersWithoutSwapped = users.reduce((acc, user) => {
......
...@@ -165,15 +165,22 @@ export default { ...@@ -165,15 +165,22 @@ export default {
this.inviteUserDialogVisible = false this.inviteUserDialogVisible = false
this.createTokenDialogVisible = false this.createTokenDialogVisible = false
this.$store.dispatch('RemoveNewToken') this.$store.dispatch('RemoveNewToken')
this.$data.inviteUserForm.email = ''
this.$data.inviteUserForm.name = ''
}, },
createToken() { createToken() {
this.$store.dispatch('GenerateInviteToken', this.$data.newTokenForm) this.$store.dispatch('GenerateInviteToken', this.$data.newTokenForm)
}, },
inviteUserViaEmail() { async inviteUserViaEmail() {
this.$refs['inviteUserForm'].validate((valid) => { this.$refs['inviteUserForm'].validate(async(valid) => {
if (valid) { if (valid) {
this.$store.dispatch('InviteUserViaEmail', this.$data.inviteUserForm) try {
this.closeDialogWindow() await this.$store.dispatch('InviteUserViaEmail', this.$data.inviteUserForm)
} catch (_e) {
return
} finally {
this.closeDialogWindow()
}
this.$message({ this.$message({
type: 'success', type: 'success',
message: this.$t('invites.emailSent') message: this.$t('invites.emailSent')
......
...@@ -147,34 +147,125 @@ export default { ...@@ -147,34 +147,125 @@ export default {
methods: { methods: {
mappers() { mappers() {
return { return {
grantRight: (right) => () => this.selectedUsers grantRight: (right) => () => {
.filter(user => user.local && !user.roles[right] && this.$store.state.user.id !== user.id) const filterUsersFn = user => user.local && !user.roles[right] && this.$store.state.user.id !== user.id
.map(user => this.$store.dispatch('ToggleRight', { user, right })), const toggleRightFn = async(user) => await this.$store.dispatch('ToggleRight', { user, right })
revokeRight: (right) => () => this.selectedUsers const filtered = this.selectedUsers.filter(filterUsersFn)
.filter(user => user.local && user.roles[right] && this.$store.state.user.id !== user.id)
.map(user => this.$store.dispatch('ToggleRight', { user, right })), Promise.all(filtered.map(toggleRightFn))
activate: () => this.selectedUsers .then(() => {
.filter(user => user.deactivated && this.$store.state.user.id !== user.id) this.$message({
.map(user => this.$store.dispatch('ToggleUserActivation', user.nickname)), type: 'success',
deactivate: () => this.selectedUsers message: this.$t('users.completed')
.filter(user => !user.deactivated && this.$store.state.user.id !== user.id) })
.map(user => this.$store.dispatch('ToggleUserActivation', user.nickname)), this.$emit('apply-action')
remove: () => this.selectedUsers }).catch((err) => {
.filter(user => this.$store.state.user.id !== user.id) console.log(err)
.map(user => this.$store.dispatch('DeleteUser', user)), return
addTag: (tag) => () => { })
const users = this.selectedUsers },
.filter(user => tag === 'disable_remote_subscription' || tag === 'disable_any_subscription' revokeRight: (right) => () => {
? user.local && !user.tags.includes(tag) const filterUsersFn = user => user.local && user.roles[right] && this.$store.state.user.id !== user.id
: !user.tags.includes(tag)) const toggleRightFn = async(user) => await this.$store.dispatch('ToggleRight', { user, right })
this.$store.dispatch('AddTag', { users, tag }) const filtered = this.selectedUsers.filter(filterUsersFn)
Promise.all(filtered.map(toggleRightFn))
.then(() => {
this.$message({
type: 'success',
message: this.$t('users.completed')
})
this.$emit('apply-action')
}).catch((err) => {
console.log(err)
return
})
},
activate: () => {
const filtered = this.selectedUsers.filter(user => user.deactivated && this.$store.state.user.id !== user.id)
const toggleActivationFn = async(user) => await this.$store.dispatch('ToggleUserActivation', user.nickname)
Promise.all(filtered.map(toggleActivationFn))
.then(() => {
this.$message({
type: 'success',
message: this.$t('users.completed')
})
this.$emit('apply-action')
}).catch((err) => {
console.log(err)
return
})
},
deactivate: () => {
const filtered = this.selectedUsers.filter(user => !user.deactivated && this.$store.state.user.id !== user.id)
const toggleActivationFn = async(user) => await this.$store.dispatch('ToggleUserActivation', user.nickname)
Promise.all(filtered.map(toggleActivationFn))
.then(() => {
this.$message({
type: 'success',
message: this.$t('users.completed')
})
this.$emit('apply-action')
}).catch((err) => {
console.log(err)
return
})
},
remove: () => {
const filtered = this.selectedUsers.filter(user => this.$store.state.user.id !== user.id)
const deleteAccountFn = async(user) => await this.$store.dispatch('DeleteUser', user)
Promise.all(filtered.map(deleteAccountFn))
.then(() => {
this.$message({
type: 'success',
message: this.$t('users.completed')
})
this.$emit('apply-action')
}).catch((err) => {
console.log(err)
return
})
},
addTag: (tag) => async() => {
const filterUsersFn = user => tag === 'disable_remote_subscription' || tag === 'disable_any_subscription'
? user.local && !user.tags.includes(tag)
: !user.tags.includes(tag)
const users = this.selectedUsers.filter(filterUsersFn)
try {
await this.$store.dispatch('AddTag', { users, tag })
} catch (err) {
console.log(err)
return
}
this.$message({
type: 'success',
message: this.$t('users.completed')
})
this.$emit('apply-action')
}, },
removeTag: (tag) => () => { removeTag: (tag) => async() => {
const users = this.selectedUsers const filterUsersFn = user => tag === 'disable_remote_subscription' || tag === 'disable_any_subscription'
.filter(user => tag === 'disable_remote_subscription' || tag === 'disable_any_subscription' ? user.local && user.tags.includes(tag)
? user.local && user.tags.includes(tag) : user.tags.includes(tag)
: user.tags.includes(tag)) const users = this.selectedUsers.filter(filterUsersFn)
this.$store.dispatch('RemoveTag', { users, tag })
try {
await this.$store.dispatch('RemoveTag', { users, tag })
} catch (err) {
console.log(err)
return
}
this.$message({
type: 'success',
message: this.$t('users.completed')
})
this.$emit('apply-action')
} }
} }
}, },
...@@ -234,11 +325,6 @@ export default { ...@@ -234,11 +325,6 @@ export default {
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
applyAction() applyAction()
this.$emit('apply-action')
this.$message({
type: 'success',
message: this.$t('users.completed')
})
}).catch(() => { }).catch(() => {
this.$message({ this.$message({
type: 'info', type: 'info',
......
...@@ -83,11 +83,6 @@ export default { ...@@ -83,11 +83,6 @@ export default {
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
if (valid) { if (valid) {
this.$emit('createNewAccount', this.$data.newUserForm) this.$emit('createNewAccount', this.$data.newUserForm)
this.closeDialogWindow()
this.$message({
type: 'success',
message: this.$t('users.completed')
})
} else { } else {
this.$message({ this.$message({
type: 'error', type: 'error',
......
...@@ -234,8 +234,18 @@ export default { ...@@ -234,8 +234,18 @@ export default {
clearSelection() { clearSelection() {
this.$refs.usersTable.clearSelection() this.$refs.usersTable.clearSelection()
}, },
createNewAccount(accountData) { async createNewAccount(accountData) {
this.$store.dispatch('CreateNewAccount', accountData) try {
await this.$store.dispatch('CreateNewAccount', accountData)
} catch (_e) {
return
} finally {
this.dialogFormVisible = false
}
this.$message({
type: 'success',
message: this.$t('users.accountCreated')
})
}, },
getFirstLetter(str) { getFirstLetter(str) {
return str.charAt(0).toUpperCase() return str.charAt(0).toUpperCase()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment