feat(xo-server/rest-api): add users collection
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
> Users must be able to say: “Nice enhancement, I'm eager to test it”
|
> Users must be able to say: “Nice enhancement, I'm eager to test it”
|
||||||
|
|
||||||
|
- [REST API] Add `users` collection
|
||||||
|
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
|
|
||||||
> Users must be able to say: “I had this issue, happy to know it's fixed”
|
> Users must be able to say: “I had this issue, happy to know it's fixed”
|
||||||
@@ -27,4 +29,6 @@
|
|||||||
|
|
||||||
<!--packages-start-->
|
<!--packages-start-->
|
||||||
|
|
||||||
|
- xo-server minor
|
||||||
|
|
||||||
<!--packages-end-->
|
<!--packages-end-->
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import pick from 'lodash/pick.js'
|
|||||||
import * as CM from 'complex-matcher'
|
import * as CM from 'complex-matcher'
|
||||||
import { VDI_FORMAT_RAW, VDI_FORMAT_VHD } from '@xen-orchestra/xapi'
|
import { VDI_FORMAT_RAW, VDI_FORMAT_VHD } from '@xen-orchestra/xapi'
|
||||||
|
|
||||||
|
import { getUserPublicProperties } from '../utils.mjs'
|
||||||
|
|
||||||
const { join } = path.posix
|
const { join } = path.posix
|
||||||
const noop = Function.prototype
|
const noop = Function.prototype
|
||||||
|
|
||||||
@@ -176,6 +178,7 @@ export default class RestApi {
|
|||||||
collections.backups = { id: 'backups' }
|
collections.backups = { id: 'backups' }
|
||||||
collections.restore = { id: 'restore' }
|
collections.restore = { id: 'restore' }
|
||||||
collections.tasks = { id: 'tasks' }
|
collections.tasks = { id: 'tasks' }
|
||||||
|
collections.users = { id: 'users' }
|
||||||
|
|
||||||
collections.hosts.routes = {
|
collections.hosts.routes = {
|
||||||
__proto__: null,
|
__proto__: null,
|
||||||
@@ -389,6 +392,30 @@ export default class RestApi {
|
|||||||
}, true)
|
}, true)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
api
|
||||||
|
.get(
|
||||||
|
'/users',
|
||||||
|
wrap(async (req, res) => {
|
||||||
|
let users = await app.getAllUsers()
|
||||||
|
|
||||||
|
const { filter, limit } = req.query
|
||||||
|
if (filter !== undefined) {
|
||||||
|
users = users.filter(CM.parse(filter).createPredicate())
|
||||||
|
}
|
||||||
|
if (limit < users.length) {
|
||||||
|
users.length = limit
|
||||||
|
}
|
||||||
|
|
||||||
|
sendObjects(users.map(getUserPublicProperties), req, res)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.get(
|
||||||
|
'/users/:id',
|
||||||
|
wrap(async (req, res) => {
|
||||||
|
res.json(getUserPublicProperties(await app.getUser(req.params.id)))
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
api.get(
|
api.get(
|
||||||
'/:collection',
|
'/:collection',
|
||||||
wrap(async (req, res) => {
|
wrap(async (req, res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user