From 9c2f08317f81adddd7431b53290c2dea711b2976 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 18 Jan 2026 13:06:23 -0600 Subject: [PATCH] feat: remove organization slug from sites and devices URLs - Created new on_mount hook :load_default_organization that automatically loads user's first organization - Moved sites and devices routes to root path (/ sites, /devices) instead of /orgs/:org_slug - Updated all navigation links and route references throughout the app - Dashboard, alerts, and agents still use org-specific routes (/orgs/:org_slug) - Users can still switch organizations via org selector for other pages --- lib/towerops_web/components/layouts.ex | 4 +- .../live/agent_live/show.html.heex | 2 +- .../live/alert_live/index.html.heex | 6 +- .../live/dashboard_live.html.heex | 12 ++-- lib/towerops_web/live/device_live/form.ex | 8 +-- .../live/device_live/form.html.heex | 6 +- .../live/device_live/index.html.heex | 10 +-- .../live/device_live/show.html.heex | 46 +++++--------- lib/towerops_web/live/graph_live/show.ex | 3 +- .../live/graph_live/show.html.heex | 2 +- lib/towerops_web/live/site_live/form.ex | 6 +- .../live/site_live/form.html.heex | 6 +- .../live/site_live/index.html.heex | 6 +- .../live/site_live/show.html.heex | 12 ++-- lib/towerops_web/router.ex | 26 +++++--- lib/towerops_web/user_auth.ex | 61 +++++++++++++++++-- 16 files changed, 129 insertions(+), 87 deletions(-) diff --git a/lib/towerops_web/components/layouts.ex b/lib/towerops_web/components/layouts.ex index 7174ce34..4a8bea47 100644 --- a/lib/towerops_web/components/layouts.ex +++ b/lib/towerops_web/components/layouts.ex @@ -150,13 +150,13 @@ defmodule ToweropsWeb.Layouts do Dashboard <.nav_link - navigate={~p"/orgs/#{@current_organization.slug}/sites"} + navigate={~p"/sites"} active={@active_page == "sites"} > Sites <.nav_link - navigate={~p"/orgs/#{@current_organization.slug}/devices"} + navigate={~p"/devices"} active={@active_page == "devices"} > Devices diff --git a/lib/towerops_web/live/agent_live/show.html.heex b/lib/towerops_web/live/agent_live/show.html.heex index baf6ca84..e7b1398f 100644 --- a/lib/towerops_web/live/agent_live/show.html.heex +++ b/lib/towerops_web/live/agent_live/show.html.heex @@ -218,7 +218,7 @@
<%= for device <- @polling_targets do %> <.link - navigate={~p"/orgs/#{@organization.slug}/devices/#{device.id}"} + navigate={~p"/devices/#{device.id}"} class="block hover:bg-zinc-50 dark:hover:bg-zinc-800 transition-colors" >
diff --git a/lib/towerops_web/live/alert_live/index.html.heex b/lib/towerops_web/live/alert_live/index.html.heex index 7a5ea29e..3e560358 100644 --- a/lib/towerops_web/live/alert_live/index.html.heex +++ b/lib/towerops_web/live/alert_live/index.html.heex @@ -95,7 +95,7 @@

<.link - navigate={~p"/orgs/#{@current_organization.slug}/devices/#{alert.device.id}"} + navigate={~p"/devices/#{alert.device.id}"} class="text-blue-600 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300" > {alert.device.name} @@ -130,9 +130,7 @@
Site: <.link - navigate={ - ~p"/orgs/#{@current_organization.slug}/sites/#{alert.device.site.id}" - } + navigate={~p"/sites/#{alert.device.site.id}"} class="text-blue-600 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300" > {alert.device.site.name} diff --git a/lib/towerops_web/live/dashboard_live.html.heex b/lib/towerops_web/live/dashboard_live.html.heex index 528b9ca5..12026b2d 100644 --- a/lib/towerops_web/live/dashboard_live.html.heex +++ b/lib/towerops_web/live/dashboard_live.html.heex @@ -62,7 +62,7 @@

- <.button navigate={~p"/orgs/#{@current_organization.slug}/sites/new"} variant="primary"> + <.button navigate={~p"/sites/new"} variant="primary"> <.icon name="hero-plus" class="h-5 w-5" /> Create Your First Site
@@ -70,7 +70,7 @@ <% else %>
<.link - navigate={~p"/orgs/#{@current_organization.slug}/sites"} + navigate={~p"/sites"} class="rounded-lg border border-zinc-200 bg-white p-6 shadow-sm transition-shadow hover:shadow-md dark:border-zinc-800 dark:bg-zinc-900" >

Sites

@@ -79,7 +79,7 @@ <.link - navigate={~p"/orgs/#{@current_organization.slug}/devices"} + navigate={~p"/devices"} class="rounded-lg border border-zinc-200 bg-white p-6 shadow-sm transition-shadow hover:shadow-md dark:border-zinc-800 dark:bg-zinc-900" >

Device

@@ -155,7 +155,7 @@

<.link - navigate={~p"/orgs/#{@current_organization.slug}/devices/#{alert.device.id}"} + navigate={~p"/devices/#{alert.device.id}"} class="hover:text-blue-600 hover:underline dark:hover:text-blue-400" > {alert.device.name} @@ -182,14 +182,14 @@

Quick Actions

<.link - navigate={~p"/orgs/#{@current_organization.slug}/sites"} + navigate={~p"/sites"} class="inline-flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:ring-offset-2 dark:bg-blue-500 dark:hover:bg-blue-600" > <.icon name="hero-building-office" class="h-5 w-5" /> Manage Sites <.link - navigate={~p"/orgs/#{@current_organization.slug}/devices"} + navigate={~p"/devices"} class="inline-flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:ring-offset-2 dark:bg-blue-500 dark:hover:bg-blue-600" > <.icon name="hero-server" class="h-5 w-5" /> diff --git a/lib/towerops_web/live/device_live/form.ex b/lib/towerops_web/live/device_live/form.ex index 93a342ec..5e9e7c95 100644 --- a/lib/towerops_web/live/device_live/form.ex +++ b/lib/towerops_web/live/device_live/form.ex @@ -20,7 +20,7 @@ defmodule ToweropsWeb.DeviceLive.Form do {:ok, socket |> put_flash(:info, "Please create a site before adding a device.") - |> push_navigate(to: ~p"/orgs/#{organization.slug}/sites/new")} + |> push_navigate(to: ~p"/sites/new")} else {:ok, socket @@ -163,7 +163,7 @@ defmodule ToweropsWeb.DeviceLive.Form do {:noreply, socket |> put_flash(:info, "Device deleted successfully") - |> push_navigate(to: ~p"/orgs/#{socket.assigns.organization.slug}/devices")} + |> push_navigate(to: ~p"/devices")} {:error, _} -> {:noreply, put_flash(socket, :error, "Unable to delete device")} @@ -203,7 +203,7 @@ defmodule ToweropsWeb.DeviceLive.Form do {:noreply, socket |> put_flash(:info, "Discovery started...") - |> push_navigate(to: ~p"/orgs/#{socket.assigns.organization.slug}/devices/#{device.id}")} + |> push_navigate(to: ~p"/devices/#{device.id}")} else {:noreply, put_flash(socket, :error, "SNMP is not enabled for this device")} end @@ -271,7 +271,7 @@ defmodule ToweropsWeb.DeviceLive.Form do {:noreply, socket |> put_flash(:info, flash_message) - |> push_navigate(to: ~p"/orgs/#{socket.assigns.organization.slug}/devices/#{device.id}")} + |> push_navigate(to: ~p"/devices/#{device.id}")} {:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign(socket, :form, to_form(changeset))} diff --git a/lib/towerops_web/live/device_live/form.html.heex b/lib/towerops_web/live/device_live/form.html.heex index f3f3fe9f..fb03d8c9 100644 --- a/lib/towerops_web/live/device_live/form.html.heex +++ b/lib/towerops_web/live/device_live/form.html.heex @@ -8,8 +8,8 @@ <.link navigate={ if @live_action == :edit, - do: ~p"/orgs/#{@organization.slug}/devices/#{@device.id}", - else: ~p"/orgs/#{@organization.slug}/devices" + do: ~p"/devices/#{@device.id}", + else: ~p"/devices" } class="inline-flex items-center gap-1 text-sm text-zinc-600 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-100" > @@ -240,7 +240,7 @@
<.button phx-disable-with="Saving..." variant="primary">Save Device - <.button navigate={~p"/orgs/#{@organization.slug}/devices"}>Cancel + <.button navigate={~p"/devices"}>Cancel
diff --git a/lib/towerops_web/live/device_live/index.html.heex b/lib/towerops_web/live/device_live/index.html.heex index 6012e0fc..8e0c4769 100644 --- a/lib/towerops_web/live/device_live/index.html.heex +++ b/lib/towerops_web/live/device_live/index.html.heex @@ -11,7 +11,7 @@ <:actions> <.button :if={@has_sites} - navigate={~p"/orgs/#{@current_organization.slug}/devices/new"} + navigate={~p"/devices/new"} variant="primary" > <.icon name="hero-plus" class="h-5 w-5" /> New Device @@ -35,7 +35,7 @@ Sites help you organize your devices by physical location.

- <.button navigate={~p"/orgs/#{@current_organization.slug}/sites/new"} variant="primary"> + <.button navigate={~p"/sites/new"} variant="primary"> <.icon name="hero-plus" class="h-5 w-5" /> Create Your First Site
@@ -50,7 +50,7 @@

<.button - navigate={~p"/orgs/#{@current_organization.slug}/devices/new"} + navigate={~p"/devices/new"} variant="primary" > <.icon name="hero-plus" class="h-5 w-5" /> New Device @@ -63,7 +63,7 @@ rows={@device} row_click={ fn eq -> - JS.navigate(~p"/orgs/#{@current_organization.slug}/devices/#{eq.id}") + JS.navigate(~p"/devices/#{eq.id}") end } > @@ -75,7 +75,7 @@ <:col :let={eq} label="Site"> <.link - navigate={~p"/orgs/#{@current_organization.slug}/sites/#{eq.site.id}"} + navigate={~p"/sites/#{eq.site.id}"} class="text-blue-600 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300" > {eq.site.name} diff --git a/lib/towerops_web/live/device_live/show.html.heex b/lib/towerops_web/live/device_live/show.html.heex index 8191f67e..ec2d0c62 100644 --- a/lib/towerops_web/live/device_live/show.html.heex +++ b/lib/towerops_web/live/device_live/show.html.heex @@ -11,7 +11,7 @@
  1. <.link - navigate={~p"/orgs/#{@current_organization.slug}/sites/#{@device.site.id}"} + navigate={~p"/sites/#{@device.site.id}"} class="hover:text-zinc-900 dark:hover:text-zinc-200" > {@device.site.name} @@ -32,7 +32,7 @@

    {@device.ip_address}

- <.button navigate={~p"/orgs/#{@current_organization.slug}/devices/#{@device.id}/edit"}> + <.button navigate={~p"/devices/#{@device.id}/edit"}> <.icon name="hero-pencil" class="h-4 w-4" /> Edit
@@ -41,7 +41,7 @@