summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-08-21 18:10:19 +0200
committerChristophe Besson <cbesson@gmail.com>2026-08-21 18:10:19 +0200
commit83881b389b96931bd504965479ff05aeabcd7ff2 (patch)
treec7fd4cc04ea2d360a37b78f300d424ee01d1fea3
parent81c7d1a34c6b1505f0a75b39c2232f92b1ca4512 (diff)
downloadmeshbay-83881b389b96931bd504965479ff05aeabcd7ff2.tar.gz
fix: delete notifications and detach content_reports before deleting a group
The DELETE /v1/groups/{id} endpoint only deleted group_members before removing the group row, causing a FK violation (500) when notifications or content_reports referenced the group. Delete notifications outright and nullify group_id on content_reports to preserve moderation history. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/api/groups.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/api/groups.py b/packages/meshbay-hub/src/meshbay_hub/api/groups.py
index 65307f1..e78d950 100644
--- a/packages/meshbay-hub/src/meshbay_hub/api/groups.py
+++ b/packages/meshbay-hub/src/meshbay_hub/api/groups.py
@@ -10,8 +10,8 @@ from meshbay_hub.api.deps import get_current_user, require_user_scope
from meshbay_hub.api.netutil import client_ip
from meshbay_hub.db.engine import get_db
from meshbay_hub.db.models import (
- FederatedGroup, Group, GroupMember,
- IPLog, SwarmSource, User,
+ ContentReport, FederatedGroup, Group, GroupMember,
+ IPLog, Notification, SwarmSource, User,
)
router = APIRouter(prefix="/v1/groups", tags=["groups"])
@@ -592,7 +592,12 @@ async def delete_group(
raise HTTPException(status_code=403, detail="Only the group creator can delete")
from sqlalchemy import delete as sa_delete
+ await db.execute(sa_delete(Notification).where(Notification.group_id == group_id))
await db.execute(sa_delete(GroupMember).where(GroupMember.group_id == group_id))
+ await db.execute(
+ update(ContentReport)
+ .where(ContentReport.group_id == group_id)
+ .values(group_id=None))
db.add(IPLog(user_id=current_user.id, event="group_delete",
ip_address=client_ip(request), detail=group.name))
await db.delete(group)