feat: add audit logging for admin trash restore/purge and notification clear actions

- Record audit events in `admin_trash_restore` and `admin_trash_purge` endpoints with target metadata
- Log `notification.read.all` event when user clears devRant notification feed
- Include `devrant` as a valid origin in audit categories
- Add `admin_section` and `pagination_query` fields to audit and backup schemas for UI consistency
This commit is contained in:
2026-06-16 05:08:58 +00:00
parent 1934dd5727
commit 99ed5c4f15
24 changed files with 466 additions and 186 deletions
+21
View File
@@ -18,6 +18,7 @@ from devplacepy.utils import require_admin, not_found
from devplacepy.seo import base_seo_context, site_url, website_schema
from devplacepy.responses import respond, action_result
from devplacepy.schemas import AdminTrashOut
from devplacepy.services.audit import record as audit
logger = logging.getLogger(__name__)
router = APIRouter()
@@ -115,6 +116,16 @@ async def admin_trash_restore(request: Request, table: str, uid: str):
logger.info(
f"Admin {admin['username']} restored {table} {uid} ({restored} rows)"
)
audit.record(
request,
"admin.trash.restore",
user=admin,
target_type=table,
target_uid=uid,
target_label=_trash_label(table, row),
metadata={"table": table, "rows": restored},
summary=f"{admin['username']} restored {table} {uid}",
)
return action_result(request, f"/admin/trash?table={table}")
@@ -135,4 +146,14 @@ async def admin_trash_purge(request: Request, table: str, uid: str):
if node.get("is_binary"):
_unlink_blob(node)
logger.info(f"Admin {admin['username']} purged {table} {uid}")
audit.record(
request,
"admin.trash.purge",
user=admin,
target_type=table,
target_uid=uid,
target_label=_trash_label(table, row),
metadata={"table": table, "tables": [t for t, _ in purged]},
summary=f"{admin['username']} permanently purged {table} {uid}",
)
return action_result(request, f"/admin/trash?table={table}")