fix(imap): address code review feedback on ingestion profiles

- Improve warning log in _resolve_categories_for_profile() to include
  exception type name for better troubleshooting
- Add SQLAlchemy IS NULL comment to imap_profiles.py filter
- Pass default_categories from server to template to avoid hardcoded
  category list in JS (now uses {{ default_categories | tojson }})
- Simplify view profiles query (remove redundant unauthenticated path)
- Update docs: ConfigurationGuide.md and EmailIngestion.md with
  full profiles documentation including category table and API reference

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-12 01:19:32 +00:00
parent c9f554465d
commit 2e087731b9
7 changed files with 79 additions and 25 deletions
+1
View File
@@ -154,6 +154,7 @@ def list_profiles(request: Request, db: DbSession, owner_id: CurrentOwner) -> li
profiles = (
db.query(ImapIngestionProfile)
.filter(
# SQLAlchemy requires `== None` for IS NULL comparison in ORM filters
(ImapIngestionProfile.owner_id == None) | (ImapIngestionProfile.owner_id == owner_id) # noqa: E711
)
.order_by(ImapIngestionProfile.is_builtin.desc(), ImapIngestionProfile.id)
+6 -1
View File
@@ -73,7 +73,12 @@ def _resolve_categories_for_profile(profile_id: int | None) -> list[str]:
finally:
db.close()
except Exception as exc: # noqa: BLE001
logger.warning("Could not load IMAP ingestion profile %d: %s — using global default", profile_id, exc)
logger.warning(
"Could not load IMAP ingestion profile %d (%s: %s) — using global default",
profile_id,
type(exc).__name__,
exc,
)
# Fall back to global setting
if settings.imap_attachment_filter == "all":
+5 -9
View File
@@ -7,7 +7,7 @@ from fastapi import Request
from sqlalchemy.orm import Session
from app.models import ImapIngestionProfile, UserImapAccount
from app.utils.allowed_types import FILE_TYPE_CATEGORIES
from app.utils.allowed_types import DEFAULT_CATEGORIES, FILE_TYPE_CATEGORIES
from app.utils.subscription import get_tier, get_user_tier_id
from app.utils.user_scope import get_current_owner_id
from app.views.base import APIRouter, Depends, get_db, require_login, templates
@@ -68,19 +68,14 @@ async def imap_accounts_page(request: Request, db: Session = Depends(get_db)):
can_add = max_mailboxes is None or (max_mailboxes > 0 and current_count < max_mailboxes)
# Load ingestion profiles: system-global + user's own
profiles: list[ImapIngestionProfile] = (
profiles = (
db.query(ImapIngestionProfile)
.filter(
(ImapIngestionProfile.owner_id == None) # noqa: E711
| (ImapIngestionProfile.owner_id == owner_id)
# SQLAlchemy requires `== None` for IS NULL comparison in ORM filters
(ImapIngestionProfile.owner_id == None) | (ImapIngestionProfile.owner_id == owner_id) # noqa: E711
)
.order_by(ImapIngestionProfile.is_builtin.desc(), ImapIngestionProfile.id)
.all()
if owner_id
else db.query(ImapIngestionProfile)
.filter(ImapIngestionProfile.owner_id == None) # noqa: E711
.order_by(ImapIngestionProfile.id)
.all()
)
# Category definitions for the UI checkbox builder
@@ -100,6 +95,7 @@ async def imap_accounts_page(request: Request, db: Session = Depends(get_db)):
"accounts": accounts,
"profiles": [_serialize_profile(p) for p in profiles],
"categories": categories,
"default_categories": DEFAULT_CATEGORIES,
"current_count": current_count,
"max_mailboxes": max_mailboxes,
"can_add": can_add,