forked from AkkomaGang/admin-fe
Add try/catch to actions that moderate users
This commit is contained in:
parent
274ed16d7e
commit
a66bb599ce
2 changed files with 64 additions and 28 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import { Message } from 'element-ui'
|
||||||
|
import i18n from '@/lang'
|
||||||
import {
|
import {
|
||||||
activateUsers,
|
activateUsers,
|
||||||
addRight,
|
addRight,
|
||||||
|
@ -78,8 +80,13 @@ const users = {
|
||||||
commit('SWAP_USERS', updatedUsers)
|
commit('SWAP_USERS', updatedUsers)
|
||||||
|
|
||||||
const usersNicknames = users.map(user => user.nickname)
|
const usersNicknames = users.map(user => user.nickname)
|
||||||
|
try {
|
||||||
await activateUsers(usersNicknames, getters.authHost, getters.token)
|
await activateUsers(usersNicknames, getters.authHost, getters.token)
|
||||||
|
} catch (_e) {
|
||||||
|
return
|
||||||
|
} finally {
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async AddRight({ commit, dispatch, getters, state }, { users, right }) {
|
async AddRight({ commit, dispatch, getters, state }, { users, right }) {
|
||||||
const updatedUsers = users.map(user => {
|
const updatedUsers = users.map(user => {
|
||||||
|
@ -88,8 +95,13 @@ const users = {
|
||||||
commit('SWAP_USERS', updatedUsers)
|
commit('SWAP_USERS', updatedUsers)
|
||||||
|
|
||||||
const usersNicknames = users.map(user => user.nickname)
|
const usersNicknames = users.map(user => user.nickname)
|
||||||
|
try {
|
||||||
await addRight(usersNicknames, right, getters.authHost, getters.token)
|
await addRight(usersNicknames, right, getters.authHost, getters.token)
|
||||||
|
} catch (_e) {
|
||||||
|
return
|
||||||
|
} finally {
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async AddTag({ commit, dispatch, getters, state }, { users, tag }) {
|
async AddTag({ commit, dispatch, getters, state }, { users, tag }) {
|
||||||
const updatedUsers = users.map(user => {
|
const updatedUsers = users.map(user => {
|
||||||
|
@ -98,16 +110,31 @@ const users = {
|
||||||
commit('SWAP_USERS', updatedUsers)
|
commit('SWAP_USERS', updatedUsers)
|
||||||
|
|
||||||
const nicknames = users.map(user => user.nickname)
|
const nicknames = users.map(user => user.nickname)
|
||||||
|
try {
|
||||||
await tagUser(nicknames, [tag], getters.authHost, getters.token)
|
await tagUser(nicknames, [tag], getters.authHost, getters.token)
|
||||||
|
} catch (_e) {
|
||||||
|
return
|
||||||
|
} finally {
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async ClearFilters({ commit, dispatch, state }) {
|
async ClearFilters({ commit, dispatch, state }) {
|
||||||
commit('CLEAR_USERS_FILTERS')
|
commit('CLEAR_USERS_FILTERS')
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: 1 })
|
dispatch('SearchUsers', { query: state.searchQuery, page: 1 })
|
||||||
},
|
},
|
||||||
async CreateNewAccount({ dispatch, getters, state }, { nickname, email, password }) {
|
async CreateNewAccount({ dispatch, getters, state }, { nickname, email, password }) {
|
||||||
|
try {
|
||||||
await createNewAccount(nickname, email, password, getters.authHost, getters.token)
|
await createNewAccount(nickname, email, password, getters.authHost, getters.token)
|
||||||
|
} catch (_e) {
|
||||||
|
return
|
||||||
|
} finally {
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
||||||
|
}
|
||||||
|
Message({
|
||||||
|
message: i18n.t('users.accountCreated'),
|
||||||
|
type: 'success',
|
||||||
|
duration: 5 * 1000
|
||||||
|
})
|
||||||
},
|
},
|
||||||
async DeactivateUsers({ commit, dispatch, getters, state }, users) {
|
async DeactivateUsers({ commit, dispatch, getters, state }, users) {
|
||||||
const updatedUsers = users.map(user => {
|
const updatedUsers = users.map(user => {
|
||||||
|
@ -116,8 +143,13 @@ const users = {
|
||||||
commit('SWAP_USERS', updatedUsers)
|
commit('SWAP_USERS', updatedUsers)
|
||||||
|
|
||||||
const usersNicknames = users.map(user => user.nickname)
|
const usersNicknames = users.map(user => user.nickname)
|
||||||
|
try {
|
||||||
await deactivateUsers(usersNicknames, getters.authHost, getters.token)
|
await deactivateUsers(usersNicknames, getters.authHost, getters.token)
|
||||||
|
} catch (_e) {
|
||||||
|
return
|
||||||
|
} finally {
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async DeleteRight({ commit, dispatch, getters, state }, { users, right }) {
|
async DeleteRight({ commit, dispatch, getters, state }, { users, right }) {
|
||||||
const updatedUsers = users.map(user => {
|
const updatedUsers = users.map(user => {
|
||||||
|
@ -126,16 +158,24 @@ const users = {
|
||||||
commit('SWAP_USERS', updatedUsers)
|
commit('SWAP_USERS', updatedUsers)
|
||||||
|
|
||||||
const usersNicknames = users.map(user => user.nickname)
|
const usersNicknames = users.map(user => user.nickname)
|
||||||
|
try {
|
||||||
await deleteRight(usersNicknames, right, getters.authHost, getters.token)
|
await deleteRight(usersNicknames, right, getters.authHost, getters.token)
|
||||||
|
} catch (_e) {
|
||||||
|
return
|
||||||
|
} finally {
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async DeleteUsers({ commit, getters, state }, users) {
|
async DeleteUsers({ commit, getters, state }, users) {
|
||||||
|
const usersNicknames = users.map(user => user.nickname)
|
||||||
|
try {
|
||||||
|
await deleteUsers(usersNicknames, getters.authHost, getters.token)
|
||||||
|
} catch (_e) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const deletedUsersIds = users.map(deletedUser => deletedUser.id)
|
const deletedUsersIds = users.map(deletedUser => deletedUser.id)
|
||||||
const updatedUsers = state.fetchedUsers.filter(user => !deletedUsersIds.includes(user.id))
|
const updatedUsers = state.fetchedUsers.filter(user => !deletedUsersIds.includes(user.id))
|
||||||
commit('SET_USERS', updatedUsers)
|
commit('SET_USERS', updatedUsers)
|
||||||
|
|
||||||
const usersNicknames = users.map(user => user.nickname)
|
|
||||||
await deleteUsers(usersNicknames, getters.authHost, getters.token)
|
|
||||||
},
|
},
|
||||||
async RequirePasswordReset({ getters }, user) {
|
async RequirePasswordReset({ getters }, user) {
|
||||||
await requirePasswordReset(user.nickname, getters.authHost, getters.token)
|
await requirePasswordReset(user.nickname, getters.authHost, getters.token)
|
||||||
|
@ -161,8 +201,13 @@ const users = {
|
||||||
commit('SWAP_USERS', updatedUsers)
|
commit('SWAP_USERS', updatedUsers)
|
||||||
|
|
||||||
const nicknames = users.map(user => user.nickname)
|
const nicknames = users.map(user => user.nickname)
|
||||||
|
try {
|
||||||
await untagUser(nicknames, [tag], getters.authHost, getters.token)
|
await untagUser(nicknames, [tag], getters.authHost, getters.token)
|
||||||
|
} catch (_e) {
|
||||||
|
return
|
||||||
|
} finally {
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async SearchUsers({ commit, dispatch, state, getters }, { query, page }) {
|
async SearchUsers({ commit, dispatch, state, getters }, { query, page }) {
|
||||||
if (query.length === 0) {
|
if (query.length === 0) {
|
||||||
|
|
|
@ -245,17 +245,8 @@ export default {
|
||||||
this.$refs.usersTable.clearSelection()
|
this.$refs.usersTable.clearSelection()
|
||||||
},
|
},
|
||||||
async createNewAccount(accountData) {
|
async createNewAccount(accountData) {
|
||||||
try {
|
|
||||||
await this.$store.dispatch('CreateNewAccount', accountData)
|
await this.$store.dispatch('CreateNewAccount', accountData)
|
||||||
} catch (_e) {
|
|
||||||
return
|
|
||||||
} finally {
|
|
||||||
this.createAccountDialogOpen = false
|
this.createAccountDialogOpen = false
|
||||||
}
|
|
||||||
this.$message({
|
|
||||||
type: 'success',
|
|
||||||
message: this.$t('users.accountCreated')
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
getFirstLetter(str) {
|
getFirstLetter(str) {
|
||||||
return str.charAt(0).toUpperCase()
|
return str.charAt(0).toUpperCase()
|
||||||
|
|
Loading…
Reference in a new issue