feat: restringe soloAdmin (Bucefalo CRM) a agentes, default WhatsApp+fallbackEmail y archivado reversible
This commit is contained in:
@@ -19,7 +19,7 @@ from app.models.common import ErrorResponse, OkResponse
|
||||
router = APIRouter(prefix="/paquetes", tags=["Paquetes"])
|
||||
|
||||
|
||||
async def _build_paquetes_responses(conn, paquete_rows: list[dict]) -> list[dict]:
|
||||
async def _build_paquetes_responses(conn, paquete_rows: list[dict], excluir_solo_admin: bool = False) -> list[dict]:
|
||||
"""Build PaqueteResponse dicts for several paquetes with 2 queries in total
|
||||
(instead of 1 + N fases per paquete)."""
|
||||
if not paquete_rows:
|
||||
@@ -43,7 +43,7 @@ async def _build_paquetes_responses(conn, paquete_rows: list[dict]) -> list[dict
|
||||
' sc."precioBase" AS "sc_precioBase", sc."tiempoEntrega" AS "sc_tiempoEntrega",'
|
||||
' sc."entregablesDefault" AS "sc_entregablesDefault",'
|
||||
' sc."categoriaId" AS "sc_categoriaId", sc.variante AS "sc_variante",'
|
||||
' sc.activo AS "sc_activo", sc.orden AS "sc_orden",'
|
||||
' sc.activo AS "sc_activo", sc."soloAdmin" AS "sc_soloAdmin", sc.orden AS "sc_orden",'
|
||||
' sc."createdAt" AS "sc_createdAt", sc."updatedAt" AS "sc_updatedAt",'
|
||||
' cat.id AS "cat_id", cat.nombre AS "cat_nombre", cat.descripcion AS "cat_descripcion",'
|
||||
' cat.color AS "cat_color", cat.activo AS "cat_activo", cat.orden AS "cat_orden",'
|
||||
@@ -57,6 +57,8 @@ async def _build_paquetes_responses(conn, paquete_rows: list[dict]) -> list[dict
|
||||
|
||||
servicios_por_fase: dict[str, list[dict]] = {}
|
||||
for s in servicios_rows:
|
||||
if excluir_solo_admin and s.get("sc_soloAdmin"):
|
||||
continue
|
||||
cat = None
|
||||
if s["cat_id"]:
|
||||
cat = {
|
||||
@@ -87,6 +89,7 @@ async def _build_paquetes_responses(conn, paquete_rows: list[dict]) -> list[dict
|
||||
"categoriaId": s["sc_categoriaId"],
|
||||
"variante": s["sc_variante"],
|
||||
"activo": s["sc_activo"],
|
||||
"soloAdmin": bool(s.get("sc_soloAdmin", False)),
|
||||
"orden": s["sc_orden"],
|
||||
"createdAt": s["sc_createdAt"],
|
||||
"updatedAt": s["sc_updatedAt"],
|
||||
@@ -120,9 +123,9 @@ async def _build_paquetes_responses(conn, paquete_rows: list[dict]) -> list[dict
|
||||
]
|
||||
|
||||
|
||||
async def _build_paquete_response(conn, paquete_row: dict) -> dict:
|
||||
async def _build_paquete_response(conn, paquete_row: dict, excluir_solo_admin: bool = False) -> dict:
|
||||
"""Build a PaqueteResponse dict with nested fases and servicios."""
|
||||
results = await _build_paquetes_responses(conn, [paquete_row])
|
||||
results = await _build_paquetes_responses(conn, [paquete_row], excluir_solo_admin=excluir_solo_admin)
|
||||
return results[0]
|
||||
|
||||
|
||||
@@ -135,7 +138,8 @@ async def list_paquetes(
|
||||
'SELECT id, nombre, descripcion, activo, "createdAt", "updatedAt"'
|
||||
' FROM "Paquete" WHERE activo = true ORDER BY "createdAt" ASC'
|
||||
)
|
||||
return await _build_paquetes_responses(conn, [dict(row) for row in rows])
|
||||
excluir = _auth.get("auth_type") == "agent"
|
||||
return await _build_paquetes_responses(conn, [dict(row) for row in rows], excluir_solo_admin=excluir)
|
||||
|
||||
|
||||
@router.post(
|
||||
@@ -192,7 +196,8 @@ async def get_paquete(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Paquete no encontrado",
|
||||
)
|
||||
return await _build_paquete_response(conn, dict(row))
|
||||
excluir = _auth.get("auth_type") == "agent"
|
||||
return await _build_paquete_response(conn, dict(row), excluir_solo_admin=excluir)
|
||||
|
||||
|
||||
@router.put(
|
||||
|
||||
Reference in New Issue
Block a user