fix: solución de bloqueos y estandarización de permisos
This commit is contained in:
@@ -326,6 +326,35 @@ class InvoiceService:
|
||||
if not filters.get("invoice_type") and ot_exp_val == "exp":
|
||||
query = query.filter(models.InvoiceHeader.invoice_type != "REPAR")
|
||||
|
||||
# Filtro por permisos granulares (allowed_types)
|
||||
if "allowed_types" in filters:
|
||||
from sqlalchemy import or_, and_
|
||||
allowed = filters["allowed_types"]
|
||||
if allowed is None:
|
||||
# Acceso global (admin o view_all) - no filtramos por tipos
|
||||
pass
|
||||
elif not allowed:
|
||||
# Seguridad: Si el usuario NO tiene permisos para ningún tipo específico
|
||||
query = query.filter(models.InvoiceHeader.id == -1)
|
||||
else:
|
||||
from sqlalchemy import func
|
||||
conditions = []
|
||||
for op, inv in allowed:
|
||||
# Aseguramos comparación insensible a mayúsculas para mayor robustez con la DB
|
||||
op_str = str(op).lower()
|
||||
inv_str = str(inv).lower()
|
||||
conditions.append(
|
||||
and_(
|
||||
func.lower(models.InvoiceHeader.operation_type) == op_str,
|
||||
func.lower(models.InvoiceHeader.invoice_type) == inv_str
|
||||
)
|
||||
)
|
||||
if conditions:
|
||||
query = query.filter(or_(*conditions))
|
||||
else:
|
||||
# Seguridad: Si tiene allowed_types pero no generamos condiciones, no debe ver nada
|
||||
query = query.filter(models.InvoiceHeader.id == -1)
|
||||
|
||||
# Apply sorting
|
||||
if sort_by:
|
||||
# Simple column mapping
|
||||
|
||||
Reference in New Issue
Block a user