feat(auth): integrate normalizePermissionKeys for consistent permission handling
Build and Push Auth Portal Docker Image / build-and-push (push) Successful in 1m54s
Build and Push Auth Portal Docker Image / create-release (push) Skipped

- Updated auth, admin, and auth-guards routes to utilize normalizePermissionKeys for permissions.
- Enhanced permission mapping to ensure legacy keys are correctly transformed to current catalog keys.
- Improved overall permission validation and user access management across the application.
This commit is contained in:
Denozordec
2026-07-19 00:19:18 +07:00
parent cfbe1fceda
commit 21d6603b57
4 changed files with 42 additions and 11 deletions
+26
View File
@@ -244,6 +244,32 @@ export function allPermissionKeys(): string[] {
return keys
}
/** Old bgp section ids → current catalog (peers/apply/settings renamed). */
const LEGACY_PERMISSION_MAP: Record<string, string> = {
'bgp:peers:read': 'bgp:network:read',
'bgp:peers:write': 'bgp:network:write',
'bgp:apply:write': 'bgp:operations:admin',
'bgp:settings:admin': 'bgp:tenant_settings:admin',
}
/**
* Map legacy keys and drop anything not in the current catalog.
* Safe for JWT issue and admin save after catalog changes.
*/
export function normalizePermissionKeys(
permissions: readonly string[],
): string[] {
const allowed = new Set(allPermissionKeys())
const out = new Set<string>()
for (const raw of permissions) {
const mapped = LEGACY_PERMISSION_MAP[raw] ?? raw
if (allowed.has(mapped)) {
out.add(mapped)
}
}
return [...out].sort()
}
export const permissionKeySchema = z
.string()
.regex(/^[a-z]+:[a-z0-9_]+:(read|write|admin)$/)