refactor: 🎨 when deleting an identity it tells you if it fails
This commit is contained in:
@@ -699,6 +699,17 @@ def update_identity(iid: int):
|
|||||||
@require_login
|
@require_login
|
||||||
def delete_identity(iid: int):
|
def delete_identity(iid: int):
|
||||||
with db_cursor() as (_, cur):
|
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,))
|
cur.execute("DELETE FROM ssh_identities WHERE id = %s", (iid,))
|
||||||
if cur.rowcount == 0:
|
if cur.rowcount == 0:
|
||||||
return jsonify({"error": "not found"}), 404
|
return jsonify({"error": "not found"}), 404
|
||||||
|
|||||||
+19
-1
@@ -44,6 +44,8 @@ const showAuditLog = ref(false);
|
|||||||
const auditLoading = ref(false);
|
const auditLoading = ref(false);
|
||||||
const auditErr = ref("");
|
const auditErr = ref("");
|
||||||
const auditRows = ref<ConnectionAuditRow[]>([]);
|
const auditRows = ref<ConnectionAuditRow[]>([]);
|
||||||
|
const deleteIdentityErr = ref("");
|
||||||
|
const deleteIdentityErrId = ref<number | null>(null);
|
||||||
const newFolderLabel = ref("");
|
const newFolderLabel = ref("");
|
||||||
const identityForm = ref({
|
const identityForm = ref({
|
||||||
label: "",
|
label: "",
|
||||||
@@ -311,9 +313,15 @@ async function deleteHostRow(id: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function deleteIdentityRow(id: number) {
|
async function deleteIdentityRow(id: number) {
|
||||||
if (!confirm("Remove this identity? Hosts using it may break.")) return;
|
if (!confirm("Remove this identity?")) return;
|
||||||
|
deleteIdentityErr.value = "";
|
||||||
|
try {
|
||||||
await api.deleteIdentity(id);
|
await api.deleteIdentity(id);
|
||||||
await refreshData();
|
await refreshData();
|
||||||
|
} catch (e) {
|
||||||
|
deleteIdentityErr.value = e instanceof Error ? e.message : "Failed to delete identity";
|
||||||
|
deleteIdentityErrId.value = id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -539,6 +547,16 @@ async function deleteIdentityRow(id: number) {
|
|||||||
<div class="text-xs font-medium uppercase tracking-wide text-slate-500">
|
<div class="text-xs font-medium uppercase tracking-wide text-slate-500">
|
||||||
Saved identities
|
Saved identities
|
||||||
</div>
|
</div>
|
||||||
|
<p v-if="deleteIdentityErr" class="mt-2 text-[11px] text-red-400">
|
||||||
|
{{ deleteIdentityErr }}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="ml-2 underline hover:text-red-300"
|
||||||
|
@click="deleteIdentityErr = ''"
|
||||||
|
>
|
||||||
|
Dismiss
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
<ul class="mt-1 max-h-32 overflow-auto text-xs text-slate-400">
|
<ul class="mt-1 max-h-32 overflow-auto text-xs text-slate-400">
|
||||||
<li
|
<li
|
||||||
v-for="i in identities"
|
v-for="i in identities"
|
||||||
|
|||||||
Reference in New Issue
Block a user