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

@@ -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",

View File

@@ -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",

View File

@@ -58,7 +58,7 @@
<div v-else class="connections-list">
<div v-for="(userConn, index) in connections" :key="index" class="connection-group">
<div class="connection-header">
<strong>{{ $t('admin.servicesStatus.daemon.connections.userId') }}:</strong> {{ userConn.userId }}
<strong>{{ $t('admin.servicesStatus.daemon.connections.username') }}:</strong> {{ userConn.username }}
<span class="connection-count">({{ userConn.connectionCount }} {{ $t('admin.servicesStatus.daemon.connections.connections') }})</span>
</div>
<div v-for="(conn, connIndex) in userConn.connections" :key="connIndex" class="connection-details">
@@ -97,6 +97,7 @@
<script>
import { mapState, mapGetters } from 'vuex';
import SimpleTabs from '@/components/SimpleTabs.vue';
import apiClient from '@/utils/axios.js';
export default {
name: 'ServicesStatusView',
@@ -214,18 +215,39 @@ export default {
this.error = this.$t('admin.servicesStatus.daemon.connections.sendError');
}
},
handleDaemonMessage(event) {
async handleDaemonMessage(event) {
try {
const data = JSON.parse(event.data);
if (data.event === 'getConnectionsResponse') {
// Die Daemon-Antwort hat die Struktur: {event, total, unauthenticated, users: {userId: count}}
if (data.users && typeof data.users === 'object') {
// Transformiere das users-Objekt in ein Array für das Template
this.connections = Object.entries(data.users).map(([userId, connectionCount]) => ({
userId: userId,
connectionCount: connectionCount,
connections: [] // Detaillierte Verbindungsinfos sind in der aktuellen Antwort nicht enthalten
}));
const userIds = Object.keys(data.users);
// Lade User-Informationen für alle User-IDs
let userMap = {};
if (userIds.length > 0) {
try {
const response = await apiClient.get('/api/admin/users/batch', {
params: { ids: userIds }
});
userMap = response.data;
} catch (err) {
console.error('Fehler beim Abrufen der User-Informationen:', err);
// Fallback: Verwende User-IDs, wenn Abruf fehlschlägt
}
}
// Transformiere das users-Objekt in ein Array für das Template
this.connections = Object.entries(data.users).map(([userId, connectionCount]) => {
const userInfo = userMap[userId];
return {
userId: userId,
username: userInfo ? userInfo.username : userId.substring(0, 8) + '...', // Fallback: Zeige ersten Teil der ID
connectionCount: connectionCount,
connections: [] // Detaillierte Verbindungsinfos sind in der aktuellen Antwort nicht enthalten
};
});
this.error = null;
} else {
this.connections = [];