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 when a super-admin is trying to render feature gate (#6016)
Adam Rutkowskiffccd7b65eda
diff --git a/lib/plausible_web/components/billing/billing.ex b/lib/plausible_web/components/billing/billing.exindex a55c80d193..83e4732719 100644--- a/lib/plausible_web/components/billing/billing.ex+++ b/lib/plausible_web/components/billing/billing.ex@@ -363,16 +363,21 @@ defmodule PlausibleWeb.Components.Billing doteam = Plausible.Teams.with_subscription(assigns.current_team)current_role =- if site do- case Plausible.Teams.Memberships.site_role(site, user) do- {:ok, {_, site_role}} -> site_role- _ -> nil- end- else- if team do- {:ok, team_role} = Plausible.Teams.Memberships.team_role(team, user)- team_role- end+ cond do+ not is_nil(site) ->+ case Plausible.Teams.Memberships.site_role(site, user) do+ {:ok, {_, site_role}} -> site_role+ _ -> nil+ end++ not is_nil(team) ->+ case Plausible.Teams.Memberships.team_role(team, user) do+ {:ok, team_role} -> team_role+ _ -> nil+ end++ true ->+ nilendupgrade_assistance_required? =diff --git a/test/plausible_web/components/billing/billing_test.exs b/test/plausible_web/components/billing/billing_test.exsindex bde06ff23e..e201ca53ec 100644--- a/test/plausible_web/components/billing/billing_test.exs+++ b/test/plausible_web/components/billing/billing_test.exs@@ -91,6 +91,24 @@ defmodule PlausibleWeb.Components.BillingTest doassert text_of_element(html, "#lock-notice") =~ "ask your team owner"end++ test "renders upgrade cta linking to the upgrade page when user is not a team member (e.g. super-admin)",+ %{+ user: user+ } do+ team = user |> subscribe_to_growth_plan() |> team_of()+ other_user = new_user()++ html =+ %{+ current_user: other_user,+ current_team: team,+ locked?: true+ }+ |> render_feature_gate()++ assert text_of_element(html, "#lock-notice") =~ "upgrade your subscription"+ endenddefp render_feature_gate(assigns) do