forked from RiseUP/riseup_squad_03
modified: src/App.jsx
modified: src/components/AppShell.jsx new file: src/config/permissions.js new file: src/hooks/useAuth.js new file: src/pages/UsersPage.jsx new file: src/repositories/userRepository.js
This commit is contained in:
169
src/config/permissions.js
Normal file
169
src/config/permissions.js
Normal file
@@ -0,0 +1,169 @@
|
||||
// Roles disponíveis no sistema
|
||||
export const ROLES = {
|
||||
ADMIN: 'admin',
|
||||
GESTOR: 'gestor',
|
||||
MEDICO: 'medico',
|
||||
SECRETARIA: 'secretaria',
|
||||
PACIENTE: 'paciente',
|
||||
}
|
||||
|
||||
// Rotas permitidas por role ('*' = todas)
|
||||
const ROLE_ROUTES = {
|
||||
admin: '*',
|
||||
gestor: [
|
||||
'/inicio', '/home', '/dashboard',
|
||||
'/agenda',
|
||||
'/pacientes',
|
||||
'/prontuario',
|
||||
'/laudos',
|
||||
'/relatorios',
|
||||
'/comunicacao', '/mensagens', '/camunicacao',
|
||||
'/profissionais',
|
||||
'/configuracoes', '/config',
|
||||
'/consultas',
|
||||
'/usuarios',
|
||||
'/perfil',
|
||||
],
|
||||
medico: [
|
||||
'/inicio', '/home', '/dashboard',
|
||||
'/agenda',
|
||||
'/prontuario',
|
||||
'/laudos',
|
||||
'/comunicacao', '/mensagens', '/camunicacao',
|
||||
'/relatorios',
|
||||
'/perfil',
|
||||
],
|
||||
secretaria: [
|
||||
'/inicio', '/home', '/dashboard',
|
||||
'/agenda',
|
||||
'/pacientes',
|
||||
'/comunicacao', '/mensagens', '/camunicacao',
|
||||
'/perfil',
|
||||
],
|
||||
paciente: [
|
||||
'/inicio', '/home', '/dashboard',
|
||||
'/perfil',
|
||||
],
|
||||
}
|
||||
|
||||
// Capacidades especiais por role
|
||||
export const ROLE_CAPABILITIES = {
|
||||
admin: {
|
||||
manageUsers: true,
|
||||
hardDeletePatients: true,
|
||||
accessSettings: true,
|
||||
ownAppointmentsOnly: false,
|
||||
canEditPatients: true,
|
||||
canViewReports: true,
|
||||
canViewMedicalRecords: true,
|
||||
},
|
||||
gestor: {
|
||||
manageUsers: true,
|
||||
hardDeletePatients: true,
|
||||
accessSettings: true,
|
||||
ownAppointmentsOnly: false,
|
||||
canEditPatients: true,
|
||||
canViewReports: true,
|
||||
canViewMedicalRecords: true,
|
||||
},
|
||||
medico: {
|
||||
manageUsers: false,
|
||||
hardDeletePatients: false,
|
||||
accessSettings: false,
|
||||
ownAppointmentsOnly: true,
|
||||
canEditPatients: false,
|
||||
canViewReports: true,
|
||||
canViewMedicalRecords: true,
|
||||
},
|
||||
secretaria: {
|
||||
manageUsers: false,
|
||||
hardDeletePatients: false,
|
||||
accessSettings: false,
|
||||
ownAppointmentsOnly: false,
|
||||
canEditPatients: true,
|
||||
canViewReports: false,
|
||||
canViewMedicalRecords: false,
|
||||
},
|
||||
paciente: {
|
||||
manageUsers: false,
|
||||
hardDeletePatients: false,
|
||||
accessSettings: false,
|
||||
ownAppointmentsOnly: false,
|
||||
canEditPatients: false,
|
||||
canViewReports: false,
|
||||
canViewMedicalRecords: false,
|
||||
},
|
||||
}
|
||||
|
||||
// Itens do menu por role (para o AppShell)
|
||||
export const ROLE_NAV_ITEMS = {
|
||||
admin: [
|
||||
{ path: '/inicio', label: 'Painel' },
|
||||
{ path: '/agenda', label: 'Agenda' },
|
||||
{ path: '/pacientes', label: 'Pacientes' },
|
||||
{ path: '/prontuario', label: 'Prontuário' },
|
||||
{ path: '/laudos', label: 'Laudos' },
|
||||
{ path: '/relatorios', label: 'Relatórios' },
|
||||
{ path: '/comunicacao', label: 'Comunicação' },
|
||||
{ path: '/profissionais', label: 'Profissionais' },
|
||||
{ path: '/usuarios', label: 'Usuários' },
|
||||
{ path: '/configuracoes', label: 'Configurações' },
|
||||
],
|
||||
gestor: [
|
||||
{ path: '/inicio', label: 'Painel' },
|
||||
{ path: '/agenda', label: 'Agenda' },
|
||||
{ path: '/pacientes', label: 'Pacientes' },
|
||||
{ path: '/prontuario', label: 'Prontuário' },
|
||||
{ path: '/laudos', label: 'Laudos' },
|
||||
{ path: '/relatorios', label: 'Relatórios' },
|
||||
{ path: '/comunicacao', label: 'Comunicação' },
|
||||
{ path: '/profissionais', label: 'Profissionais' },
|
||||
{ path: '/usuarios', label: 'Usuários' },
|
||||
{ path: '/configuracoes', label: 'Configurações' },
|
||||
],
|
||||
medico: [
|
||||
{ path: '/inicio', label: 'Painel' },
|
||||
{ path: '/agenda', label: 'Agenda' },
|
||||
{ path: '/prontuario', label: 'Prontuário' },
|
||||
{ path: '/laudos', label: 'Laudos' },
|
||||
{ path: '/comunicacao', label: 'Comunicação' },
|
||||
{ path: '/relatorios', label: 'Relatórios' },
|
||||
],
|
||||
secretaria: [
|
||||
{ path: '/inicio', label: 'Painel' },
|
||||
{ path: '/agenda', label: 'Agenda' },
|
||||
{ path: '/pacientes', label: 'Pacientes' },
|
||||
{ path: '/comunicacao', label: 'Comunicação' },
|
||||
],
|
||||
paciente: [
|
||||
{ path: '/inicio', label: 'Painel' },
|
||||
],
|
||||
}
|
||||
|
||||
// Verifica se um role pode acessar uma rota
|
||||
export function canAccess(role, pathname) {
|
||||
if (!role) return false
|
||||
const allowed = ROLE_ROUTES[role]
|
||||
if (allowed === '*') return true
|
||||
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
|
||||
}
|
||||
|
||||
// Rótulos amigáveis para cada role
|
||||
export const ROLE_LABELS = {
|
||||
admin: 'Administrador',
|
||||
gestor: 'Gestão / Coordenação',
|
||||
medico: 'Médico',
|
||||
secretaria: 'Secretária',
|
||||
paciente: 'Paciente',
|
||||
}
|
||||
|
||||
// Roles que um gestor pode criar
|
||||
export const GESTOR_CREATABLE_ROLES = ['medico', 'secretaria', 'paciente']
|
||||
|
||||
// Roles que um admin pode criar
|
||||
export const ADMIN_CREATABLE_ROLES = ['admin', 'gestor', 'medico', 'secretaria', 'paciente']
|
||||
Reference in New Issue
Block a user