Remove multiple calls of functions that moderate users
This commit is contained in:
parent
d0025dfe7a
commit
58573a7de8
1 changed files with 32 additions and 50 deletions
|
@ -150,87 +150,69 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
mappers() {
|
mappers() {
|
||||||
const applyActionToAllUsers = (filteredUsers, fn) => Promise.all(filteredUsers.map(fn))
|
const applyAction = (users, dispatchAction) => {
|
||||||
.then(() => {
|
try {
|
||||||
|
dispatchAction(users)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
this.$message({
|
this.$message({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: this.$t('users.completed')
|
message: this.$t('users.completed')
|
||||||
})
|
})
|
||||||
this.$emit('apply-action')
|
this.$emit('apply-action')
|
||||||
}).catch((err) => {
|
}
|
||||||
console.log(err)
|
|
||||||
return
|
|
||||||
})
|
|
||||||
return {
|
return {
|
||||||
grantRight: (right) => () => {
|
grantRight: (right) => () => {
|
||||||
const filterUsersFn = 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
|
||||||
const toggleRightFn = async(user) => await this.$store.dispatch('ToggleRight', { user, right })
|
const addRightFn = async(users) => await this.$store.dispatch('AddRight', { users, right })
|
||||||
const filtered = this.selectedUsers.filter(filterUsersFn)
|
const filtered = this.selectedUsers.filter(filterUsersFn)
|
||||||
|
|
||||||
applyActionToAllUsers(filtered, toggleRightFn)
|
applyAction(filtered, addRightFn)
|
||||||
},
|
},
|
||||||
revokeRight: (right) => () => {
|
revokeRight: (right) => () => {
|
||||||
const filterUsersFn = 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
|
||||||
const toggleRightFn = async(user) => await this.$store.dispatch('ToggleRight', { user, right })
|
const deleteRightFn = async(users) => await this.$store.dispatch('DeleteRight', { users, right })
|
||||||
const filtered = this.selectedUsers.filter(filterUsersFn)
|
const filtered = this.selectedUsers.filter(filterUsersFn)
|
||||||
|
|
||||||
applyActionToAllUsers(filtered, toggleRightFn)
|
applyAction(filtered, deleteRightFn)
|
||||||
},
|
},
|
||||||
activate: () => {
|
activate: () => {
|
||||||
const filtered = this.selectedUsers.filter(user => user.deactivated && this.$store.state.user.id !== user.id)
|
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)
|
const activateUsersFn = async(users) => await this.$store.dispatch('ActivateUsers', users)
|
||||||
|
|
||||||
applyActionToAllUsers(filtered, toggleActivationFn)
|
applyAction(filtered, activateUsersFn)
|
||||||
},
|
},
|
||||||
deactivate: () => {
|
deactivate: () => {
|
||||||
const filtered = this.selectedUsers.filter(user => !user.deactivated && this.$store.state.user.id !== user.id)
|
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)
|
const deactivateUsersFn = async(users) => await this.$store.dispatch('DeactivateUsers', users)
|
||||||
|
|
||||||
applyActionToAllUsers(filtered, toggleActivationFn)
|
applyAction(filtered, deactivateUsersFn)
|
||||||
},
|
},
|
||||||
remove: () => {
|
remove: () => {
|
||||||
const filtered = this.selectedUsers.filter(user => this.$store.state.user.id !== user.id)
|
const filtered = this.selectedUsers.filter(user => this.$store.state.user.id !== user.id)
|
||||||
const deleteAccountFn = async(user) => await this.$store.dispatch('DeleteUser', user)
|
const deleteAccountFn = async(user) => await this.$store.dispatch('DeleteUser', user)
|
||||||
|
|
||||||
applyActionToAllUsers(filtered, deleteAccountFn)
|
applyAction(filtered, deleteAccountFn)
|
||||||
},
|
},
|
||||||
addTag: (tag) => async() => {
|
addTag: (tag) => () => {
|
||||||
const filterUsersFn = user => tag === 'disable_remote_subscription' || tag === 'disable_any_subscription'
|
const filtered = this.selectedUsers.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)
|
const addTagFn = async(users) => await this.$store.dispatch('AddTag', { users, tag })
|
||||||
|
|
||||||
try {
|
applyAction(filtered, addTagFn)
|
||||||
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) => async() => {
|
removeTag: (tag) => async() => {
|
||||||
const filterUsersFn = user => tag === 'disable_remote_subscription' || tag === 'disable_any_subscription'
|
const filtered = this.selectedUsers.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)
|
const removeTagFn = async(users) => await this.$store.dispatch('RemoveTag', { users, tag })
|
||||||
|
|
||||||
try {
|
applyAction(filtered, removeTagFn)
|
||||||
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')
|
|
||||||
},
|
},
|
||||||
requirePasswordReset: () => {
|
requirePasswordReset: () => {
|
||||||
this.selectedUsers.map(user => this.$store.dispatch('RequirePasswordReset', user))
|
this.selectedUsers.map(user => this.$store.dispatch('RequirePasswordReset', user))
|
||||||
|
|
Loading…
Reference in a new issue