From 712174cc471cd2b7ba5873879c50873cc42351f3 Mon Sep 17 00:00:00 2001 From: Graham McIntie Date: Sat, 14 Feb 2026 16:15:26 -0600 Subject: [PATCH] Fix NetBox test connection: read URL/token from form, not just saved state --- lib/towerops_web/live/org/settings_live.ex | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/towerops_web/live/org/settings_live.ex b/lib/towerops_web/live/org/settings_live.ex index aec61e1f..bfd21b7e 100644 --- a/lib/towerops_web/live/org/settings_live.ex +++ b/lib/towerops_web/live/org/settings_live.ex @@ -383,9 +383,8 @@ defmodule ToweropsWeb.Org.SettingsLive do provider = socket.assigns.configuring if provider == "netbox" do - integration = current_integration(socket) - url = get_credential(integration, "url") - token = get_credential(integration, "api_token") + # Read from form changeset (unsaved) first, fall back to saved integration + {url, token} = extract_netbox_credentials(socket) cond do url == "" or is_nil(url) -> @@ -574,6 +573,24 @@ defmodule ToweropsWeb.Org.SettingsLive do Map.get(socket.assigns.integrations, provider) end + defp extract_netbox_credentials(socket) do + # Try form changeset first (user may have typed but not saved) + changeset = socket.assigns.integration_form.source + form_creds = Ecto.Changeset.get_field(changeset, :credentials) || %{} + form_url = Map.get(form_creds, "url", "") + form_token = Map.get(form_creds, "api_token", "") + + # Fall back to saved integration + integration = current_integration(socket) + saved_url = get_credential(integration, "url") + saved_token = get_credential(integration, "api_token") + + url = if form_url == "", do: saved_url, else: form_url + token = if form_token == "", do: saved_token, else: form_token + + {url, token} + end + defp extract_api_key(socket) do changeset = socket.assigns.integration_form.source data = Ecto.Changeset.apply_changes(changeset)