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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user