Gerencia rango operativo (crear citas), permisos por prefijo para rutas de detalle, matriz alineada (inventario para recepcion)

This commit is contained in:
2026-09-11 09:48:37 +00:00
parent 212f51cf9e
commit 0b45abc197
3 changed files with 20 additions and 6 deletions

View File

@@ -14,7 +14,7 @@ const ROLE_RANK: Record<FrontendRole, number> = {
cosmetologia: 50,
psicologa: 50,
farmacia: 50,
gerencia: 10,
gerencia: 50,
marketing: 10,
lectura: 10,
};
@@ -155,13 +155,25 @@ export const AuthProvider: FC<{ children: ReactNode }> = ({ children }) => {
const canSee = (href: string): boolean => {
if (!user) return false;
// Resolución de permiso: primero href exacto (con query), luego por
// prefijo recortando el último segmento (/pacientes/PAT-123 -> /pacientes).
// '/' no matchea subrutas: solo aterriza por canSee('/'). Rutas que no
// matchean nada = visibles para todos.
const segments = href.split('?')[0].split('/').filter(Boolean);
const candidates = [href, ...segments.map((_, i) => '/' + segments.slice(0, segments.length - i).join('/'))].filter((c) => c !== '/' || href === '/');
// Permisos personalizados: lista no vacía manda sobre la matriz por rol
if (user.allowed_menus && user.allowed_menus.length > 0) {
return user.allowed_menus.includes(href);
for (const cand of candidates) {
if (user.allowed_menus.includes(cand)) return true;
}
return false;
}
const allowed = (menuRoles || MENU_ROLES)[href];
if (!allowed) return true;
return allowed.includes(user.role);
const matrix = menuRoles || MENU_ROLES;
for (const cand of candidates) {
const allowed = matrix[cand];
if (allowed) return allowed.includes(user.role);
}
return true;
};
return (