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
Fix upgrade notices so admins get "ask a team owner" message (#6750)
Adam0ea0cb3f6d6f
diff --git a/.github/workflows/all-checks-pass.yml b/.github/workflows/all-checks-pass.ymlindex 9f8230a37d..1a0b41ec02 100644--- a/.github/workflows/all-checks-pass.yml+++ b/.github/workflows/all-checks-pass.yml@@ -14,5 +14,5 @@ jobs:uses: poseidon/wait-for-status-checks@e7e24423722c5b8e97a6dd5848827d2a412f812d # v0.7.0with:token: ${{ secrets.GITHUB_TOKEN }}- ignore: merge-sharded-e2e-test-report+ ignore: merge-sharded-e2e-test-report,copilotinterval: 6diff --git a/lib/plausible_web/components/billing/notice.ex b/lib/plausible_web/components/billing/notice.exindex be884ac8bf..7943a02cb9 100644--- a/lib/plausible_web/components/billing/notice.ex+++ b/lib/plausible_web/components/billing/notice.ex@@ -3,47 +3,28 @@ defmodule PlausibleWeb.Components.Billing.Notice douse PlausibleWeb, :component+ require Plausible.Billingrequire Plausible.Billing.Subscription.Statusalias Plausible.Billing.{Subscription, Plans, Subscriptions}+ attr(:current_team_role, :atom, required: true)+def active_grace_period(assigns) do- if assigns.enterprise? do- ~H"""- <aside class="container">- <.notice- title={Plausible.Billing.active_grace_period_notice_title()}- class="shadow-md dark:shadow-none"- >- To keep your stats running smoothly, it’s time to upgrade your subscription to match your growing usage.- <.link- href={~p"/billing/choose-plan"}- class="whitespace-nowrap font-semibold"- >- Upgrade now <span aria-hidden="true"> →</span>- </.link>- </.notice>- </aside>- """- else- ~H"""- <aside class="container">- <.notice- title={Plausible.Billing.active_grace_period_notice_title()}- class="shadow-md dark:shadow-none"- >- To keep your stats running smoothly, it’s time to upgrade your subscription to match your growing usage.- <.link- href={~p"/billing/choose-plan"}- class="whitespace-nowrap font-semibold"- >- Upgrade now <span aria-hidden="true"> →</span>- </.link>- </.notice>- </aside>- """- end+ ~H"""+ <aside class="container">+ <.notice+ title={Plausible.Billing.active_grace_period_notice_title()}+ class="shadow-md dark:shadow-none"+ >+ To keep your stats running smoothly, it’s time to upgrade your subscription to match your growing usage.+ <.upgrade_link_or_owner_hint current_team_role={@current_team_role} />+ </.notice>+ </aside>+ """end+ attr(:current_team_role, :atom, required: true)+def dashboard_locked(assigns) do~H"""<aside class="container">@@ -52,17 +33,34 @@ defmodule PlausibleWeb.Components.Billing.Notice doclass="shadow-md dark:shadow-none">Since you’ve outgrown your current subscription tier, it’s time to upgrade to match your growing usage.- <.link- href={~p"/billing/choose-plan"}- class="whitespace-nowrap font-semibold"- >- Upgrade now <span aria-hidden="true"> →</span>- </.link>+ <.upgrade_link_or_owner_hint current_team_role={@current_team_role} /></.notice></aside>"""end+ defp upgrade_link_or_owner_hint(assigns) do+ assigns =+ assign(+ assigns,+ :can_upgrade?,+ assigns.current_team_role in Plausible.Billing.allowed_roles()+ )++ ~H"""+ <.link+ :if={@can_upgrade?}+ href={~p"/billing/choose-plan"}+ class="whitespace-nowrap font-semibold"+ >+ Upgrade now <span aria-hidden="true"> →</span>+ </.link>+ <span :if={!@can_upgrade?} class="font-semibold" data-test="owner-upgrade-hint">+ Please ask a team owner to upgrade the subscription.+ </span>+ """+ end+attr(:current_team, :any, required: true)attr(:current_user, :atom, required: true)attr(:limit, :integer, required: true)diff --git a/lib/plausible_web/components/layouts.ex b/lib/plausible_web/components/layouts.exindex 8dbe07e616..5a2604508e 100644--- a/lib/plausible_web/components/layouts.ex+++ b/lib/plausible_web/components/layouts.ex@@ -42,7 +42,11 @@ defmodule PlausibleWeb.Layouts domy_team={@my_team}/>- <.team_notices :if={@global_notices?} current_team={@current_team} />+ <.team_notices+ :if={@global_notices?}+ current_team={@current_team}+ current_team_role={@current_team_role}+ /><% end %><main class="flex-1 flex flex-col">diff --git a/lib/plausible_web/components/layouts/team_notices.html.heex b/lib/plausible_web/components/layouts/team_notices.html.heexindex 3c5f0275a0..10f46e61b7 100644--- a/lib/plausible_web/components/layouts/team_notices.html.heex+++ b/lib/plausible_web/components/layouts/team_notices.html.heex@@ -1,10 +1,13 @@<div :if={assigns[:current_team]} class="flex flex-col gap-y-2"><Notice.active_grace_period:if={Plausible.Teams.GracePeriod.active?(@current_team)}- enterprise?={Plausible.Teams.Billing.enterprise_configured?(@current_team)}+ current_team_role={@current_team_role}/>- <Notice.dashboard_locked :if={Plausible.Teams.GracePeriod.expired?(@current_team)} />+ <Notice.dashboard_locked+ :if={Plausible.Teams.GracePeriod.expired?(@current_team)}+ current_team_role={@current_team_role}+ /><Notice.subscription_cancelled subscription={@current_team.subscription} />diff --git a/test/plausible_web/components/billing/notice_test.exs b/test/plausible_web/components/billing/notice_test.exsindex a0976607b8..adf1c319d1 100644--- a/test/plausible_web/components/billing/notice_test.exs+++ b/test/plausible_web/components/billing/notice_test.exs@@ -3,6 +3,35 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest doimport Phoenix.LiveViewTest, only: [render_component: 2]alias PlausibleWeb.Components.Billing.Notice+ require Plausible.Billing++ describe "global upgrade notices" do+ for {fun, title} <- [+ {:active_grace_period, "grace period"},+ {:dashboard_locked, "locked dashboard"}+ ] do+ test "#{fun}/1 links owners and billing members to the plan flow (#{title})" do+ for role <- Plausible.Billing.allowed_roles() do+ rendered = render_component(&(Notice.unquote(fun) / 1), current_team_role: role)++ assert rendered =~ "Upgrade now"+ assert rendered =~ "/billing/choose-plan"+ refute rendered =~ "ask a team owner"+ end+ end++ test "#{fun}/1 tells admins and other members to ask an owner (#{title})" do+ for role <- Plausible.Teams.Membership.roles() -- Plausible.Billing.allowed_roles() do+ rendered = render_component(&(Notice.unquote(fun) / 1), current_team_role: role)++ assert rendered =~ "ask a team owner to upgrade the subscription"+ refute rendered =~ "Upgrade now"+ refute rendered =~ "/billing/choose-plan"+ end+ end+ end+ end+test "limit_exceeded/1 when user is on growth displays upgrade link" douser = new_user() |> subscribe_to_growth_plan()team = team_of(user)