Fix: Robustere Fehlerbehandlung für Falukant-Account-Check im Menü-Filtering

- Füge try-catch zu hasFalukantAccount() hinzu um DB-Fehler abzufangen
- Füge try-catch zu filterMenu() hinzu für zusätzliche Sicherheit
- Verhindert Crash wenn Falukant-User-Tabelle nicht verfügbar ist
- Fallback: return false wenn Fehler auftritt
This commit is contained in:
Torsten Schulz (local)
2025-10-20 21:04:20 +02:00
parent c81e61433c
commit 5be3855bcd

View File

@@ -307,21 +307,27 @@ class NavigationController {
async filterMenu(menu, rights, age, userId) {
const filteredMenu = {};
const hasFalukantAccount = await this.hasFalukantAccount(userId);
for (const [key, value] of Object.entries(menu)) {
if (value.visible.includes("all")
|| value.visible.some(v => rights.includes(v)) || (value.visible.includes("anyadmin") && rights.length > 0)
|| (value.visible.includes("over14") && age >= 14)
|| (value.visible.includes("over12") && age >= 12)
|| (value.visible.includes("over18") && age >= 18)
|| (value.visible.includes('nofalukantaccount') && !hasFalukantAccount)
|| (value.visible.includes('hasfalukantaccount') && hasFalukantAccount)) {
const { visible, ...itemWithoutVisible } = value;
filteredMenu[key] = { ...itemWithoutVisible };
if (value.children) {
filteredMenu[key].children = await this.filterMenu(value.children, rights, age, userId);
try {
const hasFalukantAccount = await this.hasFalukantAccount(userId);
for (const [key, value] of Object.entries(menu)) {
if (value.visible.includes("all")
|| value.visible.some(v => rights.includes(v)) || (value.visible.includes("anyadmin") && rights.length > 0)
|| (value.visible.includes("over14") && age >= 14)
|| (value.visible.includes("over12") && age >= 12)
|| (value.visible.includes("over18") && age >= 18)
|| (value.visible.includes('nofalukantaccount') && !hasFalukantAccount)
|| (value.visible.includes('hasfalukantaccount') && hasFalukantAccount)) {
const { visible, ...itemWithoutVisible } = value;
filteredMenu[key] = { ...itemWithoutVisible };
if (value.children) {
filteredMenu[key].children = await this.filterMenu(value.children, rights, age, userId);
}
}
}
} catch (error) {
console.error('Error filtering menu:', error);
// Return empty menu if filtering fails
return {};
}
return filteredMenu;
}
@@ -363,8 +369,13 @@ class NavigationController {
}
async hasFalukantAccount(userId) {
const falukantUser = await FalukantUser.findOne({ where: { userId: userId } });
return falukantUser !== null;
try {
const falukantUser = await FalukantUser.findOne({ where: { userId: userId } });
return falukantUser !== null;
} catch (error) {
console.error('Error checking falukant account:', error);
return false; // Fallback: assume no falukant account if error occurs
}
}
}