forked from AkkomaGang/admin-fe
Update api for ActivateUsers and DeactivateUsers actions
This commit is contained in:
parent
f0899ec263
commit
77a153deac
4 changed files with 43 additions and 23 deletions
|
@ -2,6 +2,16 @@ import request from '@/utils/request'
|
|||
import { getToken } from '@/utils/auth'
|
||||
import { baseName } from './utils'
|
||||
|
||||
export async function activateUsers(nicknames, authHost, token) {
|
||||
return await request({
|
||||
baseURL: baseName(authHost),
|
||||
url: `/api/pleroma/admin/users/activate`,
|
||||
method: 'patch',
|
||||
headers: authHeaders(token),
|
||||
data: { nicknames }
|
||||
})
|
||||
}
|
||||
|
||||
export async function addRight(nicknames, right, authHost, token) {
|
||||
return await request({
|
||||
baseURL: baseName(authHost),
|
||||
|
@ -22,6 +32,16 @@ export async function createNewAccount(nickname, email, password, authHost, toke
|
|||
})
|
||||
}
|
||||
|
||||
export async function deactivateUsers(nicknames, authHost, token) {
|
||||
return await request({
|
||||
baseURL: baseName(authHost),
|
||||
url: `/api/pleroma/admin/users/deactivate`,
|
||||
method: 'patch',
|
||||
headers: authHeaders(token),
|
||||
data: { nicknames }
|
||||
})
|
||||
}
|
||||
|
||||
export async function deleteRight(nicknames, right, authHost, token) {
|
||||
return await request({
|
||||
baseURL: baseName(authHost),
|
||||
|
@ -96,15 +116,6 @@ export async function tagUser(nicknames, tags, authHost, token) {
|
|||
})
|
||||
}
|
||||
|
||||
export async function toggleUserActivation(nickname, authHost, token) {
|
||||
return await request({
|
||||
baseURL: baseName(authHost),
|
||||
url: `/api/pleroma/admin/users/${nickname}/toggle_activation`,
|
||||
method: 'patch',
|
||||
headers: authHeaders(token)
|
||||
})
|
||||
}
|
||||
|
||||
export async function untagUser(nicknames, tags, authHost, token) {
|
||||
return await request({
|
||||
baseURL: baseName(authHost),
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import {
|
||||
activateUsers,
|
||||
addRight,
|
||||
createNewAccount,
|
||||
deactivateUsers,
|
||||
deleteRight,
|
||||
deleteUser,
|
||||
fetchUsers,
|
||||
getPasswordResetToken,
|
||||
searchUsers,
|
||||
tagUser,
|
||||
toggleUserActivation,
|
||||
untagUser,
|
||||
requirePasswordReset
|
||||
} from '@/api/users'
|
||||
|
@ -76,6 +77,10 @@ const users = {
|
|||
}
|
||||
},
|
||||
actions: {
|
||||
async ActivateUsers({ commit, getters }, nicknames) {
|
||||
const { data } = await activateUsers(nicknames, getters.authHost, getters.token)
|
||||
commit('SWAP_USERS', data)
|
||||
},
|
||||
async AddRight({ dispatch, getters, state }, { users, right }) {
|
||||
const usersNicknames = users.map(user => user.nickname)
|
||||
await addRight(usersNicknames, right, getters.authHost, getters.token)
|
||||
|
@ -98,6 +103,10 @@ const users = {
|
|||
await createNewAccount(nickname, email, password, getters.authHost, getters.token)
|
||||
dispatch('FetchUsers', { page: state.currentPage })
|
||||
},
|
||||
async DeactivateUsers({ commit, getters }, nicknames) {
|
||||
const { data } = await deactivateUsers(nicknames, getters.authHost, getters.token)
|
||||
commit('SWAP_USERS', data)
|
||||
},
|
||||
async DeleteRight({ dispatch, getters, state }, { users, right }) {
|
||||
const usersNicknames = users.map(user => user.nickname)
|
||||
await deleteRight(usersNicknames, right, getters.authHost, getters.token)
|
||||
|
@ -148,10 +157,6 @@ const users = {
|
|||
loadUsers(commit, page, response.data)
|
||||
}
|
||||
},
|
||||
async ToggleUserActivation({ commit, getters }, nickname) {
|
||||
const { data } = await toggleUserActivation(nickname, getters.authHost, getters.token)
|
||||
commit('SWAP_USER', data)
|
||||
},
|
||||
async ToggleUsersFilter({ commit, dispatch, state }, filters) {
|
||||
const defaultFilters = {
|
||||
local: false,
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item
|
||||
v-if="showDeactivatedButton(report.account)"
|
||||
@click.native="handleDeactivation(report.account)">
|
||||
@click.native="toggleActivation(report.account)">
|
||||
{{ report.account.deactivated ? $t('users.activateAccount') : $t('users.deactivateAccount') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
|
@ -139,17 +139,19 @@ export default {
|
|||
return 'primary'
|
||||
}
|
||||
},
|
||||
handleDeletion(user) {
|
||||
this.$store.dispatch('DeleteUser', user)
|
||||
},
|
||||
parseTimestamp(timestamp) {
|
||||
return moment(timestamp).format('L HH:mm')
|
||||
},
|
||||
showDeactivatedButton(id) {
|
||||
return this.$store.state.user.id !== id
|
||||
},
|
||||
handleDeactivation({ nickname }) {
|
||||
this.$store.dispatch('ToggleUserActivation', nickname)
|
||||
},
|
||||
handleDeletion(user) {
|
||||
this.$store.dispatch('DeleteUser', user)
|
||||
toggleActivation({ deactivated, nickname }) {
|
||||
deactivated
|
||||
? this.$store.dispatch('ActivateUsers', [nickname])
|
||||
: this.$store.dispatch('DeactivateUsers', [nickname])
|
||||
},
|
||||
toggleTag(user, tag) {
|
||||
user.tags.includes(tag)
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
<el-dropdown-item
|
||||
v-if="showDeactivatedButton(scope.row.id)"
|
||||
:divided="showAdminAction(scope.row)"
|
||||
@click.native="handleDeactivation(scope.row)">
|
||||
@click.native="toggleActivation(scope.row)">
|
||||
{{ scope.row.deactivated ? $t('users.activateAccount') : $t('users.deactivateAccount') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
|
@ -275,8 +275,10 @@ export default {
|
|||
|
||||
this.$store.dispatch('RequirePasswordReset', { nickname })
|
||||
},
|
||||
handleDeactivation({ nickname }) {
|
||||
this.$store.dispatch('ToggleUserActivation', nickname)
|
||||
toggleActivation({ deactivated, nickname }) {
|
||||
deactivated
|
||||
? this.$store.dispatch('ActivateUsers', [nickname])
|
||||
: this.$store.dispatch('DeactivateUsers', [nickname])
|
||||
},
|
||||
handleDeletion(user) {
|
||||
this.$store.dispatch('DeleteUser', user)
|
||||
|
|
Loading…
Reference in a new issue