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
Only display "Invoices" on sidebar when subscription is present (#5634)
Adam Rutkowskic0abbe643274
diff --git a/lib/plausible_web/views/layout_view.ex b/lib/plausible_web/views/layout_view.exindex fcbc12ba65..ff1fdbbba4 100644--- a/lib/plausible_web/views/layout_view.ex+++ b/lib/plausible_web/views/layout_view.ex@@ -85,6 +85,9 @@ defmodule PlausibleWeb.LayoutView docurrent_team = conn.assigns[:current_team]current_team_role = conn.assigns[:current_team_role]+ # NOTE: Subscription will still exist if it has expired or cancelled+ subscription? = !!(conn.assigns[:current_team] && conn.assigns.current_team.subscription)+options = %{"Account Settings" =>[@@ -93,7 +96,7 @@ defmodule PlausibleWeb.LayoutView doif(not Teams.setup?(current_team),do: %{key: "Subscription", value: "billing/subscription", icon: :circle_stack}),- if(not Teams.setup?(current_team),+ if(not Teams.setup?(current_team) and subscription?,do: %{key: "Invoices", value: "billing/invoices", icon: :banknotes}),if(not Teams.setup?(current_team),@@ -115,7 +118,7 @@ defmodule PlausibleWeb.LayoutView doif(current_team_role in [:owner, :billing],do: %{key: "Subscription", value: "billing/subscription", icon: :circle_stack}),- if(current_team_role in [:owner, :billing],+ if(current_team_role in [:owner, :billing] and subscription?,do: %{key: "Invoices", value: "billing/invoices", icon: :banknotes}),if(current_team_role in [:owner, :billing, :admin, :editor],diff --git a/test/plausible_web/controllers/settings_controller_test.exs b/test/plausible_web/controllers/settings_controller_test.exsindex f9e7832e7a..b9f2f4630d 100644--- a/test/plausible_web/controllers/settings_controller_test.exs+++ b/test/plausible_web/controllers/settings_controller_test.exs@@ -1374,6 +1374,48 @@ defmodule PlausibleWeb.SettingsControllerTest dorefute html =~ "Team Settings"end+ test "does not render invoices when no subscription present (no team assigned)", %{conn: conn} do+ conn = get(conn, Routes.settings_path(conn, :preferences))+ html = html_response(conn, 200)+ refute html =~ Routes.settings_path(conn, :invoices)+ end++ test "does render invoices when subscription present (no team assigned)", %{+ conn: conn,+ user: user+ } do+ subscribe_to_growth_plan(user)+ conn = get(conn, Routes.settings_path(conn, :preferences))+ html = html_response(conn, 200)+ assert html =~ Routes.settings_path(conn, :invoices)+ end++ test "does not render invoices when no subscription (team set up)", %{+ conn: conn,+ user: user+ } do+ {:ok, team} = Plausible.Teams.get_or_create(user)+ team = Plausible.Teams.complete_setup(team)+ conn = set_current_team(conn, team)+ conn = get(conn, Routes.settings_path(conn, :preferences))+ html = html_response(conn, 200)+ refute html =~ Routes.settings_path(conn, :invoices)+ end++ test "does render invoices when subscription present (team assigned)", %{+ conn: conn,+ user: user+ } do+ subscribe_to_growth_plan(user)+ {:ok, team} = Plausible.Teams.get_or_create(user)+ team = Plausible.Teams.complete_setup(team)+ conn = set_current_team(conn, team)++ conn = get(conn, Routes.settings_path(conn, :preferences))+ html = html_response(conn, 200)+ assert html =~ Routes.settings_path(conn, :invoices)+ end+test "renders team settings, when team assigned and set up", %{conn: conn, user: user} do{:ok, team} = Plausible.Teams.get_or_create(user)team = Plausible.Teams.complete_setup(team)