modified: src/App.jsx
modified: src/components/AppShell.jsx modified: src/config/api.js modified: src/config/permissions.js modified: src/data/mockData.js modified: src/hooks/useAgenda.js modified: src/hooks/useAuth.js modified: src/mappers/appointmentMapper.js modified: src/pages/AgendaPage.jsx modified: src/pages/AuthPages.jsx modified: src/pages/HomePage.jsx modified: src/pages/MedicalRecordsPage.jsx modified: src/pages/MessagesPage.jsx modified: src/pages/NotFoundPage.jsx modified: src/pages/PatientsPage.jsx modified: src/pages/ReportsPage.jsx modified: src/pages/TeamPage.jsx modified: src/pages/UsersPage.jsx modified: src/pages/VisitsPage.jsx modified: src/repositories/authRepository.js new file: src/repositories/availabilityRepository.js modified: src/repositories/communicationRepository.js modified: src/repositories/patientRepository.js modified: src/repositories/professionalRepository.js modified: src/repositories/profileRepository.js modified: src/repositories/reportRepository.js modified: src/repositories/repositoryUtils.js modified: src/repositories/settingsRepository.js modified: src/repositories/userRepository.js modified: src/repositories/visitRepository.js
This commit is contained in:
@@ -7,6 +7,28 @@ export const ROLES = {
|
||||
PACIENTE: 'paciente',
|
||||
}
|
||||
|
||||
const ROLE_ALIASES = {
|
||||
admin: ROLES.ADMIN,
|
||||
administrador: ROLES.ADMIN,
|
||||
administrator: ROLES.ADMIN,
|
||||
gestor: ROLES.GESTOR,
|
||||
gestao: ROLES.GESTOR,
|
||||
gestao_coordenacao: ROLES.GESTOR,
|
||||
coordenacao: ROLES.GESTOR,
|
||||
coordenador: ROLES.GESTOR,
|
||||
manager: ROLES.GESTOR,
|
||||
medico: ROLES.MEDICO,
|
||||
medica: ROLES.MEDICO,
|
||||
doctor: ROLES.MEDICO,
|
||||
physician: ROLES.MEDICO,
|
||||
secretaria: ROLES.SECRETARIA,
|
||||
secretario: ROLES.SECRETARIA,
|
||||
secretary: ROLES.SECRETARIA,
|
||||
receptionist: ROLES.SECRETARIA,
|
||||
paciente: ROLES.PACIENTE,
|
||||
patient: ROLES.PACIENTE,
|
||||
}
|
||||
|
||||
// Rotas permitidas por role ('*' = todas)
|
||||
const ROLE_ROUTES = {
|
||||
admin: '*',
|
||||
@@ -142,15 +164,33 @@ export const ROLE_NAV_ITEMS = {
|
||||
|
||||
// Verifica se um role pode acessar uma rota
|
||||
export function canAccess(role, pathname) {
|
||||
if (!role) return false
|
||||
const allowed = ROLE_ROUTES[role]
|
||||
const normalizedRole = normalizeRole(role)
|
||||
if (!normalizedRole) return false
|
||||
const allowed = ROLE_ROUTES[normalizedRole]
|
||||
if (allowed === '*') return true
|
||||
if (!Array.isArray(allowed)) return false
|
||||
return allowed.some((route) => pathname === route || pathname.startsWith(route + '/'))
|
||||
}
|
||||
|
||||
// Verifica se um role tem uma capacidade específica
|
||||
export function hasCapability(role, capability) {
|
||||
return ROLE_CAPABILITIES[role]?.[capability] ?? false
|
||||
const normalizedRole = normalizeRole(role)
|
||||
return ROLE_CAPABILITIES[normalizedRole]?.[capability] ?? false
|
||||
}
|
||||
|
||||
export function normalizeRole(role) {
|
||||
const normalized = normalizeRoleKey(role)
|
||||
return ROLE_ALIASES[normalized] ?? null
|
||||
}
|
||||
|
||||
function normalizeRoleKey(role) {
|
||||
return String(role ?? '')
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^a-z0-9]+/g, '_')
|
||||
.replace(/^_+|_+$/g, '')
|
||||
}
|
||||
|
||||
// Rótulos amigáveis para cada role
|
||||
|
||||
Reference in New Issue
Block a user