feat: marca Uriel Jareth Consulting, API segura para agentes, aprobacion humana y webhooks HMAC

This commit is contained in:
urieljareth
2026-11-25 00:55:18 -06:00
parent 75180b0fe4
commit 0d4f19f35d
111 changed files with 7167 additions and 1272 deletions
+20 -14
View File
@@ -15,7 +15,7 @@ from asyncpg import Connection
from app.dependencies import get_db
from app.models.export_ import ExportDraft
from app.models.common import ErrorResponse
from app.auth import require_auth
from app.auth import es_agente_solo_aceptadas, require_scope
from app.services.calculators import bucefalo_precio, calcular_vigencia, sanitize_filename
from app.services.pdf_generator import generate_cotizacion_pdf
from app.services.excel_generator import generate_cotizacion_excel
@@ -86,13 +86,12 @@ def _build_pdf_data_from_draft(draft: ExportDraft, branding: dict[str, str]) ->
"planBucefaloNivel": draft.planBucefaloNivel,
"planBucefaloPrecio": bucefalo_precio(draft.planBucefaloNivel) if draft.planBucefaloNivel else 0,
"incluirBonos": draft.incluirBonos,
"colorPrimario": branding.get("color_primario", "#2563eb"),
"colorSecundario": branding.get("color_secundario", "#1e293b"),
"colorPrimario": branding.get("color_primario") or "#0400C4",
"colorSecundario": branding.get("color_secundario") or "#0F172A",
"logoBase64": logo_b64,
"logoMime": logo_mime,
"configBancaria": branding,
"razonSocial": branding.get("razon_social", "Cotizador E3"),
"domicilioFiscal": branding.get("domicilio_fiscal"),
"razonSocial": branding.get("razon_social") or "Uriel Jareth Consulting",
}
@@ -188,13 +187,12 @@ async def _build_pdf_data_from_db(db: Connection, cotizacion_id: str) -> dict[st
"planBucefaloNivel": plan_nivel,
"planBucefaloPrecio": float(plan["precio"]) if plan else 0,
"incluirBonos": cot["incluirBonos"],
"colorPrimario": branding.get("color_primario", "#2563eb"),
"colorSecundario": branding.get("color_secundario", "#1e293b"),
"colorPrimario": branding.get("color_primario") or "#0400C4",
"colorSecundario": branding.get("color_secundario") or "#0F172A",
"logoBase64": logo_b64,
"logoMime": logo_mime,
"configBancaria": branding,
"razonSocial": branding.get("razon_social", "Cotizador E3"),
"domicilioFiscal": branding.get("domicilio_fiscal"),
"razonSocial": branding.get("razon_social") or "Uriel Jareth Consulting",
}
@@ -203,7 +201,7 @@ async def _build_pdf_data_from_db(db: Connection, cotizacion_id: str) -> dict[st
@router.post("/pdf")
async def export_pdf_draft(
body: ExportDraft,
_auth: dict = Depends(require_auth),
_auth: dict = Depends(require_scope("cotizaciones:leer", "cotizaciones:borrador")),
db: Connection = Depends(get_db),
):
branding = await _load_branding(db)
@@ -223,9 +221,13 @@ async def export_pdf_draft(
@router.get("/pdf/{cotizacion_id}")
async def export_pdf_saved(
cotizacion_id: str,
_auth: dict = Depends(require_auth),
_auth: dict = Depends(require_scope("cotizaciones:leer", "cotizaciones:enviar", "cotizaciones:leer_aceptadas")),
db: Connection = Depends(get_db),
):
if es_agente_solo_aceptadas(_auth):
row_est = await db.fetchrow('SELECT estado FROM "Cotizacion" WHERE id = $1', cotizacion_id)
if row_est and row_est["estado"] != "aceptada":
raise HTTPException(status_code=403, detail="Tu clave solo permite exportar cotizaciones aceptadas")
pdf_data = await _build_pdf_data_from_db(db, cotizacion_id)
if not pdf_data:
raise HTTPException(status_code=404, detail="Cotización no encontrada")
@@ -247,7 +249,7 @@ async def export_pdf_saved(
@router.post("/excel")
async def export_excel_draft(
body: ExportDraft,
_auth: dict = Depends(require_auth),
_auth: dict = Depends(require_scope("cotizaciones:leer", "cotizaciones:borrador")),
db: Connection = Depends(get_db),
):
branding = await _load_branding(db)
@@ -267,9 +269,13 @@ async def export_excel_draft(
@router.get("/excel/{cotizacion_id}")
async def export_excel_saved(
cotizacion_id: str,
_auth: dict = Depends(require_auth),
_auth: dict = Depends(require_scope("cotizaciones:leer", "cotizaciones:enviar", "cotizaciones:leer_aceptadas")),
db: Connection = Depends(get_db),
):
if es_agente_solo_aceptadas(_auth):
row_est = await db.fetchrow('SELECT estado FROM "Cotizacion" WHERE id = $1', cotizacion_id)
if row_est and row_est["estado"] != "aceptada":
raise HTTPException(status_code=403, detail="Tu clave solo permite exportar cotizaciones aceptadas")
excel_data = await _build_pdf_data_from_db(db, cotizacion_id)
if not excel_data:
raise HTTPException(status_code=404, detail="Cotización no encontrada")
@@ -290,7 +296,7 @@ async def export_excel_saved(
@router.get("/catalogo", response_class=PlainTextResponse)
async def export_catalogo_csv(
_auth: dict = Depends(require_auth),
_auth: dict = Depends(require_scope("catalogo:leer")),
db: Connection = Depends(get_db),
):
rows = await db.fetch(