refactor: 🎨 when deleting an identity it tells you if it fails

This commit is contained in:
2026-05-14 11:33:46 +00:00
parent 4e77b8f412
commit 5bba2947c4
2 changed files with 32 additions and 3 deletions
+11
View File
@@ -699,6 +699,17 @@ def update_identity(iid: int):
@require_login
def delete_identity(iid: int):
with db_cursor() as (_, cur):
# Check if identity is being used by any hosts
cur.execute(
"SELECT COUNT(*) as count FROM ssh_hosts WHERE identity_id = %s",
(iid,),
)
result = cur.fetchone()
if result and result["count"] > 0:
return jsonify({
"error": f"Cannot delete identity: it is being used by {result['count']} host(s)"
}), 409
cur.execute("DELETE FROM ssh_identities WHERE id = %s", (iid,))
if cur.rowcount == 0:
return jsonify({"error": "not found"}), 404