202920b9ef
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) <noreply@anthropic.com>
142 lines
3.1 KiB
Python
142 lines
3.1 KiB
Python
from datetime import datetime
|
|
|
|
from pydantic import BaseModel
|
|
|
|
from app.models.db_models import ActionType, ConditionField, MatchType
|
|
|
|
|
|
# --- Filter Condition ---
|
|
|
|
|
|
class FilterConditionCreate(BaseModel):
|
|
field: ConditionField
|
|
match_type: MatchType
|
|
value: str
|
|
negate: bool = False
|
|
|
|
|
|
class FilterConditionResponse(FilterConditionCreate):
|
|
id: int
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
# --- Filter Action ---
|
|
|
|
|
|
class FilterActionCreate(BaseModel):
|
|
action_type: ActionType
|
|
parameter: str | None = None
|
|
|
|
|
|
class FilterActionResponse(FilterActionCreate):
|
|
id: int
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
# --- Filter Rule ---
|
|
|
|
|
|
class FilterRuleCreate(BaseModel):
|
|
name: str
|
|
account_id: int
|
|
priority: int | None = None # None → automatisch ans Ende einsortieren (max+10)
|
|
enabled: bool = True
|
|
stop_processing: bool = False
|
|
source_folder: str = "INBOX"
|
|
conditions: list[FilterConditionCreate] = []
|
|
actions: list[FilterActionCreate] = []
|
|
|
|
|
|
class FilterRuleUpdate(BaseModel):
|
|
name: str | None = None
|
|
priority: int | None = None
|
|
enabled: bool | None = None
|
|
stop_processing: bool | None = None
|
|
source_folder: str | None = None
|
|
conditions: list[FilterConditionCreate] | None = None
|
|
actions: list[FilterActionCreate] | None = None
|
|
|
|
|
|
class FilterRuleResponse(BaseModel):
|
|
id: int
|
|
account_id: int
|
|
name: str
|
|
priority: int
|
|
enabled: bool
|
|
stop_processing: bool
|
|
source_folder: str
|
|
conditions: list[FilterConditionResponse]
|
|
actions: list[FilterActionResponse]
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
# --- Account ---
|
|
|
|
|
|
class AccountCreate(BaseModel):
|
|
name: str
|
|
imap_host: str
|
|
imap_port: int = 993
|
|
use_ssl: bool = True
|
|
username: str
|
|
password: str
|
|
smtp_host: str | None = None
|
|
smtp_port: int | None = None
|
|
smtp_username: str | None = None
|
|
smtp_password: str | None = None
|
|
poll_interval_seconds: int = 120
|
|
enabled: bool = True
|
|
|
|
|
|
class AccountUpdate(BaseModel):
|
|
name: str | None = None
|
|
imap_host: str | None = None
|
|
imap_port: int | None = None
|
|
use_ssl: bool | None = None
|
|
username: str | None = None
|
|
password: str | None = None
|
|
smtp_host: str | None = None
|
|
smtp_port: int | None = None
|
|
smtp_username: str | None = None
|
|
smtp_password: str | None = None
|
|
poll_interval_seconds: int | None = None
|
|
enabled: bool | None = None
|
|
|
|
|
|
class AccountResponse(BaseModel):
|
|
id: int
|
|
name: str
|
|
imap_host: str
|
|
imap_port: int
|
|
use_ssl: bool
|
|
username: str
|
|
smtp_host: str | None
|
|
smtp_port: int | None
|
|
smtp_username: str | None
|
|
poll_interval_seconds: int
|
|
enabled: bool
|
|
last_poll_at: datetime | None
|
|
filter_rules: list[FilterRuleResponse] = []
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class AccountListResponse(BaseModel):
|
|
id: int
|
|
name: str
|
|
imap_host: str
|
|
username: str
|
|
enabled: bool
|
|
last_poll_at: datetime | None
|
|
poll_interval_seconds: int
|
|
filter_rule_count: int = 0
|
|
|
|
model_config = {"from_attributes": True}
|