From 1e5e35a26af47db925f77514a3bfdbccf417c0f5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 23:38:25 +0000 Subject: [PATCH] refactor(routing): address code review feedback - simplify list filter, fix docs example Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- app/api/routing_rules.py | 20 +++++++++----------- docs/UserGuide.md | 7 ++++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/api/routing_rules.py b/app/api/routing_rules.py index fa8db9cf..98162c09 100644 --- a/app/api/routing_rules.py +++ b/app/api/routing_rules.py @@ -170,18 +170,16 @@ def list_routing_rules(request: Request, db: DbSession) -> list[dict[str, Any]]: Rules are sorted by position. """ user_id = _get_user_id(request) - admin = _is_admin(request) - query = db.query(PipelineRoutingRule) - if admin: - query = query.filter((PipelineRoutingRule.owner_id == user_id) | (PipelineRoutingRule.owner_id.is_(None))) - else: - query = query.filter((PipelineRoutingRule.owner_id == user_id) | (PipelineRoutingRule.owner_id.is_(None))) - - rules = query.order_by( - PipelineRoutingRule.owner_id.is_(None).asc(), - PipelineRoutingRule.position.asc(), - ).all() + rules = ( + db.query(PipelineRoutingRule) + .filter((PipelineRoutingRule.owner_id == user_id) | (PipelineRoutingRule.owner_id.is_(None))) + .order_by( + PipelineRoutingRule.owner_id.is_(None).asc(), + PipelineRoutingRule.position.asc(), + ) + .all() + ) return [_serialize_rule(r) for r in rules] diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 20f256c5..957d005d 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -662,13 +662,18 @@ based on their properties — no manual pipeline selection required. | `regex` | Full Python regex match (case-insensitive) | | `gt` / `lt` / `gte` / `lte` | Numeric comparison (greater/less than) | -**Example:** Route all invoices over 1 MB to a dedicated pipeline: +**Example:** Route invoices to one pipeline and large files to another: ``` Rule 1: field=document_type, operator=equals, value=Invoice, target_pipeline=3 Rule 2: field=size, operator=gt, value=1048576, target_pipeline=5 ``` +With first-match-wins logic, an invoice of any size matches Rule 1 and is +routed to pipeline 3. A non-invoice file larger than 1 MB matches Rule 2 +and is routed to pipeline 5. Everything else falls back to the default +pipeline. + You can test your rules without actually routing a document using the **evaluate** endpoint (`POST /api/routing-rules/evaluate`). For the full API reference, see [API Documentation](API.md#routing-rules).