feat: agent-11 PR3 – Scheduler + Erinnerungs-Mails + Notification-Prefs

Geplante Erinnerungen (Feature-Parität mit Urlaubsverwaltung):

- APScheduler (AsyncIOScheduler) in der FastAPI-Lifespan; tägliche Jobs ab
  settings.reminder_hour. Redis-Tageslock gegen Doppelversand bei mehreren
  Prozessen; jeder Job mit eigener Session + RLS-Bypass.
- Drei Jobs (auch einzeln aufrufbar): offene Anträge an Genehmiger,
  Resturlaub-Verfall-Vorwarnung an Mitarbeiter, fehlende AU an HR.
- Pro-User notification_prefs (JSONB, opt-out); GET/PATCH /users/me/notification-prefs
  + ProfilePage-UI; Vertreter-Mail respektiert die Prefs.
- Manueller Trigger POST /companies/me/run-reminders (Admin) – gleiche Logik,
  firmen-scoped (testbar ohne Warten).
- Bugfix: GET-/PATCH-Urlaubskonto (update_balance) nutzte nicht existente
  Felder (base_days/carried_over_days/ip_address) → korrigiert auf
  entitled_days/carried_over/ip + company_id; available_days ergänzt.

Migration 0037 (users.notification_prefs). 188/188 Tests grün. Deployed 137 + 164.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-23 12:21:14 +02:00
co-authored by Claude Opus 4.8
parent e8bed43570
commit 2f110df619
15 changed files with 542 additions and 9 deletions
+28
View File
@@ -12,6 +12,8 @@ from app.schemas.auth import MessageResponse
from app.schemas.user import (
InviteRequest,
NextPersonnelNumberResponse,
NotificationPrefsUpdate,
NotificationTypeOut,
SetKioskPinRequest,
UserImportResult,
UserImportRowResult,
@@ -79,6 +81,32 @@ async def get_me(current_user: CurrentUser):
return UserOut.model_validate(current_user)
@router.get("/me/notification-prefs", response_model=list[NotificationTypeOut])
async def get_notification_prefs(current_user: CurrentUser):
from app.core.notifications import NOTIFICATION_TYPES, pref_enabled
return [
NotificationTypeOut(key=k, label=label, enabled=pref_enabled(current_user, k))
for k, (label, _default) in NOTIFICATION_TYPES.items()
]
@router.patch("/me/notification-prefs", response_model=list[NotificationTypeOut])
async def update_notification_prefs(
data: NotificationPrefsUpdate,
current_user: CurrentUser,
db: AsyncSession = Depends(get_db),
):
from app.core.notifications import NOTIFICATION_TYPES, normalize_prefs, pref_enabled
merged = dict(current_user.notification_prefs or {})
merged.update(normalize_prefs(data.prefs))
current_user.notification_prefs = merged # neues dict → JSONB-Änderung erkannt
await db.commit()
return [
NotificationTypeOut(key=k, label=label, enabled=pref_enabled(current_user, k))
for k, (label, _default) in NOTIFICATION_TYPES.items()
]
@router.get("/next-personnel-number", response_model=NextPersonnelNumberResponse)
async def next_personnel_number(
current_user: User = require_role(*_hr_roles),