forked from AkkomaGang/admin-fe
Update api function and module action for user deletion
This commit is contained in:
parent
58573a7de8
commit
4d58527201
4 changed files with 24 additions and 32 deletions
|
@ -52,12 +52,13 @@ export async function deleteRight(nicknames, right, authHost, token) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteUser(nickname, authHost, token) {
|
export async function deleteUsers(nicknames, authHost, token) {
|
||||||
return await request({
|
return await request({
|
||||||
baseURL: baseName(authHost),
|
baseURL: baseName(authHost),
|
||||||
url: `/api/pleroma/admin/users?nickname=${nickname}`,
|
url: `/api/pleroma/admin/users`,
|
||||||
method: 'delete',
|
method: 'delete',
|
||||||
headers: authHeaders(token)
|
headers: authHeaders(token),
|
||||||
|
data: { nicknames }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
createNewAccount,
|
createNewAccount,
|
||||||
deactivateUsers,
|
deactivateUsers,
|
||||||
deleteRight,
|
deleteRight,
|
||||||
deleteUser,
|
deleteUsers,
|
||||||
fetchUsers,
|
fetchUsers,
|
||||||
getPasswordResetToken,
|
getPasswordResetToken,
|
||||||
searchUsers,
|
searchUsers,
|
||||||
|
@ -77,24 +77,20 @@ const users = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async ActivateUsers({ commit, getters }, users) {
|
async ActivateUsers({ dispatch, getters, state }, users) {
|
||||||
const usersNicknames = users.map(user => user.nickname)
|
const usersNicknames = users.map(user => user.nickname)
|
||||||
const { data } = await activateUsers(usersNicknames, getters.authHost, getters.token)
|
await activateUsers(usersNicknames, getters.authHost, getters.token)
|
||||||
commit('SWAP_USERS', data)
|
dispatch('FetchUsers', { page: state.currentPage })
|
||||||
},
|
},
|
||||||
async AddRight({ dispatch, getters, state }, { users, right }) {
|
async AddRight({ dispatch, getters, state }, { users, right }) {
|
||||||
const usersNicknames = users.map(user => user.nickname)
|
const usersNicknames = users.map(user => user.nickname)
|
||||||
await addRight(usersNicknames, right, getters.authHost, getters.token)
|
await addRight(usersNicknames, right, getters.authHost, getters.token)
|
||||||
|
|
||||||
dispatch('FetchUsers', { page: state.currentPage })
|
dispatch('FetchUsers', { page: state.currentPage })
|
||||||
// const updatedUser = { ...user, roles: { ...user.roles, [right]: !user.roles[right] }}
|
|
||||||
// commit('SWAP_USER', updatedUser)
|
|
||||||
},
|
},
|
||||||
async AddTag({ commit, getters }, { users, tag }) {
|
async AddTag({ dispatch, getters, state }, { users, tag }) {
|
||||||
const nicknames = users.map(user => user.nickname)
|
const nicknames = users.map(user => user.nickname)
|
||||||
await tagUser(nicknames, [tag], getters.authHost, getters.token)
|
await tagUser(nicknames, [tag], getters.authHost, getters.token)
|
||||||
|
dispatch('FetchUsers', { page: state.currentPage })
|
||||||
commit('SWAP_USERS', users.map(user => ({ ...user, tags: [...user.tags, tag] })))
|
|
||||||
},
|
},
|
||||||
async ClearFilters({ commit, dispatch, state }) {
|
async ClearFilters({ commit, dispatch, state }) {
|
||||||
commit('CLEAR_USERS_FILTERS')
|
commit('CLEAR_USERS_FILTERS')
|
||||||
|
@ -104,46 +100,41 @@ const users = {
|
||||||
await createNewAccount(nickname, email, password, getters.authHost, getters.token)
|
await createNewAccount(nickname, email, password, getters.authHost, getters.token)
|
||||||
dispatch('FetchUsers', { page: state.currentPage })
|
dispatch('FetchUsers', { page: state.currentPage })
|
||||||
},
|
},
|
||||||
async DeactivateUsers({ commit, getters }, users) {
|
async DeactivateUsers({ dispatch, getters, state }, users) {
|
||||||
const usersNicknames = users.map(user => user.nickname)
|
const usersNicknames = users.map(user => user.nickname)
|
||||||
const { data } = await deactivateUsers(usersNicknames, getters.authHost, getters.token)
|
await deactivateUsers(usersNicknames, getters.authHost, getters.token)
|
||||||
commit('SWAP_USERS', data)
|
dispatch('FetchUsers', { page: state.currentPage })
|
||||||
},
|
},
|
||||||
async DeleteRight({ dispatch, getters, state }, { users, right }) {
|
async DeleteRight({ dispatch, getters, state }, { users, right }) {
|
||||||
const usersNicknames = users.map(user => user.nickname)
|
const usersNicknames = users.map(user => user.nickname)
|
||||||
await deleteRight(usersNicknames, right, getters.authHost, getters.token)
|
await deleteRight(usersNicknames, right, getters.authHost, getters.token)
|
||||||
|
|
||||||
dispatch('FetchUsers', { page: state.currentPage })
|
dispatch('FetchUsers', { page: state.currentPage })
|
||||||
// const updatedUser = { ...user, roles: { ...user.roles, [right]: !user.roles[right] }}
|
|
||||||
// commit('SWAP_USER', updatedUser)
|
|
||||||
},
|
},
|
||||||
async DeleteUser({ commit, getters, state }, user) {
|
async DeleteUsers({ dispatch, getters, state }, users) {
|
||||||
const { data } = await deleteUser(user.nickname, getters.authHost, getters.token)
|
const usersNicknames = users.map(user => user.nickname)
|
||||||
const users = state.fetchedUsers.filter(user => user.nickname !== data)
|
await deleteUsers(usersNicknames, getters.authHost, getters.token)
|
||||||
commit('SET_USERS', users)
|
|
||||||
},
|
},
|
||||||
async RequirePasswordReset({ commit, getters, state }, user) {
|
async RequirePasswordReset({ getters }, user) {
|
||||||
await requirePasswordReset(user.nickname, getters.authHost, getters.token)
|
await requirePasswordReset(user.nickname, getters.authHost, getters.token)
|
||||||
},
|
},
|
||||||
async FetchUsers({ commit, state, getters, dispatch }, { page }) {
|
async FetchUsers({ commit, dispatch, getters, state }, { page }) {
|
||||||
commit('SET_LOADING', true)
|
commit('SET_LOADING', true)
|
||||||
const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join()
|
const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join()
|
||||||
const response = await fetchUsers(filters, getters.authHost, getters.token, page)
|
const response = await fetchUsers(filters, getters.authHost, getters.token, page)
|
||||||
await dispatch('GetNodeInfo')
|
// await dispatch('GetNodeInfo')
|
||||||
loadUsers(commit, page, response.data)
|
loadUsers(commit, page, response.data)
|
||||||
},
|
},
|
||||||
async GetPasswordResetToken({ commit, state, getters }, nickname) {
|
async GetPasswordResetToken({ commit, getters }, nickname) {
|
||||||
const { data } = await getPasswordResetToken(nickname, getters.authHost, getters.token)
|
const { data } = await getPasswordResetToken(nickname, getters.authHost, getters.token)
|
||||||
commit('SET_PASSWORD_RESET_TOKEN', data)
|
commit('SET_PASSWORD_RESET_TOKEN', data)
|
||||||
},
|
},
|
||||||
RemovePasswordToken({ commit }) {
|
RemovePasswordToken({ commit }) {
|
||||||
commit('SET_PASSWORD_RESET_TOKEN', { link: '', token: '' })
|
commit('SET_PASSWORD_RESET_TOKEN', { link: '', token: '' })
|
||||||
},
|
},
|
||||||
async RemoveTag({ commit, getters }, { users, tag }) {
|
async RemoveTag({ dispatch, getters, state }, { users, tag }) {
|
||||||
const nicknames = users.map(user => user.nickname)
|
const nicknames = users.map(user => user.nickname)
|
||||||
await untagUser(nicknames, [tag], getters.authHost, getters.token)
|
await untagUser(nicknames, [tag], getters.authHost, getters.token)
|
||||||
|
dispatch('FetchUsers', { page: state.currentPage })
|
||||||
commit('SWAP_USERS', users.map(user => ({ ...user, tags: user.tags.filter(userTag => userTag !== tag) })))
|
|
||||||
},
|
},
|
||||||
async SearchUsers({ commit, dispatch, state, getters }, { query, page }) {
|
async SearchUsers({ commit, dispatch, state, getters }, { query, page }) {
|
||||||
if (query.length === 0) {
|
if (query.length === 0) {
|
||||||
|
|
|
@ -140,7 +140,7 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleDeletion(user) {
|
handleDeletion(user) {
|
||||||
this.$store.dispatch('DeleteUser', user)
|
this.$store.dispatch('DeleteUsers', [user])
|
||||||
},
|
},
|
||||||
parseTimestamp(timestamp) {
|
parseTimestamp(timestamp) {
|
||||||
return moment(timestamp).format('L HH:mm')
|
return moment(timestamp).format('L HH:mm')
|
||||||
|
|
|
@ -281,7 +281,7 @@ export default {
|
||||||
: this.$store.dispatch('DeactivateUsers', [user])
|
: this.$store.dispatch('DeactivateUsers', [user])
|
||||||
},
|
},
|
||||||
handleDeletion(user) {
|
handleDeletion(user) {
|
||||||
this.$store.dispatch('DeleteUser', user)
|
this.$store.dispatch('DeleteUsers', [user])
|
||||||
},
|
},
|
||||||
handlePageChange(page) {
|
handlePageChange(page) {
|
||||||
const searchQuery = this.$store.state.users.searchQuery
|
const searchQuery = this.$store.state.users.searchQuery
|
||||||
|
|
Loading…
Reference in a new issue