mirror of
https://akkoma.dev/AkkomaGang/akkoma-fe
synced 2025-04-30 19:19:29 +08:00
Implement admin user list API endpoint
This commit is contained in:
parent
50b919fb23
commit
db7395b502
3 changed files with 46 additions and 0 deletions
|
@ -185,6 +185,9 @@ export const mutations = {
|
||||||
user['followedTagIds'] = []
|
user['followedTagIds'] = []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
adminSetUsers (state, users) {
|
||||||
|
state.adminUsers = users
|
||||||
|
},
|
||||||
addNewUsers (state, users) {
|
addNewUsers (state, users) {
|
||||||
each(users, (user) => {
|
each(users, (user) => {
|
||||||
if (user.relationship) {
|
if (user.relationship) {
|
||||||
|
@ -294,6 +297,7 @@ export const defaultState = {
|
||||||
currentUser: false,
|
currentUser: false,
|
||||||
users: [],
|
users: [],
|
||||||
usersObject: {},
|
usersObject: {},
|
||||||
|
adminUsers: [],
|
||||||
signUpPending: false,
|
signUpPending: false,
|
||||||
signUpErrors: [],
|
signUpErrors: [],
|
||||||
relationships: {},
|
relationships: {},
|
||||||
|
@ -306,6 +310,14 @@ const users = {
|
||||||
mutations,
|
mutations,
|
||||||
getters,
|
getters,
|
||||||
actions: {
|
actions: {
|
||||||
|
fetchUsers (store, params = false) {
|
||||||
|
return store.rootState.api.backendInteractor.fetchUsers(params)
|
||||||
|
.then((users) => {
|
||||||
|
store.commit('adminSetUsers', users)
|
||||||
|
users.forEach(user => store.dispatch('fetchUserIfMissing', user.id))
|
||||||
|
return users
|
||||||
|
})
|
||||||
|
},
|
||||||
fetchUserIfMissing (store, id) {
|
fetchUserIfMissing (store, id) {
|
||||||
if (!store.getters.findUser(id)) {
|
if (!store.getters.findUser(id)) {
|
||||||
store.dispatch('fetchUser', id)
|
store.dispatch('fetchUser', id)
|
||||||
|
|
|
@ -557,6 +557,29 @@ const fetchStatusHistory = ({ status, credentials }) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fetchUsers = ({ filters, name, page, actorTypes, credentials }) => {
|
||||||
|
const url = ADMIN_USERS_URL
|
||||||
|
const params = []
|
||||||
|
|
||||||
|
if (filters) {
|
||||||
|
params.push(['filters', filters.join(',')])
|
||||||
|
}
|
||||||
|
if (name) {
|
||||||
|
params.push(['name', name])
|
||||||
|
}
|
||||||
|
if (page) {
|
||||||
|
params.push(['page', page])
|
||||||
|
}
|
||||||
|
if (actorTypes) {
|
||||||
|
actorTypes.forEach(type => (params.push(['actor_types[]', type])))
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&')
|
||||||
|
return promisedRequest({ url: url + `?${queryString}`, credentials })
|
||||||
|
.then((data) => data.users)
|
||||||
|
.then((data) => data.map(parseUser))
|
||||||
|
}
|
||||||
|
|
||||||
const tagUser = ({ tag, credentials, user }) => {
|
const tagUser = ({ tag, credentials, user }) => {
|
||||||
const screenName = user.screen_name
|
const screenName = user.screen_name
|
||||||
const form = {
|
const form = {
|
||||||
|
@ -1762,6 +1785,7 @@ const apiService = {
|
||||||
fetchBlocks,
|
fetchBlocks,
|
||||||
fetchOAuthTokens,
|
fetchOAuthTokens,
|
||||||
revokeOAuthToken,
|
revokeOAuthToken,
|
||||||
|
fetchUsers,
|
||||||
tagUser,
|
tagUser,
|
||||||
untagUser,
|
untagUser,
|
||||||
deleteUser,
|
deleteUser,
|
||||||
|
|
|
@ -43,6 +43,9 @@ export const parseUser = (data) => {
|
||||||
// case for users in "mentions" property for statuses in MastoAPI
|
// case for users in "mentions" property for statuses in MastoAPI
|
||||||
const mastoShort = masto && !data.hasOwnProperty('avatar')
|
const mastoShort = masto && !data.hasOwnProperty('avatar')
|
||||||
|
|
||||||
|
// account format from the admin API
|
||||||
|
const admin = data.hasOwnProperty('actor_type')
|
||||||
|
|
||||||
output.id = String(data.id)
|
output.id = String(data.id)
|
||||||
output._original = data // used for server-side settings
|
output._original = data // used for server-side settings
|
||||||
|
|
||||||
|
@ -139,6 +142,13 @@ export const parseUser = (data) => {
|
||||||
|
|
||||||
// TODO: handle is_local
|
// TODO: handle is_local
|
||||||
output.is_local = !output.screen_name.includes('@')
|
output.is_local = !output.screen_name.includes('@')
|
||||||
|
} else if (admin) {
|
||||||
|
output.screen_name = data.nickname
|
||||||
|
output.name = data.display_name
|
||||||
|
output.profile_image_url = data.avatar
|
||||||
|
output.profile_image_url_original = data.avatar
|
||||||
|
output.is_local = data.local
|
||||||
|
output.emoji = []
|
||||||
} else {
|
} else {
|
||||||
output.screen_name = data.screen_name
|
output.screen_name = data.screen_name
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue