From 202920b9effaf6341310dbf6b5576f8a8b2a2de4 Mon Sep 17 00:00:00 2001 From: duffyduck Date: Sun, 31 May 2026 10:46:52 +0200 Subject: [PATCH] auto-assign filter priority (max+10) on create New filter rules no longer default to priority 100. Server picks max(priority)+10 per account when client sends priority=None (or 10 if the account has no rules yet), and the UI pre-fills the input with the next value instead of a fixed 100. Avoids ambiguous ordering when multiple rules end up with the same priority. Co-Authored-By: Claude Opus 4.7 (1M context) --- app/routers/filters.py | 13 ++++++++++++- app/schemas/schemas.py | 2 +- app/templates/filters.html | 14 ++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/routers/filters.py b/app/routers/filters.py index fcaf46d..362b7ef 100644 --- a/app/routers/filters.py +++ b/app/routers/filters.py @@ -1,4 +1,5 @@ from fastapi import APIRouter, Depends, HTTPException +from sqlalchemy import func from sqlalchemy.orm import Session import logging @@ -52,10 +53,20 @@ def create_filter(data: FilterRuleCreate, db: Session = Depends(get_db)): if not account: raise HTTPException(404, "Konto nicht gefunden") + if data.priority is None: + # Ans Ende einsortieren: max(priority) + 10 für dieses Konto. Falls noch + # keine Regel existiert, starten wir bei 10. + current_max = db.query(func.max(FilterRule.priority)).filter( + FilterRule.account_id == data.account_id + ).scalar() + priority = (current_max + 10) if current_max is not None else 10 + else: + priority = data.priority + rule = FilterRule( account_id=data.account_id, name=data.name, - priority=data.priority, + priority=priority, enabled=data.enabled, stop_processing=data.stop_processing, source_folder=data.source_folder, diff --git a/app/schemas/schemas.py b/app/schemas/schemas.py index c935f7b..1f501b3 100644 --- a/app/schemas/schemas.py +++ b/app/schemas/schemas.py @@ -41,7 +41,7 @@ class FilterActionResponse(FilterActionCreate): class FilterRuleCreate(BaseModel): name: str account_id: int - priority: int = 100 + priority: int | None = None # None → automatisch ans Ende einsortieren (max+10) enabled: bool = True stop_processing: bool = False source_folder: str = "INBOX" diff --git a/app/templates/filters.html b/app/templates/filters.html index 22e6719..34cee8a 100644 --- a/app/templates/filters.html +++ b/app/templates/filters.html @@ -29,8 +29,8 @@