Fix NetBox test connection: read URL/token from form, not just saved state
This commit is contained in:
parent
7a840ef3c0
commit
712174cc47
1 changed files with 20 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue