Discord remove server: audit a removal a restart interrupted
DELETE /discord/guilds/{id} deletes channels one by one. If a channel was
restarted mid-removal, delete_stream raised "restarted" and the route
returned 409 with no audit entry, though the channels before it were
already deleted for good. The error now carries the channels already
removed and the route writes discord.guild.remove with outcome
"incomplete" before returning the 409. The server stays linked.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c92bdfe841
commit
25553fbac6
@@ -374,8 +374,15 @@ async def remove_guild(guild_id: str, by: str) -> dict:
|
||||
link = await fstore.doc_get(GUILDS, guild_id) or {}
|
||||
removed = []
|
||||
for s in await fstore.collection_list(STREAMS, guild_id=guild_id):
|
||||
if s.get("stream_id") and await delete_stream(s["stream_id"], "server_removed"):
|
||||
removed.append(s["stream_id"])
|
||||
try:
|
||||
if s.get("stream_id") and await delete_stream(s["stream_id"], "server_removed"):
|
||||
removed.append(s["stream_id"])
|
||||
except StreamError as e:
|
||||
# A channel restarted mid-removal: stop here, leave the server
|
||||
# linked, and tell the caller which channels are already gone so
|
||||
# the partial removal is still audited.
|
||||
e.removed = removed
|
||||
raise
|
||||
now = _now_iso()
|
||||
await fstore.doc_set(GUILDS, guild_id, {
|
||||
"guild_id": guild_id, "org_id": None,
|
||||
|
||||
@@ -222,6 +222,11 @@ async def remove_guild(guild_id: str, leave_radio_bots: bool = False,
|
||||
try:
|
||||
out = await streams.remove_guild(guild_id, uid)
|
||||
except streams.StreamError as e:
|
||||
# Channels deleted before the race are gone for good — audit them.
|
||||
await write_audit(uid, email, "discord.guild.remove", details={
|
||||
"guild_id": guild_id, "acting_org_id": acting_org, "outcome": "incomplete", "error": e.code,
|
||||
"streams_removed": getattr(e, "removed", []), "leave_radio_bots": leave_radio_bots,
|
||||
})
|
||||
return _error(e)
|
||||
left: list = []
|
||||
if leave_radio_bots:
|
||||
|
||||
Reference in New Issue
Block a user