diff --git a/backend/controllers/adminController.js b/backend/controllers/adminController.js index b841b9b..4eeda49 100644 --- a/backend/controllers/adminController.js +++ b/backend/controllers/adminController.js @@ -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; diff --git a/backend/routers/adminRouter.js b/backend/routers/adminRouter.js index e78a86e..2807c95 100644 --- a/backend/routers/adminRouter.js +++ b/backend/routers/adminRouter.js @@ -18,6 +18,7 @@ router.delete('/chat/rooms/:id', authenticate, adminController.deleteRoom); // --- Users Admin --- router.get('/users/search', authenticate, adminController.searchUsers); router.get('/users/statistics', authenticate, adminController.getUserStatistics); +router.get('/users/batch', authenticate, adminController.getUsers); router.get('/users/:id', authenticate, adminController.getUser); router.put('/users/:id', authenticate, adminController.updateUser); diff --git a/backend/services/adminService.js b/backend/services/adminService.js index 7956c5e..f9e4b2e 100644 --- a/backend/services/adminService.js +++ b/backend/services/adminService.js @@ -441,6 +441,30 @@ class AdminService { return { id: user.hashedId, username: user.username, active: user.active, registrationDate: user.registrationDate }; } + async getUsersByHashedIds(requestingHashedUserId, targetHashedIds) { + if (!(await this.hasUserAccess(requestingHashedUserId, 'useradministration'))) { + throw new Error('noaccess'); + } + if (!Array.isArray(targetHashedIds) || targetHashedIds.length === 0) { + return []; + } + const users = await User.findAll({ + where: { hashedId: { [Op.in]: targetHashedIds } }, + attributes: ['id', 'hashedId', 'username', 'active', 'registrationDate'] + }); + // Erstelle ein Map für schnellen Zugriff + const userMap = {}; + users.forEach(user => { + userMap[user.hashedId] = { + id: user.hashedId, + username: user.username, + active: user.active, + registrationDate: user.registrationDate + }; + }); + return userMap; + } + async updateUser(requestingHashedUserId, targetHashedId, data) { if (!(await this.hasUserAccess(requestingHashedUserId, 'useradministration'))) { throw new Error('noaccess'); diff --git a/frontend/src/i18n/locales/de/admin.json b/frontend/src/i18n/locales/de/admin.json index a44a439..40aaff6 100644 --- a/frontend/src/i18n/locales/de/admin.json +++ b/frontend/src/i18n/locales/de/admin.json @@ -256,6 +256,7 @@ "title": "Aktive Verbindungen", "none": "Keine aktiven Verbindungen", "userId": "Benutzer-ID", + "username": "Benutzername", "connections": "Verbindungen", "duration": "Verbindungsdauer", "lastPong": "Zeit seit letztem Pong", diff --git a/frontend/src/i18n/locales/en/admin.json b/frontend/src/i18n/locales/en/admin.json index 3391ff0..adcc859 100644 --- a/frontend/src/i18n/locales/en/admin.json +++ b/frontend/src/i18n/locales/en/admin.json @@ -256,6 +256,7 @@ "title": "Active Connections", "none": "No active connections", "userId": "User ID", + "username": "Username", "connections": "connections", "duration": "Connection Duration", "lastPong": "Time Since Last Pong", diff --git a/frontend/src/views/admin/ServicesStatusView.vue b/frontend/src/views/admin/ServicesStatusView.vue index 1366ee4..e01ee58 100644 --- a/frontend/src/views/admin/ServicesStatusView.vue +++ b/frontend/src/views/admin/ServicesStatusView.vue @@ -58,7 +58,7 @@
- {{ $t('admin.servicesStatus.daemon.connections.userId') }}: {{ userConn.userId }} + {{ $t('admin.servicesStatus.daemon.connections.username') }}: {{ userConn.username }} ({{ userConn.connectionCount }} {{ $t('admin.servicesStatus.daemon.connections.connections') }})
@@ -97,6 +97,7 @@