2019-02-23 21:40:26 +00:00
|
|
|
import request from '@/utils/request'
|
2019-03-22 20:58:58 +00:00
|
|
|
import { getToken } from '@/utils/auth'
|
2019-03-23 14:09:48 +00:00
|
|
|
import { baseName } from './utils'
|
2019-02-23 21:40:26 +00:00
|
|
|
|
2019-03-29 14:25:53 +00:00
|
|
|
export async function fetchUsers(filters, authHost, token, page = 1) {
|
2019-02-23 21:40:26 +00:00
|
|
|
return await request({
|
2019-03-23 14:09:48 +00:00
|
|
|
baseURL: baseName(authHost),
|
2019-03-29 14:25:53 +00:00
|
|
|
url: `/api/pleroma/admin/users?page=${page}&filters=${filters}`,
|
2019-03-22 20:58:58 +00:00
|
|
|
method: 'get',
|
2019-03-22 21:18:57 +00:00
|
|
|
headers: authHeaders(token)
|
2019-02-23 21:40:26 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-03-23 14:09:48 +00:00
|
|
|
export async function toggleUserActivation(nickname, authHost, token) {
|
2019-02-26 19:50:25 +00:00
|
|
|
return await request({
|
2019-03-23 14:09:48 +00:00
|
|
|
baseURL: baseName(authHost),
|
2019-02-26 19:50:25 +00:00
|
|
|
url: `/api/pleroma/admin/users/${nickname}/toggle_activation`,
|
2019-03-22 20:58:58 +00:00
|
|
|
method: 'patch',
|
2019-03-22 21:18:57 +00:00
|
|
|
headers: authHeaders(token)
|
2019-02-26 19:50:25 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-03-29 14:25:53 +00:00
|
|
|
export async function searchUsers(query, filters, authHost, token, page = 1) {
|
2019-03-01 17:32:03 +00:00
|
|
|
return await request({
|
2019-03-23 14:09:48 +00:00
|
|
|
baseURL: baseName(authHost),
|
2019-03-29 14:25:53 +00:00
|
|
|
url: `/api/pleroma/admin/users?query=${query}&page=${page}&filters=${filters}`,
|
2019-03-22 20:58:58 +00:00
|
|
|
method: 'get',
|
2019-03-22 21:18:57 +00:00
|
|
|
headers: authHeaders(token)
|
2019-03-01 17:32:03 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-03-23 14:09:48 +00:00
|
|
|
export async function addRight(nickname, right, authHost, token) {
|
2019-03-22 21:18:57 +00:00
|
|
|
return await request({
|
2019-03-23 14:09:48 +00:00
|
|
|
baseURL: baseName(authHost),
|
2019-03-22 21:18:57 +00:00
|
|
|
url: `/api/pleroma/admin/permission_group/${nickname}/${right}`,
|
|
|
|
method: 'post',
|
|
|
|
headers: authHeaders(token)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-03-23 14:09:48 +00:00
|
|
|
export async function deleteRight(nickname, right, authHost, token) {
|
2019-03-22 21:18:57 +00:00
|
|
|
return await request({
|
2019-03-23 14:09:48 +00:00
|
|
|
baseURL: baseName(authHost),
|
2019-03-22 21:18:57 +00:00
|
|
|
url: `/api/pleroma/admin/permission_group/${nickname}/${right}`,
|
|
|
|
method: 'delete',
|
|
|
|
headers: authHeaders(token)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-03-23 14:09:48 +00:00
|
|
|
export async function deleteUser(nickname, authHost, token) {
|
2019-03-22 21:18:57 +00:00
|
|
|
return await request({
|
2019-03-23 14:09:48 +00:00
|
|
|
baseURL: baseName(authHost),
|
2019-03-22 21:18:57 +00:00
|
|
|
url: `/api/pleroma/admin/user.json?nickname=${nickname}`,
|
|
|
|
method: 'delete',
|
|
|
|
headers: authHeaders(token)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-03-23 14:09:48 +00:00
|
|
|
export async function tagUser(nickname, tag, authHost, token) {
|
2019-03-22 21:18:57 +00:00
|
|
|
return await request({
|
2019-03-23 14:09:48 +00:00
|
|
|
baseURL: baseName(authHost),
|
2019-03-22 21:18:57 +00:00
|
|
|
url: '/api/pleroma/admin/users/tag',
|
|
|
|
method: 'put',
|
|
|
|
headers: authHeaders(token),
|
|
|
|
data: { nicknames: [nickname], tags: [tag] }
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-03-23 14:09:48 +00:00
|
|
|
export async function untagUser(nickname, tag, authHost, token) {
|
2019-03-22 21:18:57 +00:00
|
|
|
return await request({
|
2019-03-23 14:09:48 +00:00
|
|
|
baseURL: baseName(authHost),
|
2019-03-22 21:18:57 +00:00
|
|
|
url: '/api/pleroma/admin/users/tag',
|
|
|
|
method: 'delete',
|
|
|
|
headers: authHeaders(token),
|
|
|
|
data: { nicknames: [nickname], tags: [tag] }
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {}
|