aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/api
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-08-15 00:50:05 +0200
committerChristophe Besson <cbesson@gmail.com>2026-08-15 00:50:05 +0200
commitf4d04741379e77d2ef86cccc93856e590bfe1082 (patch)
treee3a094f9a8778cfcb8b3bd49ca422a28e2434104 /packages/meshbay-hub/src/meshbay_hub/api
parent76724252d08162d4df39090af19796054bf4add8 (diff)
downloadmeshbay-f4d04741379e77d2ef86cccc93856e590bfe1082.tar.gz
feat(logs): keep the username on records the account no longer answers for
The connection log took the name from a join on `users`, and deletion tombstones that row — so every record belonging to a deleted account reported `deleted-3f9a1c`, which is the one answer that helps nobody. The log is kept for a legal retention period precisely so it can say who did what; losing the name at deletion kept the data and lost the point of it. `ip_logs.username` is written as the account is erased, and stays NULL while the account is alive, where the join is better because it cannot go stale. The admin view prefers the stored name when there is one: the join still answers after deletion, just with the tombstone. Releasing the username for re-registration and keeping it in the log are separate things, and the guide now says so. On the node side, the pre-proof audit line records the username the session already knew, instead of leaving the column empty. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/api')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/api/admin.py5
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/api/users.py7
2 files changed, 10 insertions, 2 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/api/admin.py b/packages/meshbay-hub/src/meshbay_hub/api/admin.py
index efebb75..785731d 100644
--- a/packages/meshbay-hub/src/meshbay_hub/api/admin.py
+++ b/packages/meshbay-hub/src/meshbay_hub/api/admin.py
@@ -315,7 +315,10 @@ async def admin_list_logs(
{
"id": lg.id,
"user_id": lg.user_id,
- "username": uname or "",
+ # The kept name wins: it is only ever written when an account is
+ # deleted, and the join still answers then — with the tombstone,
+ # `deleted-3f9a1c`, which is the one answer that helps nobody.
+ "username": lg.username or uname or "",
"event": lg.event,
"ip_address": lg.ip_address,
"detail": lg.detail,
diff --git a/packages/meshbay-hub/src/meshbay_hub/api/users.py b/packages/meshbay-hub/src/meshbay_hub/api/users.py
index b7b402f..0bfbcac 100644
--- a/packages/meshbay-hub/src/meshbay_hub/api/users.py
+++ b/packages/meshbay-hub/src/meshbay_hub/api/users.py
@@ -7,7 +7,7 @@ from datetime import datetime, timezone, timedelta
from fastapi import APIRouter, Depends, HTTPException, Request, status
from pydantic import BaseModel, field_validator
-from sqlalchemy import delete, select
+from sqlalchemy import delete, select, update
from sqlalchemy.ext.asyncio import AsyncSession
from meshbay_hub.auth import (
@@ -365,6 +365,11 @@ async def erase_account(db: AsyncSession, user: User) -> dict:
await db.execute(delete(Node).where(Node.user_id == user.id))
username = user.username
+ # Before the name is released: the connection log is kept for its legal
+ # retention period and has to stay readable, which means saying who this was
+ # and not "deleted-3f9a1c". Nothing else keeps it.
+ await db.execute(
+ update(IPLog).where(IPLog.user_id == user.id).values(username=username))
user.username = f"deleted-{user.id[:8]}"
user.email = ""
user.pw_hash = b""