mirror of
https://github.com/idrainformatica/PecFlow.git
synced 2026-06-16 12:45:42 +02:00
Audit Log
This commit is contained in:
@@ -12,6 +12,7 @@ from app.core.exceptions import ConflictError, ForbiddenError, NotFoundError
|
||||
from app.core.security import decrypt_credential, encrypt_credential
|
||||
from app.models.mailbox import Mailbox
|
||||
from app.models.tenant import Tenant
|
||||
from app.services.audit_service import log_audit
|
||||
from app.schemas.mailbox import (
|
||||
ConnectionTestRequest,
|
||||
ConnectionTestResult,
|
||||
@@ -85,6 +86,15 @@ class MailboxService:
|
||||
)
|
||||
self.db.add(mailbox)
|
||||
await self.db.flush()
|
||||
await log_audit(
|
||||
self.db,
|
||||
"mailbox.created",
|
||||
tenant_id=tenant_id,
|
||||
user_id=created_by,
|
||||
resource_type="mailbox",
|
||||
resource_id=mailbox.id,
|
||||
payload={"email_address": mailbox.email_address},
|
||||
)
|
||||
return mailbox
|
||||
|
||||
async def list_mailboxes(
|
||||
@@ -175,6 +185,14 @@ class MailboxService:
|
||||
mailbox.status = "active"
|
||||
|
||||
await self.db.flush()
|
||||
await log_audit(
|
||||
self.db,
|
||||
"mailbox.updated",
|
||||
tenant_id=tenant_id,
|
||||
resource_type="mailbox",
|
||||
resource_id=mailbox_id,
|
||||
payload={"mailbox_id": str(mailbox_id)},
|
||||
)
|
||||
return mailbox
|
||||
|
||||
async def delete_mailbox(
|
||||
@@ -184,8 +202,17 @@ class MailboxService:
|
||||
) -> None:
|
||||
"""Soft-delete: imposta status=deleted."""
|
||||
mailbox = await self.get_mailbox(mailbox_id, tenant_id)
|
||||
email = mailbox.email_address
|
||||
mailbox.status = "deleted"
|
||||
await self.db.flush()
|
||||
await log_audit(
|
||||
self.db,
|
||||
"mailbox.deleted",
|
||||
tenant_id=tenant_id,
|
||||
resource_type="mailbox",
|
||||
resource_id=mailbox_id,
|
||||
payload={"email_address": email},
|
||||
)
|
||||
|
||||
# ─── Decrypt helpers (usati internamente e dal worker) ───────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user