fix: handle legacy JSON array permissions and improve admin toggle UX

- Add migration to convert legacy JSON array permissions to decimal strings
- Add runtime fallback in stringToPermissions for legacy format
- Show all permission toggles as enabled (dimmed) when Administrator is on
This commit is contained in:
Jannis Braun
2026-03-09 23:01:27 +01:00
parent 11a69fe92a
commit 018828575c
3 changed files with 57 additions and 8 deletions
+12
View File
@@ -63,6 +63,18 @@ export function stringToPermissions(str: string | undefined | null): bigint {
try {
return BigInt(str);
} catch {
// Fallback: legacy JSON array format (e.g. '["VIEW_CHANNEL","SEND_MESSAGES"]')
try {
const parsed = JSON.parse(str);
if (Array.isArray(parsed)) {
let result = 0n;
for (const key of parsed) {
const bit = PermissionBits[key as keyof typeof PermissionBits];
if (bit !== undefined) result |= bit;
}
return result;
}
} catch { /* not JSON either */ }
return 0n;
}
}