Frontend v1.0.80:
El botón "📄 Exportar PDF" ahora solo es visible para admin y asesor Los mecánicos (role === 'mechanic') pueden ver el modal de inspección pero NO pueden exportar el PDF Backend v1.0.82 (sin cambios adicionales) Resumen de permisos: ✅ Admin: Ver inspección + Exportar PDF + Ver historial + Inactivar ✅ Asesor: Ver inspección + Exportar PDF ❌ Mecánico: Solo ver inspección + Continuar incompletas
This commit is contained in:
@@ -3479,60 +3479,63 @@ function InspectionDetailModal({ inspection, user, onClose, onUpdate, onContinue
|
||||
{loadingAudit ? 'Cargando...' : 'Ver Historial de Cambios'}
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('token')
|
||||
const API_URL = import.meta.env.VITE_API_URL || ''
|
||||
const response = await fetch(`${API_URL}/api/inspections/${inspection.id}/pdf`, {
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
})
|
||||
if (response.ok) {
|
||||
const contentType = response.headers.get('content-type')
|
||||
if (contentType && contentType.includes('application/pdf')) {
|
||||
const blob = await response.blob()
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = `inspeccion_${inspection.id}_${inspection.vehicle_plate || 'sin-patente'}.pdf`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
window.URL.revokeObjectURL(url)
|
||||
} else {
|
||||
const data = await response.json()
|
||||
if (data.pdf_url) {
|
||||
const pdfRes = await fetch(data.pdf_url)
|
||||
if (pdfRes.ok) {
|
||||
const pdfBlob = await pdfRes.blob()
|
||||
const pdfUrl = window.URL.createObjectURL(pdfBlob)
|
||||
const a = document.createElement('a')
|
||||
a.href = pdfUrl
|
||||
a.download = `inspeccion_${inspection.id}_${inspection.vehicle_plate || 'sin-patente'}.pdf`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
window.URL.revokeObjectURL(pdfUrl)
|
||||
} else {
|
||||
alert('No se pudo descargar el PDF desde MinIO')
|
||||
}
|
||||
{/* Botón Exportar PDF - solo para admin y asesor */}
|
||||
{(user?.role === 'admin' || user?.role === 'asesor') && (
|
||||
<button
|
||||
onClick={async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('token')
|
||||
const API_URL = import.meta.env.VITE_API_URL || ''
|
||||
const response = await fetch(`${API_URL}/api/inspections/${inspection.id}/pdf`, {
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
})
|
||||
if (response.ok) {
|
||||
const contentType = response.headers.get('content-type')
|
||||
if (contentType && contentType.includes('application/pdf')) {
|
||||
const blob = await response.blob()
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = `inspeccion_${inspection.id}_${inspection.vehicle_plate || 'sin-patente'}.pdf`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
window.URL.revokeObjectURL(url)
|
||||
} else {
|
||||
alert('No se encontró la URL del PDF')
|
||||
const data = await response.json()
|
||||
if (data.pdf_url) {
|
||||
const pdfRes = await fetch(data.pdf_url)
|
||||
if (pdfRes.ok) {
|
||||
const pdfBlob = await pdfRes.blob()
|
||||
const pdfUrl = window.URL.createObjectURL(pdfBlob)
|
||||
const a = document.createElement('a')
|
||||
a.href = pdfUrl
|
||||
a.download = `inspeccion_${inspection.id}_${inspection.vehicle_plate || 'sin-patente'}.pdf`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
window.URL.revokeObjectURL(pdfUrl)
|
||||
} else {
|
||||
alert('No se pudo descargar el PDF desde MinIO')
|
||||
}
|
||||
} else {
|
||||
alert('No se encontró la URL del PDF')
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alert('Error al generar PDF')
|
||||
}
|
||||
} else {
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
alert('Error al generar PDF')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
alert('Error al generar PDF')
|
||||
}
|
||||
}}
|
||||
className="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition flex items-center gap-2"
|
||||
>
|
||||
<span>📄</span>
|
||||
Exportar PDF
|
||||
</button>
|
||||
}}
|
||||
className="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition flex items-center gap-2"
|
||||
>
|
||||
<span>📄</span>
|
||||
Exportar PDF
|
||||
</button>
|
||||
)}
|
||||
{user?.role === 'admin' && (
|
||||
<>
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user