feat: restringe soloAdmin (Bucefalo CRM) a agentes, default WhatsApp+fallbackEmail y archivado reversible

This commit is contained in:
urieljareth
2026-11-25 08:54:28 -06:00
parent 0d4f19f35d
commit 670265a390
31 changed files with 672 additions and 78 deletions
+23 -3
View File
@@ -5,7 +5,7 @@ import json
from fastapi import APIRouter, Depends, HTTPException, Query, status
from asyncpg import Connection
from app.auth import require_scope, require_staff_human
from app.auth import registrar_auditoria, require_scope, require_staff_human
from app.dependencies import get_db
from app.models.catalogo import (
ServicioCatalogoCreate,
@@ -49,6 +49,7 @@ def _row_to_response(row, categoria_row=None) -> ServicioCatalogoResponse:
variante=row["variante"],
nivel=row["nivel"],
activo=row["activo"],
soloAdmin=bool(row.get("soloAdmin", False)),
orden=row["orden"],
createdAt=row["createdAt"],
updatedAt=row["updatedAt"],
@@ -70,6 +71,8 @@ async def list_catalogo(
q: str | None = Query(None, description="Search by nombre or descripcion"),
):
where_clauses: list[str] = ['activo = true']
if auth.get("auth_type") == "agent":
where_clauses.append('"soloAdmin" = false')
params: list = []
idx = 1
@@ -135,8 +138,8 @@ async def create_catalogo(
row = await db.fetchrow(
'INSERT INTO "ServicioCatalogo" '
'(nombre, descripcion, fase, "tipoPago", "precioBase", "tiempoEntrega", '
'"entregablesDefault", "categoriaId", variante, nivel, activo, orden) '
"VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, true, $11) RETURNING *",
'"entregablesDefault", "categoriaId", variante, nivel, activo, "soloAdmin", orden) '
"VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, true, $11, $12) RETURNING *",
body.nombre,
body.descripcion,
body.fase,
@@ -147,6 +150,7 @@ async def create_catalogo(
body.categoriaId,
body.variante,
body.nivel,
body.soloAdmin,
body.orden,
)
@@ -176,6 +180,21 @@ async def get_catalogo(
if not row:
raise HTTPException(status_code=404, detail="Servicio no encontrado")
if auth.get("auth_type") == "agent" and row.get("soloAdmin"):
await registrar_auditoria(
db,
auth,
"catalogo.solo_admin_bloqueado",
"catalogo",
recurso_id=servicio_id,
exito=False,
detalle={"nombre": row["nombre"]},
)
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Este servicio esta restringido solo al administrador y no esta disponible para agentes",
)
cat_row = None
if row["categoriaId"]:
cat_row = await db.fetchrow(
@@ -222,6 +241,7 @@ async def update_catalogo(
"variante": "variante",
"nivel": "nivel",
"activo": "activo",
"soloAdmin": '"soloAdmin"',
"orden": "orden",
}