qb-admin-fe/src/api/users.js

190 lines
5.1 KiB
JavaScript
Raw Normal View History

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
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) {
2019-02-23 21:40:26 +00:00
return await request({
2019-03-23 14:09:48 +00:00
baseURL: baseName(authHost),
url: `/api/pleroma/admin/users/permission_group/${right}`,
2019-06-11 15:13:48 +00:00
method: 'post',
headers: authHeaders(token),
data: { nicknames }
2019-02-23 21:40:26 +00:00
})
}
2019-06-11 15:13:48 +00:00
export async function createNewAccount(nickname, email, password, 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-06-11 15:13:48 +00:00
url: '/api/pleroma/admin/users',
method: 'post',
headers: authHeaders(token),
2019-09-23 19:00:28 +00:00
data: { users: [{ nickname, email, password }] }
2019-02-26 19:50:25 +00:00
})
}
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) {
2019-03-01 17:32:03 +00:00
return await request({
2019-03-23 14:09:48 +00:00
baseURL: baseName(authHost),
url: `/api/pleroma/admin/users/permission_group/${right}`,
2019-06-11 15:13:48 +00:00
method: 'delete',
headers: authHeaders(token),
data: { nicknames }
2019-03-01 17:32:03 +00:00
})
}
export async function deleteUsers(nicknames, authHost, token) {
2019-03-22 21:18:57 +00:00
return await request({
2019-03-23 14:09:48 +00:00
baseURL: baseName(authHost),
url: `/api/pleroma/admin/users`,
2019-06-11 15:13:48 +00:00
method: 'delete',
headers: authHeaders(token),
data: { nicknames }
2019-03-22 21:18:57 +00:00
})
}
export async function disableMfa(nickname, authHost, token) {
return await request({
baseURL: baseName(authHost),
url: `/api/pleroma/admin/users/disable_mfa`,
method: 'put',
headers: authHeaders(token),
data: { nickname }
})
}
export async function fetchUser(id, authHost, token) {
return await request({
baseURL: baseName(authHost),
url: `/api/pleroma/admin/users/${id}`,
method: 'get',
headers: authHeaders(token)
})
}
export async function fetchUserCredentials(nickname, authHost, token) {
return await request({
baseURL: baseName(authHost),
url: `/api/pleroma/admin/users/${nickname}/credentials`,
method: 'get',
headers: authHeaders(token)
})
}
export async function updateUserCredentials(nickname, credentials, authHost, token) {
return await request({
baseURL: baseName(authHost),
url: `/api/pleroma/admin/users/${nickname}/credentials`,
method: 'patch',
headers: authHeaders(token),
data: credentials
})
}
2019-06-11 15:13:48 +00:00
export async function fetchUsers(filters, authHost, token, page = 1) {
2019-03-22 21:18:57 +00:00
return await request({
2019-03-23 14:09:48 +00:00
baseURL: baseName(authHost),
2019-06-11 15:13:48 +00:00
url: `/api/pleroma/admin/users?page=${page}&filters=${filters}`,
method: 'get',
2019-03-22 21:18:57 +00:00
headers: authHeaders(token)
})
}
2019-09-23 19:00:28 +00:00
export async function getPasswordResetToken(nickname, authHost, token) {
return await request({
baseURL: baseName(authHost),
url: `/api/pleroma/admin/users/${nickname}/password_reset`,
method: 'get',
headers: authHeaders(token)
})
}
2020-01-28 13:06:49 +00:00
export async function forcePasswordReset(nicknames, authHost, token) {
return await request({
baseURL: baseName(authHost),
2020-01-28 13:06:49 +00:00
url: `/api/pleroma/admin/users/force_password_reset`,
method: 'patch',
2020-01-28 13:06:49 +00:00
headers: authHeaders(token),
data: { nicknames }
})
}
2019-06-11 15:13:48 +00:00
export async function searchUsers(query, filters, authHost, token, page = 1) {
2019-03-22 21:18:57 +00:00
return await request({
2019-03-23 14:09:48 +00:00
baseURL: baseName(authHost),
2019-06-11 15:13:48 +00:00
url: `/api/pleroma/admin/users?query=${query}&page=${page}&filters=${filters}`,
method: 'get',
2019-03-22 21:18:57 +00:00
headers: authHeaders(token)
})
}
export async function tagUser(nicknames, tags, 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, tags }
2019-03-22 21:18:57 +00:00
})
}
export async function untagUser(nicknames, tags, 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, tags }
2019-03-22 21:18:57 +00:00
})
}
export async function fetchUserStatuses(id, authHost, godmode, token) {
return await request({
baseURL: baseName(authHost),
url: `/api/pleroma/admin/users/${id}/statuses?godmode=${godmode}`,
method: 'get',
headers: authHeaders(token)
})
}
export async function confirmUserEmail(nicknames, authHost, token) {
return await request({
baseURL: baseName(authHost),
url: '/api/pleroma/admin/users/confirm_email',
method: 'patch',
headers: authHeaders(token),
data: { nicknames }
})
}
export async function resendConfirmationEmail(nicknames, authHost, token) {
return await request({
baseURL: baseName(authHost),
url: '/api/pleroma/admin/users/resend_confirmation_email',
method: 'patch',
headers: authHeaders(token),
data: { nicknames }
})
}
2019-03-22 21:18:57 +00:00
const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {}