Fetch single status after user was moderated on the status view page

This commit is contained in:
Angelina Filippova 2020-05-19 23:21:03 +03:00
parent fd54181805
commit 1dfc0bacab
2 changed files with 33 additions and 28 deletions

View file

@ -77,16 +77,16 @@ const users = {
} }
}, },
actions: { actions: {
async ActivateUsers({ dispatch, getters }, { users, _userId }) { async ActivateUsers({ dispatch, getters }, { users, _userId, _statusId }) {
const updatedUsers = users.map(user => { const updatedUsers = users.map(user => {
return { ...user, deactivated: false } return { ...user, deactivated: false }
}) })
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)
const callApiFn = async() => await activateUsers(nicknames, getters.authHost, getters.token) const callApiFn = async() => await activateUsers(nicknames, getters.authHost, getters.token)
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId }) dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId, statusId: _statusId })
}, },
async ApplyChanges({ commit, dispatch, state }, { updatedUsers, callApiFn, userId }) { async ApplyChanges({ commit, dispatch, state }, { updatedUsers, callApiFn, userId, statusId }) {
commit('SWAP_USERS', updatedUsers) commit('SWAP_USERS', updatedUsers)
try { try {
@ -96,29 +96,30 @@ const users = {
} finally { } finally {
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage }) dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
} }
if (statusId) {
if (userId) { dispatch('FetchStatus', statusId)
} else if (userId) {
dispatch('FetchUserProfile', { userId, godmode: false }) dispatch('FetchUserProfile', { userId, godmode: false })
} }
dispatch('SuccessMessage') dispatch('SuccessMessage')
}, },
async AddRight({ dispatch, getters }, { users, right, _userId }) { async AddRight({ dispatch, getters }, { users, right, _userId, _statusId }) {
const updatedUsers = users.map(user => { const updatedUsers = users.map(user => {
return user.local ? { ...user, roles: { ...user.roles, [right]: true }} : user return user.local ? { ...user, roles: { ...user.roles, [right]: true }} : user
}) })
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)
const callApiFn = async() => await addRight(nicknames, right, getters.authHost, getters.token) const callApiFn = async() => await addRight(nicknames, right, getters.authHost, getters.token)
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId }) dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId, statusId: _statusId })
}, },
async AddTag({ dispatch, getters }, { users, tag, _userId }) { async AddTag({ dispatch, getters }, { users, tag, _userId, _statusId }) {
const updatedUsers = users.map(user => { const updatedUsers = users.map(user => {
return { ...user, tags: [...user.tags, tag] } return { ...user, tags: [...user.tags, tag] }
}) })
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)
const callApiFn = async() => await tagUser(nicknames, [tag], getters.authHost, getters.token) const callApiFn = async() => await tagUser(nicknames, [tag], getters.authHost, getters.token)
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId }) dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId, statusId: _statusId })
}, },
async ClearFilters({ commit, dispatch, state }) { async ClearFilters({ commit, dispatch, state }) {
commit('CLEAR_USERS_FILTERS') commit('CLEAR_USERS_FILTERS')
@ -134,23 +135,23 @@ const users = {
} }
dispatch('SuccessMessage') dispatch('SuccessMessage')
}, },
async DeactivateUsers({ dispatch, getters }, { users, _userId }) { async DeactivateUsers({ dispatch, getters }, { users, _userId, _statusId }) {
const updatedUsers = users.map(user => { const updatedUsers = users.map(user => {
return { ...user, deactivated: true } return { ...user, deactivated: true }
}) })
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)
const callApiFn = async() => await deactivateUsers(nicknames, getters.authHost, getters.token) const callApiFn = async() => await deactivateUsers(nicknames, getters.authHost, getters.token)
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId }) dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId, statusId: _statusId })
}, },
async ConfirmUsersEmail({ dispatch, getters }, { users, _userId }) { async ConfirmUsersEmail({ dispatch, getters }, { users, _userId, _statusId }) {
const updatedUsers = users.map(user => { const updatedUsers = users.map(user => {
return { ...user, confirmation_pending: false } return { ...user, confirmation_pending: false }
}) })
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)
const callApiFn = async() => await confirmUserEmail(nicknames, getters.authHost, getters.token) const callApiFn = async() => await confirmUserEmail(nicknames, getters.authHost, getters.token)
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId }) dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId, statusId: _statusId })
}, },
async ResendConfirmationEmail({ dispatch, getters }, users) { async ResendConfirmationEmail({ dispatch, getters }, users) {
const usersNicknames = users.map(user => user.nickname) const usersNicknames = users.map(user => user.nickname)
@ -161,16 +162,16 @@ const users = {
} }
dispatch('SuccessMessage') dispatch('SuccessMessage')
}, },
async DeleteRight({ dispatch, getters }, { users, right, _userId }) { async DeleteRight({ dispatch, getters }, { users, right, _userId, _statusId }) {
const updatedUsers = users.map(user => { const updatedUsers = users.map(user => {
return user.local ? { ...user, roles: { ...user.roles, [right]: false }} : user return user.local ? { ...user, roles: { ...user.roles, [right]: false }} : user
}) })
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)
const callApiFn = async() => await deleteRight(nicknames, right, getters.authHost, getters.token) const callApiFn = async() => await deleteRight(nicknames, right, getters.authHost, getters.token)
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId }) dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId, statusId: _statusId })
}, },
async DeleteUsers({ commit, dispatch, getters, state }, { users, _userId }) { async DeleteUsers({ commit, dispatch, getters, state }, { users, _userId, _statusId }) {
const usersNicknames = users.map(user => user.nickname) const usersNicknames = users.map(user => user.nickname)
try { try {
await deleteUsers(usersNicknames, getters.authHost, getters.token) await deleteUsers(usersNicknames, getters.authHost, getters.token)
@ -181,7 +182,7 @@ const users = {
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)
dispatch('FetchUserProfile', { userId: _userId, godmode: false }) dispatch('FetchUserProfile', { userId: _userId, statusId: _statusId, godmode: false })
dispatch('SuccessMessage') dispatch('SuccessMessage')
}, },
async FetchUsers({ commit, dispatch, getters, state }, { page }) { async FetchUsers({ commit, dispatch, getters, state }, { page }) {
@ -198,14 +199,14 @@ const users = {
RemovePasswordToken({ commit }) { RemovePasswordToken({ commit }) {
commit('SET_PASSWORD_RESET_TOKEN', { link: '', token: '' }) commit('SET_PASSWORD_RESET_TOKEN', { link: '', token: '' })
}, },
async RemoveTag({ dispatch, getters }, { users, tag, _userId }) { async RemoveTag({ dispatch, getters }, { users, tag, _userId, _statusId }) {
const updatedUsers = users.map(user => { const updatedUsers = users.map(user => {
return { ...user, tags: user.tags.filter(userTag => userTag !== tag) } return { ...user, tags: user.tags.filter(userTag => userTag !== tag) }
}) })
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)
const callApiFn = async() => await untagUser(nicknames, [tag], getters.authHost, getters.token) const callApiFn = async() => await untagUser(nicknames, [tag], getters.authHost, getters.token)
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId }) dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId, statusId: _statusId })
}, },
async RequirePasswordReset({ dispatch, getters }, users) { async RequirePasswordReset({ dispatch, getters }, users) {
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)

View file

@ -5,7 +5,7 @@
{{ $t('users.moderation') }} {{ $t('users.moderation') }}
<i v-if="isDesktop" class="el-icon-arrow-down el-icon--right"/> <i v-if="isDesktop" class="el-icon-arrow-down el-icon--right"/>
</span> </span>
<el-button v-if="page === 'userPage'" class="moderate-user-button"> <el-button v-if="page === 'userPage' || page === 'statusPage'" class="moderate-user-button">
<span class="moderate-user-button-container"> <span class="moderate-user-button-container">
<span> <span>
<i class="el-icon-edit" /> <i class="el-icon-edit" />
@ -115,6 +115,10 @@ export default {
page: { page: {
type: String, type: String,
default: 'users' default: 'users'
},
statusId: {
type: String,
default: ''
} }
}, },
computed: { computed: {
@ -131,10 +135,10 @@ export default {
this.$store.dispatch('ResendConfirmationEmail', [user]) this.$store.dispatch('ResendConfirmationEmail', [user])
}, },
handleDeletion(user) { handleDeletion(user) {
this.$store.dispatch('DeleteUsers', { users: [user], _userId: user.id }) this.$store.dispatch('DeleteUsers', { users: [user], _userId: user.id, _statusId: this.statusId })
}, },
handleEmailConfirmation(user) { handleEmailConfirmation(user) {
this.$store.dispatch('ConfirmUsersEmail', { users: [user], _userId: user.id }) this.$store.dispatch('ConfirmUsersEmail', { users: [user], _userId: user.id, _statusId: this.statusId })
}, },
requirePasswordReset(user) { requirePasswordReset(user) {
const mailerEnabled = this.$store.state.user.nodeInfo.metadata.mailerEnabled const mailerEnabled = this.$store.state.user.nodeInfo.metadata.mailerEnabled
@ -152,18 +156,18 @@ export default {
}, },
toggleActivation(user) { toggleActivation(user) {
user.deactivated user.deactivated
? this.$store.dispatch('ActivateUsers', { users: [user], _userId: user.id }) ? this.$store.dispatch('ActivateUsers', { users: [user], _userId: user.id, _statusId: this.statusId })
: this.$store.dispatch('DeactivateUsers', { users: [user], _userId: user.id }) : this.$store.dispatch('DeactivateUsers', { users: [user], _userId: user.id, _statusId: this.statusId })
}, },
toggleTag(user, tag) { toggleTag(user, tag) {
user.tags.includes(tag) user.tags.includes(tag)
? this.$store.dispatch('RemoveTag', { users: [user], tag, _userId: user.id }) ? this.$store.dispatch('RemoveTag', { users: [user], tag, _userId: user.id, _statusId: this.statusId })
: this.$store.dispatch('AddTag', { users: [user], tag, _userId: user.id }) : this.$store.dispatch('AddTag', { users: [user], tag, _userId: user.id, _statusId: this.statusId })
}, },
toggleUserRight(user, right) { toggleUserRight(user, right) {
user.roles[right] user.roles[right]
? this.$store.dispatch('DeleteRight', { users: [user], right, _userId: user.id }) ? this.$store.dispatch('DeleteRight', { users: [user], right, _userId: user.id, _statusId: this.statusId })
: this.$store.dispatch('AddRight', { users: [user], right, _userId: user.id }) : this.$store.dispatch('AddRight', { users: [user], right, _userId: user.id, _statusId: this.statusId })
} }
} }
} }