Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Don't crash audit browser with weak user association missing (#5589)
Adam Rutkowski01e801942e3c
diff --git a/extra/lib/plausible_web/live/customer_support/live/team.ex b/extra/lib/plausible_web/live/customer_support/live/team.exindex 8ebc4a50bc..20a2b422e8 100644--- a/extra/lib/plausible_web/live/customer_support/live/team.ex+++ b/extra/lib/plausible_web/live/customer_support/live/team.ex@@ -52,7 +52,7 @@ defmodule PlausibleWeb.CustomerSupport.Live.Team dometa =if entry.user_id && entry.user_id > 0 do- user = Plausible.Repo.get!(Plausible.Auth.User, entry.user_id)+ user = Plausible.Repo.get(Plausible.Auth.User, entry.user_id)Map.put(meta, :user, user)elsemeta@@ -60,7 +60,7 @@ defmodule PlausibleWeb.CustomerSupport.Live.Team dometa =if entry.entity == "Plausible.Auth.User" do- user = Plausible.Repo.get!(Plausible.Auth.User, String.to_integer(entry.entity_id))+ user = Plausible.Repo.get(Plausible.Auth.User, String.to_integer(entry.entity_id))Map.put(meta, :entity, user)elsemeta@@ -1229,6 +1229,12 @@ defmodule PlausibleWeb.CustomerSupport.Live.Team doattr :user, Plausible.Auth.User+ defp audit_user(%{user: nil} = assigns) do+ ~H"""+ (N/A)+ """+ end+defp audit_user(assigns) do~H"""<div class="flex items-center gap-x-1">diff --git a/test/plausible_web/live/customer_support/teams_test.exs b/test/plausible_web/live/customer_support/teams_test.exsindex 866ebf2916..26119cc7e8 100644--- a/test/plausible_web/live/customer_support/teams_test.exs+++ b/test/plausible_web/live/customer_support/teams_test.exs@@ -658,6 +658,27 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest doassert text_of_element(html, ~s|textarea|) =="{ &quot;foo&quot;: &quot;bar&quot; }"end++ test "shows audit entries when user id does not exists", %{conn: conn, user: user} do+ team = team_of(user)++ %Plausible.Audit.Entry{+ name: "Reveal Test",+ entity: "Plausible.Auth.User",+ entity_id: "666111",+ team_id: team.id,+ datetime: NaiveDateTime.utc_now(),+ user_id: 666_111,+ actor_type: :user+ }+ |> Plausible.Repo.insert!()++ {:ok, lv, _html} = live(conn, open_team(team.id, tab: :audit))++ text = lv |> render() |> text()++ assert text =~ "(N/A) (N/A)"+ endendendend