forked from AkkomaGang/admin-fe
Update api for AddRight and DeleteRight actions
This commit is contained in:
parent
e500401698
commit
f0899ec263
4 changed files with 28 additions and 16 deletions
|
@ -48,7 +48,7 @@ export async function searchUsers(query, filters, authHost, token, page = 1) {
|
|||
}})
|
||||
}
|
||||
|
||||
export async function addRight(nickname, right, authHost, token) {
|
||||
export async function addRight(nicknames, right, authHost, token) {
|
||||
return Promise.resolve({ data:
|
||||
{ [`is_${right}`]: true }
|
||||
})
|
||||
|
|
|
@ -2,12 +2,13 @@ import request from '@/utils/request'
|
|||
import { getToken } from '@/utils/auth'
|
||||
import { baseName } from './utils'
|
||||
|
||||
export async function addRight(nickname, right, authHost, token) {
|
||||
export async function addRight(nicknames, right, authHost, token) {
|
||||
return await request({
|
||||
baseURL: baseName(authHost),
|
||||
url: `/api/pleroma/admin/users/${nickname}/permission_group/${right}`,
|
||||
url: `/api/pleroma/admin/users/permission_group/${right}`,
|
||||
method: 'post',
|
||||
headers: authHeaders(token)
|
||||
headers: authHeaders(token),
|
||||
data: { nicknames }
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -21,12 +22,13 @@ export async function createNewAccount(nickname, email, password, authHost, toke
|
|||
})
|
||||
}
|
||||
|
||||
export async function deleteRight(nickname, right, authHost, token) {
|
||||
export async function deleteRight(nicknames, right, authHost, token) {
|
||||
return await request({
|
||||
baseURL: baseName(authHost),
|
||||
url: `/api/pleroma/admin/users/${nickname}/permission_group/${right}`,
|
||||
url: `/api/pleroma/admin/users/permission_group/${right}`,
|
||||
method: 'delete',
|
||||
headers: authHeaders(token)
|
||||
headers: authHeaders(token),
|
||||
data: { nicknames }
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -76,6 +76,14 @@ const users = {
|
|||
}
|
||||
},
|
||||
actions: {
|
||||
async AddRight({ dispatch, getters, state }, { users, right }) {
|
||||
const usersNicknames = users.map(user => user.nickname)
|
||||
await addRight(usersNicknames, right, getters.authHost, getters.token)
|
||||
|
||||
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 }) {
|
||||
const nicknames = users.map(user => user.nickname)
|
||||
await tagUser(nicknames, [tag], getters.authHost, getters.token)
|
||||
|
@ -90,6 +98,14 @@ const users = {
|
|||
await createNewAccount(nickname, email, password, getters.authHost, getters.token)
|
||||
dispatch('FetchUsers', { page: state.currentPage })
|
||||
},
|
||||
async DeleteRight({ dispatch, getters, state }, { users, right }) {
|
||||
const usersNicknames = users.map(user => user.nickname)
|
||||
await deleteRight(usersNicknames, right, getters.authHost, getters.token)
|
||||
|
||||
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) {
|
||||
const { data } = await deleteUser(user.nickname, getters.authHost, getters.token)
|
||||
const users = state.fetchedUsers.filter(user => user.nickname !== data)
|
||||
|
@ -146,14 +162,6 @@ const users = {
|
|||
const currentFilters = { ...defaultFilters, ...filters }
|
||||
commit('SET_USERS_FILTERS', currentFilters)
|
||||
dispatch('SearchUsers', { query: state.searchQuery, page: 1 })
|
||||
},
|
||||
async ToggleRight({ commit, getters }, { user, right }) {
|
||||
user.roles[right]
|
||||
? await deleteRight(user.nickname, right, getters.authHost, getters.token)
|
||||
: await addRight(user.nickname, right, getters.authHost, getters.token)
|
||||
|
||||
const updatedUser = { ...user, roles: { ...user.roles, [right]: !user.roles[right] }}
|
||||
commit('SWAP_USER', updatedUser)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -308,7 +308,9 @@ export default {
|
|||
: this.$store.dispatch('AddTag', { users: [user], tag })
|
||||
},
|
||||
toggleUserRight(user, right) {
|
||||
this.$store.dispatch('ToggleRight', { user, right })
|
||||
user.roles[right]
|
||||
? this.$store.dispatch('DeleteRight', { users: [user], right })
|
||||
: this.$store.dispatch('AddRight', { users: [user], right })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue