Drop the sharing settings of tools deleted with their connection

Removing a connection with its tools now also deletes those tools' sharing
switches in the same transaction, as deleting a tool on its own does.
Team grants and chat preferences were already removed with the tools.
This commit is contained in:
arc53-machine committed 2026-09-29 14:13:35 +01:00
1 parent a45e369d0f
commit b2d26c72ed
2 files changed
+30 -1

No files matched your search

+8 -1
View File
@@ -1442,8 +1442,15 @@ def remove_connection(conn, row: dict, *, sources: str = "keep", tools: str = "d
except CredentialDecryptionError:
pass
if tools == "delete":
# Team grants go with the tools (delete trigger) and chat preferences
# by FK cascade; the owner's sharing switches have no FK.
conn.execute(
text("DELETE FROM user_tools WHERE connection_id = CAST(:id AS uuid) AND user_id = :user_id"),
text(
"WITH gone AS (DELETE FROM user_tools WHERE connection_id = CAST(:id AS uuid) "
"AND user_id = :user_id RETURNING id) "
"DELETE FROM resource_share_settings WHERE resource_type = 'tool' "
"AND resource_id IN (SELECT id FROM gone)"
),
{"id": connection_id, "user_id": row["user_id"]},
)
else: