From 1ef286ac55a3dcd060db6d5e8b16e7a22bb34032 Mon Sep 17 00:00:00 2001 From: Brian Manifold Date: Mon, 18 Nov 2024 13:52:23 -0500 Subject: [PATCH] fix(portal): API clients 'show' page should always be in settings (#7371) Why: * The portal currently shows API clients in the Actors index list. Each Actor in the list has a link to their own 'show' page. Prior to this commit, selecting an API client from the list would result an error. While API clients are technically an Actor, they aren't quite the same as all other Actors because they are only used to configure the portal for a given account. Because of this, they don't have the same information to show as all other Actors. This commit sets the 'show' URL for API clients to the 'settings' page to show the proper info for the API client. Fixes: #7370 --- .../web/lib/web/live/actors/components.ex | 13 +++++++++++- .../web/test/web/live/actors/index_test.exs | 21 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/elixir/apps/web/lib/web/live/actors/components.ex b/elixir/apps/web/lib/web/live/actors/components.ex index f74ea31fc..04931e4d1 100644 --- a/elixir/apps/web/lib/web/live/actors/components.ex +++ b/elixir/apps/web/lib/web/live/actors/components.ex @@ -45,7 +45,7 @@ defmodule Web.Actors.Components do def actor_name_and_role(assigns) do ~H""" <.link - navigate={~p"/#{@account}/actors/#{@actor}"} + navigate={actor_show_url(@account, @actor)} class={["text-accent-500 hover:underline", @class]} > <%= @actor.name %> @@ -56,6 +56,9 @@ defmodule Web.Actors.Components do (service account) + + (api client) + """ end @@ -190,4 +193,12 @@ defmodule Web.Actors.Components do def next_step_path(_other, account) do ~p"/#{account}/actors/users/new" end + + def actor_show_url(account, %Domain.Actors.Actor{type: :api_client} = actor) do + ~p"/#{account}/settings/api_clients/#{actor}" + end + + def actor_show_url(account, actor) do + ~p"/#{account}/actors/#{actor}" + end end diff --git a/elixir/apps/web/test/web/live/actors/index_test.exs b/elixir/apps/web/test/web/live/actors/index_test.exs index 75b4574db..839aaf288 100644 --- a/elixir/apps/web/test/web/live/actors/index_test.exs +++ b/elixir/apps/web/test/web/live/actors/index_test.exs @@ -144,4 +144,25 @@ defmodule Web.Live.Actors.IndexTest do assert String.contains?(row["last signed in"], "1 hour ago") end) end + + test "renders proper URL for API client 'show' page", %{ + account: account, + identity: identity, + conn: conn + } do + api_client = Fixtures.Actors.create_actor(type: :api_client, account: account) + + {:ok, lv, _html} = + conn + |> authorize_conn(identity) + |> live(~p"/#{account}/actors") + + items = + lv + |> element("#actors") + |> render() + |> Floki.find("a[href*=\"api_clients/#{api_client.id}\"]") + + assert length(items) == 1 + end end