feat(D): Phase D — Undo/Restore komplett implementiert
Check Cross-Plugin Imports / check (push) Has been cancelled

- D-GEN: RestoreRegistry mit RestoreConfig (model_class, restore_permission, excluded_fields, special_handler)
- D-HOOK: history_hooks.py mit register_history_hooks() für after_create/update/delete
- D-CORE: Company create+update record_history in companies.py
- D-PLUG: Task/Calendar/DMS record_history in services/routes
- D-SOFT: Alle registrierten Entitäten haben deleted_at + un-delete via Registry
- D-MAIL: Mail special_handler (IMAP Trash-Move, Folder-Verify) + record_history in delete/move
- D-TRASH: GET /entity-history/trash (filterbar, paginiert) + Frontend Trash.tsx
- D-TOAST: UndoToast.tsx (5s Auto-Dismiss, useUndoToast Hook)
- D-HIST-UI: HistoryPanel.tsx (Timeline, Diff-View, Restore-Button)
- D-BULK: POST /entity-history/bulk-restore mit partial_success Semantik
- D-RET: POST /entity-history/retention/archive (GDPR hard-delete >90 Tage)
- D-TEST: 26 Tests in test_restore_registry.py, alle grün
- D-DOC: test-strategy.md + security_kernel.md aktualisiert

Backend: 10 Dateien, Frontend: 7 Dateien, Tests: 1 Datei, Docs: 3 Dateien
26/26 Tests passed, TSC 0 errors, App import 492 routes
This commit is contained in:
Agent Zero
2026-08-13 23:08:29 +02:00
parent 29410f19d3
commit a4d0f0c35d
22 changed files with 2175 additions and 91 deletions
+22 -1
View File
@@ -465,6 +465,9 @@ async def create_entry(
)
db.add(entry)
await db.flush()
# Record history (D-PLUG)
from app.services.entity_history_service import record_history
await record_history(db, tenant_id, user_id, "calendar_entry", entry.id, "create", snapshot_after=_entry_to_dict(entry))
# ── Hook: calendar.after_appointment (Action) ──
from app.core.hooks import do_action
@@ -614,6 +617,8 @@ async def update_entry(
from app.core.hooks import do_action
await do_action("calendar.before_update", body=body, tenant_id=tenant_id, user_id=user_id, entry_id=entry_id)
# Capture snapshot before update (D-PLUG)
snapshot_before = _entry_to_dict(entry)
# Apply updates
if body.title is not None:
entry.title = body.title
@@ -648,9 +653,20 @@ async def update_entry(
await db.flush()
await db.refresh(entry)
snapshot_after = _entry_to_dict(entry)
# Compute changes diff (D-PLUG)
changes: dict = {}
for key, new_val in snapshot_after.items():
old_val = snapshot_before.get(key)
if old_val != new_val:
changes[key] = {"old": old_val, "new": new_val}
# Record history (D-PLUG)
from app.services.entity_history_service import record_history
await record_history(db, tenant_id, user_id, "calendar_entry", entry.id, "update",
snapshot_before=snapshot_before, snapshot_after=snapshot_after, changes=changes or None)
from app.core.hooks import do_action
await do_action("calendar.after_update", entry_id=str(entry.id), tenant_id=tenant_id, user_id=user_id)
return _entry_to_dict(entry)
return snapshot_after
@router.delete("/calendar/entries/{entry_id}", status_code=status.HTTP_204_NO_CONTENT, dependencies=[Depends(require_permission("calendar:delete"))])
@@ -670,8 +686,13 @@ async def delete_entry(
raise HTTPException(403, detail={"detail": "No write permission", "code": "forbidden"})
from app.core.hooks import do_action
await do_action("calendar.before_delete", tenant_id=tenant_id, user_id=user_id, entry_id=entry_id)
# Capture snapshot before delete (D-PLUG)
snapshot_before = _entry_to_dict(entry)
entry.deleted_at = datetime.now(UTC)
await db.flush()
# Record history (D-PLUG)
from app.services.entity_history_service import record_history
await record_history(db, tenant_id, user_id, "calendar_entry", entry.id, "delete", snapshot_before=snapshot_before)
from app.core.hooks import do_action
await do_action("calendar.after_delete", tenant_id=tenant_id, user_id=user_id, entry_id=entry_id)
return Response(status_code=204)