Implement batch user retrieval in AdminController and update routes

- Added a new method `getUsers` in AdminController to handle batch retrieval of user information based on hashed IDs.
- Updated adminRouter to include a new route for batch user retrieval.
- Enhanced AdminService with a method to fetch user details by hashed IDs, ensuring proper access control.
- Updated localization files to include the new "username" field for user connections in both German and English.
- Modified ServicesStatusView to utilize the new batch user retrieval for displaying usernames alongside connection counts.
This commit is contained in:
Torsten Schulz (local)
2025-11-21 23:49:05 +01:00
parent 8a9acf6c4a
commit dc7001a80c
6 changed files with 81 additions and 7 deletions

View File

@@ -27,6 +27,7 @@ class AdminController {
// User administration
this.searchUsers = this.searchUsers.bind(this);
this.getUser = this.getUser.bind(this);
this.getUsers = this.getUsers.bind(this);
this.updateUser = this.updateUser.bind(this);
// Rights
@@ -74,6 +75,30 @@ class AdminController {
}
}
async getUsers(req, res) {
try {
const { userid: requester } = req.headers;
let { ids } = req.query;
if (!ids) {
return res.status(400).json({ error: 'ids query parameter is required' });
}
// Unterstütze sowohl Array-Format (ids[]=...) als auch komma-separierten String (ids=...)
let hashedIds;
if (Array.isArray(ids)) {
hashedIds = ids;
} else if (typeof ids === 'string') {
hashedIds = ids.split(',').map(id => id.trim()).filter(id => id.length > 0);
} else {
return res.status(400).json({ error: 'ids must be an array or comma-separated string' });
}
const result = await AdminService.getUsersByHashedIds(requester, hashedIds);
res.status(200).json(result);
} catch (error) {
const status = error.message === 'noaccess' ? 403 : 500;
res.status(status).json({ error: error.message });
}
}
async updateUser(req, res) {
try {
const { userid: requester } = req.headers;