feat(xo-server/rest-api): add /groups/:id/users and /users/:id/groups collections

Fixes https://xcp-ng.org/forum/post/70500
This commit is contained in:
Julien Fontanet 2024-02-08 11:12:46 +01:00
parent bcdcfbf20b
commit e162fd835b
2 changed files with 31 additions and 0 deletions

View File

@ -8,6 +8,7 @@
> Users must be able to say: “Nice enhancement, I'm eager to test it”
- [REST API] Add `/groups` collection [Forum#70500](https://xcp-ng.org/forum/post/70500)
- [REST API] Add `/groups/:id/users` and `/users/:id/groups` collection [Forum#70500](https://xcp-ng.org/forum/post/70500)
### Bug fixes

View File

@ -326,6 +326,21 @@ export default class RestApi {
async getObjects(filter, limit) {
return handleArray(await app.getAllGroups(), filter, limit)
},
routes: {
async users(req, res) {
const { filter, limit } = req.query
await sendObjects(
handleArray(
await Promise.all(req.object.users.map(id => app.getUser(id).then(getUserPublicProperties))),
handleOptionalUserFilter(filter),
ifDef(limit, Number)
),
req,
res,
'/users'
)
},
},
}
collections.restore = {}
collections.tasks = {}
@ -336,6 +351,21 @@ export default class RestApi {
async getObjects(filter, limit) {
return handleArray(await app.getAllUsers(), filter, limit)
},
routes: {
async groups(req, res) {
const { filter, limit } = req.query
await sendObjects(
handleArray(
await Promise.all(req.object.groups.map(id => app.getGroup(id))),
handleOptionalUserFilter(filter),
ifDef(limit, Number)
),
req,
res,
'/groups'
)
},
},
}
// normalize collections