aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/api/users.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-09-11 19:27:27 +0200
committerChristophe Besson <cbesson@gmail.com>2026-09-11 19:27:27 +0200
commitd8885c8df17c60927cb8d1f77ce1745814c6d3b4 (patch)
treefafa41edfc7adcb25d6c46d4bbf2d0fba93ed010 /packages/meshbay-hub/src/meshbay_hub/api/users.py
parentedbff1768054afa80efda721cd1011b29c7fe355 (diff)
downloadmeshbay-d8885c8df17c60927cb8d1f77ce1745814c6d3b4.tar.gz
fix(hub): an administrator can erase an account that owns groups
An administrator's deletion answered 409 for any account owning a group, so an erasure ordered by an authority had to wait on the person it was about. It now deletes the account's groups with it, then pushes a signed revocation for the account and for each group to every connected node: an access token already issued stays valid on a node until it expires, and the revocation is what makes the nodes refuse the account and close the groups' sessions now. The action is written to the IP log, and the confirmation dialog says the groups go too, in all ten catalogues. The owner's own deletion is unchanged: refused while they own groups, which they can hand over first (CGU 3.4, privacy statement). Deleting a group had three partial cascades. The owner's route left email_verifications behind, and the cleanup of unhosted groups left notifications, invitations and reports - each an IntegrityError on PostgreSQL, invisible on SQLite, which does not enforce foreign keys by default. db/purge.py is now the one implementation: it finds every table referencing groups.id from the schema, deletes the group's rows and detaches content reports, which are evidence and outlive the group. test_group_purge.py turns foreign-key enforcement on for its connection, seeds every referencing table, and fails without the fix on all three routes. MESHBAY_DESIGN.md 7.7 states the rule, and now lists the device keys and swarm sources that e3c68b3 erases. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D9MCBBWSm9GhBESmqzJxNy
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/api/users.py')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/api/users.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/api/users.py b/packages/meshbay-hub/src/meshbay_hub/api/users.py
index f291f59..a1b436e 100644
--- a/packages/meshbay-hub/src/meshbay_hub/api/users.py
+++ b/packages/meshbay-hub/src/meshbay_hub/api/users.py
@@ -1079,10 +1079,16 @@ async def unlink_node_key(
# ── Account deletion ─────────────────────────────────────────────────────────
-async def erase_account(db: AsyncSession, user: User) -> dict:
+async def erase_account(db: AsyncSession, user: User, owned_groups: str = "refuse") -> dict:
"""
Erase an account, keeping only what the law asked us to keep.
+ Groups the account owns: `"refuse"` (the owner's own deletion) answers 409
+ with their names, because deleting them strands their members and the
+ owner can hand them over first. `"delete"` (an administrator's) deletes
+ them with the account — an erasure an authority has ordered cannot wait on
+ the person it is about.
+
Gone: credentials, email, node key, group memberships, notifications, refresh
tokens, node registrations, device keys, public-swarm sources. The username
is released.
@@ -1105,7 +1111,8 @@ async def erase_account(db: AsyncSession, user: User) -> dict:
"""
owned = (await db.execute(
select(Group).where(Group.admin_id == user.id))).scalars().all()
- if owned:
+ deleted_groups = [{"id": g.id, "name": g.name} for g in owned]
+ if owned and owned_groups != "delete":
raise HTTPException(
status_code=409,
detail=("This account still owns groups: "
@@ -1113,6 +1120,9 @@ async def erase_account(db: AsyncSession, user: User) -> dict:
+ ". Delete them or hand them over first — deleting the "
"account would strand their members."),
)
+ if owned:
+ from meshbay_hub.db.purge import purge_groups
+ await purge_groups(db, [g["id"] for g in deleted_groups])
await db.execute(delete(UserPreference).where(UserPreference.user_id == user.id))
await db.execute(delete(GroupMember).where(GroupMember.user_id == user.id))
@@ -1138,8 +1148,10 @@ async def erase_account(db: AsyncSession, user: User) -> dict:
user.status = "deleted"
user.role = "user"
await db.commit()
- log.info("Account erased: %s (%s)", username, user.id[:8])
- return {"status": "deleted", "username": username}
+ log.info("Account erased: %s (%s), %d owned group(s) deleted",
+ username, user.id[:8], len(deleted_groups))
+ return {"status": "deleted", "username": username, "user_id": user.id,
+ "groups_deleted": deleted_groups}
class DeleteAccountRequest(BaseModel):