feat(F-G-H-I): STL cache, invoices, import validation, notification settings
Phase F — STL Hash Cache:
- Migration 041: step_file_hash column on cad_files
- cache_service.py: SHA256 hash + MinIO-backed STL cache (check/store)
- render_step_thumbnail: compute+persist hash before render
- generate_stl_cache: check MinIO cache before cadquery conversion, store after
Phase G — Invoices:
- Migration 042: invoices + invoice_lines tables with RLS
- Invoice/InvoiceLine models + schemas
- billing service: generate_invoice_number (INV-YYYY-NNNN), create/list/get/delete/PDF
- WeasyPrint PDF generation; backend Dockerfile + pyproject.toml deps
- invoice_router with 6 endpoints; registered in main.py
- frontend: Billing.tsx page + api/billing.ts; route + nav link
Phase H — Import Sanity Check:
- Migration 043: import_validations table
- ImportValidation model + schemas
- run_sanity_check: material fuzzy-match (cutoff=0.8), STEP availability, duplicate detection
- validate_excel_import Celery task (queue: step_processing)
- uploads.py: create ImportValidation on /excel, fire task, expose GET /validations/{id}
- frontend: Upload.tsx polling ValidationDialog with Ampel status indicators
Phase I — Notification Settings:
- Migration 044: notification_configs table (user×event×channel toggles)
- NotificationConfig model + seeds (in_app=true, email=false)
- get/upsert/reset config endpoints on /notifications/config
- frontend: NotificationSettings.tsx page + api/notifications.ts extensions
Infrastructure:
- docker-compose.yml: add worker-thumbnail service (concurrency=1, Q=thumbnail_rendering)
- Fix Dockerfile: libgdk-pixbuf-2.0-0 (correct Debian bookworm package name)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,7 @@ import logging
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy import create_engine, select
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
@@ -82,3 +82,91 @@ def emit_notification_sync(
|
||||
session.commit()
|
||||
except Exception:
|
||||
logger.exception("Failed to emit notification (sync)")
|
||||
|
||||
|
||||
# ── Notification config helpers ─────────────────────────────────────────────
|
||||
|
||||
def _is_channel_enabled_sync(user_id: str | None, event_type: str, channel: str) -> bool:
|
||||
"""Check if a notification channel is enabled for a user (sync, for Celery)."""
|
||||
if not user_id:
|
||||
return channel == "in_app" # default: in_app on, email off
|
||||
engine = _get_engine()
|
||||
from app.domains.notifications.models import NotificationConfig
|
||||
with Session(engine) as session:
|
||||
cfg = session.execute(
|
||||
select(NotificationConfig).where(
|
||||
NotificationConfig.user_id == user_id,
|
||||
NotificationConfig.event_type == event_type,
|
||||
NotificationConfig.channel == channel,
|
||||
)
|
||||
).scalar_one_or_none()
|
||||
if cfg is None:
|
||||
return channel == "in_app" # default
|
||||
return cfg.enabled
|
||||
|
||||
|
||||
def send_email_notification_stub(
|
||||
*,
|
||||
to_user_id: str | None,
|
||||
event_type: str,
|
||||
subject: str,
|
||||
body: str,
|
||||
) -> None:
|
||||
"""Email notification stub — logs only, email sending not yet active."""
|
||||
logger.info(
|
||||
"[EMAIL STUB] Would send email to user=%s event=%s subject=%s",
|
||||
to_user_id, event_type, subject
|
||||
)
|
||||
|
||||
|
||||
async def get_notification_configs(db: AsyncSession, user_id: uuid.UUID) -> list:
|
||||
from app.domains.notifications.models import NotificationConfig
|
||||
from sqlalchemy import select as sa_select
|
||||
result = await db.execute(
|
||||
sa_select(NotificationConfig).where(NotificationConfig.user_id == user_id)
|
||||
.order_by(NotificationConfig.event_type, NotificationConfig.channel)
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def upsert_notification_config(
|
||||
db: AsyncSession,
|
||||
user_id: uuid.UUID,
|
||||
event_type: str,
|
||||
channel: str,
|
||||
enabled: bool,
|
||||
) -> object:
|
||||
from app.domains.notifications.models import NotificationConfig
|
||||
from sqlalchemy import select as sa_select
|
||||
result = await db.execute(
|
||||
sa_select(NotificationConfig).where(
|
||||
NotificationConfig.user_id == user_id,
|
||||
NotificationConfig.event_type == event_type,
|
||||
NotificationConfig.channel == channel,
|
||||
)
|
||||
)
|
||||
cfg = result.scalar_one_or_none()
|
||||
if cfg is None:
|
||||
cfg = NotificationConfig(user_id=user_id, event_type=event_type, channel=channel, enabled=enabled)
|
||||
db.add(cfg)
|
||||
else:
|
||||
cfg.enabled = enabled
|
||||
await db.commit()
|
||||
await db.refresh(cfg)
|
||||
return cfg
|
||||
|
||||
|
||||
async def reset_notification_configs(db: AsyncSession, user_id: uuid.UUID) -> list:
|
||||
from app.domains.notifications.models import NotificationConfig, NotificationEvent
|
||||
from sqlalchemy import delete as sa_delete
|
||||
await db.execute(sa_delete(NotificationConfig).where(NotificationConfig.user_id == user_id))
|
||||
configs = []
|
||||
for event in NotificationEvent.ALL:
|
||||
for channel, default_enabled in [("in_app", True), ("email", False)]:
|
||||
cfg = NotificationConfig(
|
||||
user_id=user_id, event_type=event, channel=channel, enabled=default_enabled
|
||||
)
|
||||
db.add(cfg)
|
||||
configs.append(cfg)
|
||||
await db.commit()
|
||||
return configs
|
||||
|
||||
Reference in New Issue
Block a user