feat(D): Phase D — Undo/Restore komplett implementiert
Check Cross-Plugin Imports / check (push) Has been cancelled
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:
@@ -1643,6 +1643,18 @@ async def delete_mail(
|
||||
account = await _get_account(db, mail.account_id, tenant_id, user_id, is_system_admin=is_system_admin)
|
||||
await _check_delegate_access(db, account, user_id, "delete")
|
||||
|
||||
# Capture snapshot before delete for history/restore (D-MAIL)
|
||||
from app.services.entity_history_service import record_history
|
||||
mail_snapshot = {
|
||||
"id": str(mail.id),
|
||||
"folder_id": str(mail.folder_id) if mail.folder_id else None,
|
||||
"subject": mail.subject if hasattr(mail, "subject") else None,
|
||||
"account_id": str(mail.account_id),
|
||||
"is_read": mail.is_read if hasattr(mail, "is_read") else None,
|
||||
"is_flagged": mail.is_flagged if hasattr(mail, "is_flagged") else None,
|
||||
}
|
||||
await record_history(db, tenant_id, user_id, "mail", mail.id, "delete", snapshot_before=mail_snapshot)
|
||||
|
||||
# Find the Trash folder for this account
|
||||
trash_folder = None
|
||||
all_folders = (
|
||||
@@ -1757,9 +1769,22 @@ async def move_mail(
|
||||
).scalar_one_or_none()
|
||||
if not target_folder:
|
||||
raise HTTPException(404, detail={"detail": "Target folder not found", "code": "not_found"})
|
||||
# Capture snapshot before move (D-MAIL)
|
||||
from app.services.entity_history_service import record_history
|
||||
snapshot_before = {
|
||||
"id": str(mail.id),
|
||||
"folder_id": str(mail.folder_id) if mail.folder_id else None,
|
||||
"subject": mail.subject if hasattr(mail, "subject") else None,
|
||||
"is_read": mail.is_read if hasattr(mail, "is_read") else None,
|
||||
"is_flagged": mail.is_flagged if hasattr(mail, "is_flagged") else None,
|
||||
}
|
||||
# Update mail.folder_id
|
||||
mail.folder_id = target_f_id
|
||||
await db.flush()
|
||||
snapshot_after = {**snapshot_before, "folder_id": str(target_f_id)}
|
||||
changes = {"folder_id": {"old": snapshot_before.get("folder_id"), "new": str(target_f_id)}}
|
||||
await record_history(db, tenant_id, user_id, "mail", mail.id, "update",
|
||||
snapshot_before=snapshot_before, snapshot_after=snapshot_after, changes=changes)
|
||||
# IMAP move: queue for retry if it fails
|
||||
try:
|
||||
await mail_services.imap_move_mail(db, m_id, target_f_id, tenant_id)
|
||||
|
||||
Reference in New Issue
Block a user