backend crear endpoitns para permisos de checklist por mecanico, 1.0.30
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Syntria - Sistema Inteligente de Inspecciones</title>
|
||||
<meta name="description" content="Syntria: Sistema avanzado de inspecciones vehiculares con inteligencia artificial" />
|
||||
<title>AYUTEC - Sistema Inteligente de Inspecciones</title>
|
||||
<meta name="description" content="AYUTEC: Sistema avanzado de inspecciones vehiculares con inteligencia artificial" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@@ -106,7 +106,7 @@ function LoginPage({ setUser }) {
|
||||
<div className="w-24 h-24 bg-white rounded-2xl flex items-center justify-center shadow-lg text-gray-400">Sin logo</div>
|
||||
)}
|
||||
</div>
|
||||
<h1 className="text-4xl font-bold text-white mb-2">Syntria</h1>
|
||||
<h1 className="text-4xl font-bold text-white mb-2">AYUTEC</h1>
|
||||
<p className="text-indigo-100 text-sm">Sistema Inteligente de Inspecciones</p>
|
||||
</div>
|
||||
|
||||
@@ -296,7 +296,7 @@ function DashboardPage({ user, setUser }) {
|
||||
<div className="w-12 h-12 bg-white rounded-xl flex items-center justify-center shadow-lg text-gray-400">Sin logo</div>
|
||||
)}
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-white">Syntria</h1>
|
||||
<h1 className="text-2xl font-bold text-white">AYUTEC</h1>
|
||||
<p className="text-xs text-indigo-200">Sistema Inteligente de Inspecciones</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -887,7 +887,7 @@ function APITokensTab({ user }) {
|
||||
Incluye el token en el header <code className="bg-blue-100 px-1 py-0.5 rounded">Authorization</code> de tus requests:
|
||||
</p>
|
||||
<code className="block bg-blue-100 p-2 rounded text-xs mt-2">
|
||||
Authorization: Bearer syntria_tu_token_aqui
|
||||
Authorization: Bearer AYUTEC_tu_token_aqui
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1346,13 +1346,39 @@ function ChecklistsTab({ checklists, user, onChecklistCreated, onStartInspection
|
||||
const [showQuestionsModal, setShowQuestionsModal] = useState(false)
|
||||
const [selectedChecklist, setSelectedChecklist] = useState(null)
|
||||
const [creating, setCreating] = useState(false)
|
||||
const [mechanics, setMechanics] = useState([])
|
||||
const [formData, setFormData] = useState({
|
||||
name: '',
|
||||
description: '',
|
||||
ai_mode: 'off',
|
||||
scoring_enabled: true
|
||||
scoring_enabled: true,
|
||||
mechanic_ids: []
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
loadMechanics()
|
||||
}, [])
|
||||
|
||||
const loadMechanics = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('token')
|
||||
const API_URL = import.meta.env.VITE_API_URL || ''
|
||||
const response = await fetch(`${API_URL}/api/users`, {
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
})
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
// Filtrar solo mecánicos activos
|
||||
const mechanicUsers = data.filter(u =>
|
||||
(u.role === 'mechanic' || u.role === 'mecanico') && u.is_active
|
||||
)
|
||||
setMechanics(mechanicUsers)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading mechanics:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleCreate = async (e) => {
|
||||
e.preventDefault()
|
||||
setCreating(true)
|
||||
@@ -1372,7 +1398,13 @@ function ChecklistsTab({ checklists, user, onChecklistCreated, onStartInspection
|
||||
|
||||
if (response.ok) {
|
||||
setShowCreateModal(false)
|
||||
setFormData({ name: '', description: '', ai_mode: 'off', scoring_enabled: true })
|
||||
setFormData({
|
||||
name: '',
|
||||
description: '',
|
||||
ai_mode: 'off',
|
||||
scoring_enabled: true,
|
||||
mechanic_ids: []
|
||||
})
|
||||
onChecklistCreated()
|
||||
} else {
|
||||
alert('Error al crear checklist')
|
||||
@@ -1414,7 +1446,7 @@ function ChecklistsTab({ checklists, user, onChecklistCreated, onStartInspection
|
||||
checklists.map((checklist) => (
|
||||
<div key={checklist.id} className="border border-gray-200 rounded-lg p-4 hover:shadow-md transition">
|
||||
<div className="flex justify-between items-start">
|
||||
<div>
|
||||
<div className="flex-1">
|
||||
<h3 className="text-lg font-semibold text-gray-900">{checklist.name}</h3>
|
||||
<p className="text-sm text-gray-600 mt-1">{checklist.description}</p>
|
||||
<div className="flex gap-4 mt-3 text-sm">
|
||||
@@ -1425,6 +1457,22 @@ function ChecklistsTab({ checklists, user, onChecklistCreated, onStartInspection
|
||||
Modo IA: <strong className="capitalize">{checklist.ai_mode}</strong>
|
||||
</span>
|
||||
</div>
|
||||
{/* Mostrar permisos de mecánicos */}
|
||||
{user.role === 'admin' && (
|
||||
<div className="mt-2">
|
||||
{!checklist.allowed_mechanics || checklist.allowed_mechanics.length === 0 ? (
|
||||
<span className="inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-green-100 text-green-800">
|
||||
🌍 Acceso Global - Todos los mecánicos
|
||||
</span>
|
||||
) : (
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<span className="inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-indigo-100 text-indigo-800">
|
||||
🔐 Restringido - {checklist.allowed_mechanics.length} mecánico{checklist.allowed_mechanics.length !== 1 ? 's' : ''}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
{user.role === 'admin' && (
|
||||
@@ -1558,6 +1606,65 @@ function ChecklistsTab({ checklists, user, onChecklistCreated, onStartInspection
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{/* Selector de Mecánicos Autorizados */}
|
||||
<div className="border-t pt-4">
|
||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||
🔐 Mecánicos Autorizados
|
||||
</label>
|
||||
<div className="bg-gray-50 border border-gray-300 rounded-lg p-3 max-h-48 overflow-y-auto">
|
||||
{mechanics.length === 0 ? (
|
||||
<p className="text-sm text-gray-500">No hay mecánicos disponibles</p>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center pb-2 border-b">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={formData.mechanic_ids.length === 0}
|
||||
onChange={(e) => {
|
||||
if (e.target.checked) {
|
||||
setFormData({ ...formData, mechanic_ids: [] })
|
||||
}
|
||||
}}
|
||||
className="w-4 h-4 text-green-600 border-gray-300 rounded focus:ring-green-500"
|
||||
/>
|
||||
<label className="ml-2 text-sm font-semibold text-green-700">
|
||||
🌍 Todos los mecánicos (acceso global)
|
||||
</label>
|
||||
</div>
|
||||
{mechanics.map((mechanic) => (
|
||||
<div key={mechanic.id} className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={formData.mechanic_ids.includes(mechanic.id)}
|
||||
onChange={(e) => {
|
||||
if (e.target.checked) {
|
||||
setFormData({
|
||||
...formData,
|
||||
mechanic_ids: [...formData.mechanic_ids, mechanic.id]
|
||||
})
|
||||
} else {
|
||||
setFormData({
|
||||
...formData,
|
||||
mechanic_ids: formData.mechanic_ids.filter(id => id !== mechanic.id)
|
||||
})
|
||||
}
|
||||
}}
|
||||
className="w-4 h-4 text-indigo-600 border-gray-300 rounded focus:ring-indigo-500"
|
||||
/>
|
||||
<label className="ml-2 text-sm text-gray-700">
|
||||
{mechanic.full_name || mechanic.username} ({mechanic.email})
|
||||
</label>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-gray-500">
|
||||
💡 Si no seleccionas ningún mecánico, todos podrán usar este checklist.
|
||||
Si seleccionas mecánicos específicos, solo ellos tendrán acceso.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="bg-yellow-50 border border-yellow-200 rounded-lg p-4 mt-4">
|
||||
<p className="text-sm text-yellow-800">
|
||||
ℹ️ Después de crear el checklist, podrás agregar preguntas desde la API o directamente en la base de datos.
|
||||
@@ -1569,7 +1676,13 @@ function ChecklistsTab({ checklists, user, onChecklistCreated, onStartInspection
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setShowCreateModal(false)
|
||||
setFormData({ name: '', description: '', ai_mode: 'off', scoring_enabled: true })
|
||||
setFormData({
|
||||
name: '',
|
||||
description: '',
|
||||
ai_mode: 'off',
|
||||
scoring_enabled: true,
|
||||
mechanic_ids: []
|
||||
})
|
||||
}}
|
||||
className="flex-1 px-4 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 transition"
|
||||
disabled={creating}
|
||||
|
||||
Reference in New Issue
Block a user