Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Business tier bug smash (#3493)

RobertJoonas7036332db27e
diff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.ex
index c9c751856a..e4d1089d11 100644
--- a/lib/plausible/billing/billing.ex
+++ b/lib/plausible/billing/billing.ex
@@ -3,6 +3,11 @@ defmodule Plausible.Billing do
require Plausible.Billing.Subscription.Status
alias Plausible.Billing.{Subscription, Plans, Quota}
+ def upgrade_route_for(user) do
+ action = if FunWithFlags.enabled?(:business_tier, for: user), do: :choose_plan, else: :upgrade
+ PlausibleWeb.Router.Helpers.billing_path(PlausibleWeb.Endpoint, action)
+ end
+
@spec active_subscription_for(integer()) :: Subscription.t() | nil
def active_subscription_for(user_id) do
user_id |> active_subscription_query() |> Repo.one()
diff --git a/lib/plausible/billing/feature.ex b/lib/plausible/billing/feature.ex
index 211039286a..4d55cb17b5 100644
--- a/lib/plausible/billing/feature.ex
+++ b/lib/plausible/billing/feature.ex
@@ -124,6 +124,8 @@ defmodule Plausible.Billing.Feature do
{:error, :upgrade_required} -> {:error, :upgrade_required}
end
end
+
+ defoverridable check_availability: 1
end
end
end
@@ -165,4 +167,27 @@ defmodule Plausible.Billing.Feature.StatsAPI do
use Plausible.Billing.Feature,
name: :stats_api,
display_name: "Stats API"
+
+ @impl true
+ @doc """
+ Checks whether the user has access to Stats API or not.
+
+ Before the the business tier, users who had not yet started their trial had
+ access to Stats API. With the business tier work, access is blocked and they
+ must either start their trial or subscribe to a plan. This is common when a
+ site owner invites a new user. In such cases, using the owner's API key is
+ recommended.
+ """
+ def check_availability(%Plausible.Auth.User{} = user) do
+ unlimited_trial? = is_nil(user.trial_expiry_date)
+
+ pre_business_tier_account? =
+ Timex.before?(user.inserted_at, Plausible.Billing.Plans.business_tier_launch())
+
+ cond do
+ unlimited_trial? && pre_business_tier_account? -> :ok
+ unlimited_trial? && !pre_business_tier_account? -> {:error, :upgrade_required}
+ true -> super(user)
+ end
+ end
end
diff --git a/lib/plausible/billing/subscriptions.ex b/lib/plausible/billing/subscriptions.ex
index 6c0bc98254..13cfc4d611 100644
--- a/lib/plausible/billing/subscriptions.ex
+++ b/lib/plausible/billing/subscriptions.ex
@@ -30,4 +30,13 @@ defmodule Plausible.Billing.Subscriptions do
Subscription.Status.paused()
]
end
+
+ def halted?(nil), do: false
+
+ def halted?(%Subscription{status: status}) do
+ status in [
+ Subscription.Status.past_due(),
+ Subscription.Status.paused()
+ ]
+ end
end
diff --git a/lib/plausible_web/components/billing.ex b/lib/plausible_web/components/billing.ex
index ee3a385d48..f980038b47 100644
--- a/lib/plausible_web/components/billing.ex
+++ b/lib/plausible_web/components/billing.ex
@@ -5,7 +5,7 @@ defmodule PlausibleWeb.Components.Billing do
import PlausibleWeb.Components.Generic
require Plausible.Billing.Subscription.Status
alias PlausibleWeb.Router.Helpers, as: Routes
- alias Plausible.{Billing.Subscription, Billing.Plans}
+ alias Plausible.Billing.{Subscription, Plans, Subscriptions}
attr(:billable_user, Plausible.Auth.User, required: true)
attr(:current_user, Plausible.Auth.User, required: true)
@@ -40,7 +40,7 @@ defmodule PlausibleWeb.Components.Billing do
not has_access? && display_upgrade_link? ->
~H"""
<%= @feature_mod.display_name() %> is part of the Plausible Business plan. To get access to it, please
- <.link class="underline" href={Routes.billing_path(PlausibleWeb.Endpoint, :upgrade)}>
+ <.link class="underline inline-block" href={Plausible.Billing.upgrade_route_for(@current_user)}>
upgrade your subscription
</.link> to the Business plan.
"""
@@ -61,6 +61,50 @@ defmodule PlausibleWeb.Components.Billing do
"""
end
+ attr(:billable_user, Plausible.Auth.User, required: true)
+ attr(:current_user, Plausible.Auth.User, required: true)
+ attr(:limit, :integer, required: true)
+ attr(:resource, :string, required: true)
+ attr(:rest, :global)
+
+ # credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity
+ def limit_exceeded_notice(assigns) do
+ billable_user = Plausible.Users.with_subscription(assigns.billable_user)
+
+ plan =
+ Plausible.Billing.Plans.get_regular_plan(billable_user.subscription, only_non_expired: true)
+
+ trial? = Plausible.Billing.on_trial?(assigns.billable_user)
+ growth? = plan && plan.kind == :growth
+
+ display_upgrade_link? = assigns.current_user.id == assigns.billable_user.id
+
+ message =
+ cond do
+ !display_upgrade_link? ->
+ "This account is limited to #{assigns.limit} #{assigns.resource}. To increase this limit, please reach out to the site owner to upgrade their subscription"
+
+ growth? || trial? ->
+ ~H"""
+ Your account is limited to <%= @limit %> <%= @resource %>. To increase this limit, please
+ <.link class="underline inline-block" href={Plausible.Billing.upgrade_route_for(@current_user)}>
+ upgrade your subscription
+ </.link> to the Business plan.
+ """
+
+ true ->
+ "Your account is limited to #{assigns.limit} #{assigns.resource}. To increase this limit, please contact [email protected] about the Enterprise plan"
+ end
+
+ assigns = assign(assigns, :message, message)
+
+ ~H"""
+ <.notice :if={@message} {@rest}>
+ <%= @message %>
+ </.notice>
+ """
+ end
+
defp private_preview_days_remaining do
private_preview_ends_at = Timex.shift(Plausible.Billing.Plans.business_tier_launch(), days: 7)
@@ -126,9 +170,11 @@ defmodule PlausibleWeb.Components.Billing do
<%= PlausibleWeb.AuthView.subscription_quota(@subscription, format: :long) %>
</div>
<.styled_link
- :if={show_upgrade_or_change_plan_link?(@user, @subscription)}
+ :if={
+ not (Plausible.Auth.enterprise_configured?(@user) && Subscriptions.halted?(@subscription))
+ }
id="#upgrade-or-change-plan-link"
- href={upgrade_link_href(@user)}
+ href={Routes.billing_path(PlausibleWeb.Endpoint, :choose_plan)}
class="text-sm font-medium"
>
<%= change_plan_or_upgrade_text(@subscription) %>
@@ -285,16 +331,9 @@ defmodule PlausibleWeb.Components.Billing do
|> PlausibleWeb.StatsView.large_number_format()
end
- @spec format_price(Money.t(), Keyword.t()) :: String.t()
- def format_price(money, opts \\ []) do
- opts =
- opts
- |> Keyword.put_new(:format, :short)
- |> Keyword.put_new(:fractional_digits, 2)
-
- money
- |> Money.to_string!(opts)
- |> String.replace(".00", "")
+ @spec format_price(Money.t()) :: String.t()
+ def format_price(money) do
+ Money.to_string!(money, fractional_digits: 2, no_fraction_if_integer: true)
end
attr :id, :string, required: true
@@ -340,7 +379,10 @@ defmodule PlausibleWeb.Components.Billing do
def upgrade_link(%{business_tier: true} = assigns) do
~H"""
- <PlausibleWeb.Components.Generic.button_link id="upgrade-link-2" href={upgrade_link_href(@user)}>
+ <PlausibleWeb.Components.Generic.button_link
+ id="upgrade-link-2"
+ href={Routes.billing_path(PlausibleWeb.Endpoint, :choose_plan)}
+ >
Upgrade
</PlausibleWeb.Components.Generic.button_link>
"""
@@ -356,29 +398,10 @@ defmodule PlausibleWeb.Components.Billing do
"""
end
- defp upgrade_link_href(user) do
- action =
- if Plausible.Auth.enterprise_configured?(user),
- do: :upgrade_to_enterprise_plan,
- else: :choose_plan
-
- Routes.billing_path(PlausibleWeb.Endpoint, action)
- end
-
defp change_plan_or_upgrade_text(nil), do: "Upgrade"
defp change_plan_or_upgrade_text(%Subscription{status: Subscription.Status.deleted()}),
do: "Upgrade"
defp change_plan_or_upgrade_text(_subscription), do: "Change plan"
-
- defp show_upgrade_or_change_plan_link?(user, subscription) do
- is_enterprise? = Plausible.Auth.enterprise_configured?(user)
-
- subscription_halted? =
- subscription &&
- subscription.status in [Subscription.Status.past_due(), Subscription.Status.paused()]
-
- !(is_enterprise? && subscription_halted?)
- end
end
diff --git a/lib/plausible_web/controllers/billing_controller.ex b/lib/plausible_web/controllers/billing_controller.ex
index 3015a25a61..cc7bf0b501 100644
--- a/lib/plausible_web/controllers/billing_controller.ex
+++ b/lib/plausible_web/controllers/billing_controller.ex
@@ -20,6 +20,9 @@ defmodule PlausibleWeb.BillingController do
Plausible.Auth.enterprise_configured?(user) ->
redirect(conn, to: Routes.billing_path(conn, :upgrade_to_enterprise_plan))
+ FunWithFlags.enabled?(:business_tier, for: user) ->
+ redirect(conn, to: Routes.billing_path(conn, :choose_plan))
+
user.subscription && user.subscription.status == Subscription.Status.active() ->
redirect(conn, to: Routes.billing_path(conn, :change_plan_form))
@@ -37,14 +40,21 @@ defmodule PlausibleWeb.BillingController do
user = conn.assigns.current_user
if FunWithFlags.enabled?(:business_tier, for: user) do
- render(conn, "choose_plan.html",
- skip_plausible_tracking: true,
- user: user,
- layout: {PlausibleWeb.LayoutView, "focus.html"},
- connect_live_socket: true
- )
+ if Plausible.Auth.enterprise_configured?(user) do
+ redirect(conn, to: Routes.billing_path(conn, :upgrade_to_enterprise_plan))
+ else
+ render(conn, "choose_plan.html",
+ skip_plausible_tracking: true,
+ user: user,
+ layout: {PlausibleWeb.LayoutView, "focus.html"},
+ connect_live_socket: true
+ )
+ end
else
- render_error(conn, 404)
+ # This will be needed in case we need to flip back the flag.
+ # With the :business_tier flag enabled we'll have sent emails
+ # linking to `/billing/choose-plan`.
+ redirect(conn, to: Routes.billing_path(conn, :upgrade))
end
end
@@ -102,6 +112,9 @@ defmodule PlausibleWeb.BillingController do
subscription = Billing.active_subscription_for(user.id)
cond do
+ FunWithFlags.enabled?(:business_tier, for: user) ->
+ render_error(conn, 404)
+
Plausible.Auth.enterprise_configured?(user) ->
redirect(conn, to: Routes.billing_path(conn, :upgrade_to_enterprise_plan))
@@ -139,8 +152,6 @@ defmodule PlausibleWeb.BillingController do
)
else
_ ->
- redirect_to = if business_tier_enabled?, do: :choose_plan, else: :upgrade
-
msg =
"Something went wrong with loading your plan change information. Please try again, or contact us at [email protected] if the issue persists."
@@ -154,7 +165,7 @@ defmodule PlausibleWeb.BillingController do
conn
|> put_flash(:error, msg)
- |> redirect(to: Routes.billing_path(conn, redirect_to))
+ |> redirect(to: Plausible.Billing.upgrade_route_for(user))
end
end
diff --git a/lib/plausible_web/controllers/site/membership_controller.ex b/lib/plausible_web/controllers/site/membership_controller.ex
index 2d0001a11f..bdf34dba05 100644
--- a/lib/plausible_web/controllers/site/membership_controller.ex
+++ b/lib/plausible_web/controllers/site/membership_controller.ex
@@ -24,13 +24,22 @@ defmodule PlausibleWeb.Site.MembershipController do
[:owner, :admin] when action not in @only_owner_is_allowed_to
def invite_member_form(conn, _params) do
- site = Sites.get_for_user!(conn.assigns[:current_user].id, conn.assigns[:site].domain)
+ site =
+ conn.assigns.current_user.id
+ |> Sites.get_for_user!(conn.assigns.site.domain)
+ |> Plausible.Repo.preload(:owner)
+
+ limit = Plausible.Billing.Quota.team_member_limit(site.owner)
+ usage = Plausible.Billing.Quota.team_member_limit(site.owner)
+ below_limit? = Plausible.Billing.Quota.below_limit?(usage, limit)
render(
conn,
"invite_member_form.html",
site: site,
layout: {PlausibleWeb.LayoutView, "focus.html"},
+ team_member_limit: limit,
+ is_at_limit: not below_limit?,
skip_plausible_tracking: true
)
end
diff --git a/lib/plausible_web/live/choose_plan.ex b/lib/plausible_web/live/choose_plan.ex
index 2dfaaacb66..08e22197d0 100644
--- a/lib/plausible_web/live/choose_plan.ex
+++ b/lib/plausible_web/live/choose_plan.ex
@@ -708,6 +708,7 @@ defmodule PlausibleWeb.Live.ChoosePlan do
"Everything in Business",
team_members,
"50+ sites",
+ "600+ Stats API requests per hour",
&sites_api_benefit/1,
"Technical onboarding"
]
@@ -727,6 +728,7 @@ defmodule PlausibleWeb.Live.ChoosePlan do
Enum.map(plan.features, fn feature_mod ->
case feature_mod.name() do
:goals -> "Goals and custom events"
+ :stats_api -> "Stats API (600 requests per hour)"
:revenue_goals -> "Ecommerce revenue attribution"
_ -> feature_mod.display_name()
end
diff --git a/lib/plausible_web/live/goal_settings/form.ex b/lib/plausible_web/live/goal_settings/form.ex
index 4229505c58..93e5e7e0a8 100644
--- a/lib/plausible_web/live/goal_settings/form.ex
+++ b/lib/plausible_web/live/goal_settings/form.ex
@@ -152,6 +152,13 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do
})
}
>
+ <PlausibleWeb.Components.Billing.premium_feature_notice
+ billable_user={@site.owner}
+ current_user={@current_user}
+ feature_mod={Plausible.Billing.Feature.RevenueGoals}
+ size={:xs}
+ class="rounded-b-md"
+ />
<button
class={[
"flex items-center w-max mb-3",
@@ -191,16 +198,6 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do
</span>
</button>
- <span x-show="active">
- <PlausibleWeb.Components.Billing.premium_feature_notice
- billable_user={@site.owner}
- current_user={@current_user}
- feature_mod={Plausible.Billing.Feature.RevenueGoals}
- size={:xs}
- class="rounded-b-md"
- />
- </span>
-
<div x-show="active">
<.live_component
id="currency_input"
diff --git a/lib/plausible_web/templates/billing/upgrade_to_enterprise_plan.html.heex b/lib/plausible_web/templates/billing/upgrade_to_enterprise_plan.html.heex
index 4388a9127d..9649328ecd 100644
--- a/lib/plausible_web/templates/billing/upgrade_to_enterprise_plan.html.heex
+++ b/lib/plausible_web/templates/billing/upgrade_to_enterprise_plan.html.heex
@@ -22,11 +22,8 @@
The plan is priced at
<b>
<%= case @price do
- %Money{} = money ->
- PlausibleWeb.Components.Billing.format_price(money, format: :standard)
-
- nil ->
- "N/A"
+ %Money{} = money -> PlausibleWeb.Components.Billing.format_price(money)
+ nil -> "N/A"
end %>
</b>
</span>
diff --git a/lib/plausible_web/templates/email/trial_one_week_reminder.html.eex b/lib/plausible_web/templates/email/trial_one_week_reminder.html.eex
index 1b16bcfaf6..cd11129103 100644
--- a/lib/plausible_web/templates/email/trial_one_week_reminder.html.eex
+++ b/lib/plausible_web/templates/email/trial_one_week_reminder.html.eex
@@ -2,6 +2,6 @@ Time flies! Your 30-day free trial of Plausible will end next week.
<br /><br />
Over the last three weeks, We hope you got to experience the potential benefits of having website stats in an easy to use dashboard while respecting the privacy of your visitors, not annoying them with the cookie and privacy notices and still having a fast loading site.
<br /><br />
-In order to continue receiving valuable website traffic insights at a glance, you’ll need to <%= link("upgrade your account", to: "#{plausible_url()}/billing/upgrade") %>.
+In order to continue receiving valuable website traffic insights at a glance, you’ll need to <%= link("upgrade your account", to: plausible_url() <> Plausible.Billing.upgrade_route_for(@user)) %>.
<br /><br />
If you have any questions or feedback for us, feel free to reply to this email.
diff --git a/lib/plausible_web/templates/email/trial_over_email.html.eex b/lib/plausible_web/templates/email/trial_over_email.html.eex
index 7c8981b8f0..41766f8bf5 100644
--- a/lib/plausible_web/templates/email/trial_over_email.html.eex
+++ b/lib/plausible_web/templates/email/trial_over_email.html.eex
@@ -1,6 +1,6 @@
Your free Plausible trial has now expired. Upgrade your account to continue receiving valuable website traffic insights at a glance while respecting the privacy of your visitors and still having a fast loading site. <br /><br />
-<%= link("Upgrade now", to: "#{plausible_url()}/billing/upgrade") %>
+<%= link("Upgrade now", to: plausible_url() <> Plausible.Billing.upgrade_route_for(@user)) %>
<br /><br />
We will keep recording stats for another month to give you time to upgrade.
diff --git a/lib/plausible_web/templates/email/trial_upgrade_email.html.eex b/lib/plausible_web/templates/email/trial_upgrade_email.html.eex
index 3fc23add72..7d92bd8723 100644
--- a/lib/plausible_web/templates/email/trial_upgrade_email.html.eex
+++ b/lib/plausible_web/templates/email/trial_upgrade_email.html.eex
@@ -6,7 +6,7 @@ This is more than our standard plans, so please reply back to this email to get
<% else %>
Based on that we recommend you select a <%= @suggested_plan.volume %>/mo plan.
<br /><br />
-<%= link("Upgrade now", to: "#{plausible_url()}/billing/upgrade") %>
+<%= link("Upgrade now", to: plausible_url() <> Plausible.Billing.upgrade_route_for(@user)) %>
<br /><br />
Have a question, feedback or need some guidance? Just reply to this email to get in touch!
<% end %>
diff --git a/lib/plausible_web/templates/email/yearly_expiration_notification.html.eex b/lib/plausible_web/templates/email/yearly_expiration_notification.html.eex
index 6a4009c10f..2a85813f24 100644
--- a/lib/plausible_web/templates/email/yearly_expiration_notification.html.eex
+++ b/lib/plausible_web/templates/email/yearly_expiration_notification.html.eex
@@ -1,6 +1,6 @@
Time flies! This is a reminder that your annual subscription for Plausible Analytics will expire on <%= @date %>.
<br /><br />
-You need to renew your subscription on <%= link("account settings page", to: "#{plausible_url()}/billing/upgrade") %> if you want to continue using Plausible to count your website stats in a privacy-friendly way.
+You need to <%= link("renew your subscription", to: plausible_url() <> Plausible.Billing.upgrade_route_for(@user)) %> if you want to continue using Plausible to count your website stats in a privacy-friendly way.
<br /><br />
If you don't want to continue your subscription, there's no action required. You will lose access to the stats on <%= @date %>.
<br /><br />
diff --git a/lib/plausible_web/templates/site/membership/invite_member_form.html.eex b/lib/plausible_web/templates/site/membership/invite_member_form.html.eex
deleted file mode 100644
index 81467a65c2..0000000000
--- a/lib/plausible_web/templates/site/membership/invite_member_form.html.eex
+++ /dev/null
@@ -1,63 +0,0 @@
-<%= form_for @conn, Routes.membership_path(@conn, :invite_member, @site.domain), [class: "max-w-lg w-full mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 pt-6 pb-8 mb-4 mt-8"], fn f -> %>
- <h2 class="text-xl font-black dark:text-gray-100">Invite member to <%= @site.domain %></h2>
-
- <p class="mt-4 max-w-2xl text-sm text-gray-500 dark:text-gray-200">
- Enter the email address and role of the person you want to invite. We will contact them over email to offer them access to
- <%= @site.domain %> analytics.
- </p>
-
- <p class="mt-4 max-w-2xl text-sm text-gray-500 dark:text-gray-200">
- The invitation will expire in 48 hours
- </p>
-
- <%= if @conn.assigns[:error] do %>
- <div class="text-red-500 text-xs italic mt-4"><%= @conn.assigns[:error] %></div>
- <% end %>
-
- <div class="my-6">
- <%= label f, :email, "Email address", class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
- <div class="mt-1 relative rounded-md shadow-sm">
- <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
- <svg class="h-5 w-5 text-gray-500 dark:text-gray-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path d="M2.003 5.884L10 9.882l7.997-3.998A2 2 0 0016 4H4a2 2 0 00-1.997 1.884z" /><path d="M18 8.118l-8 4-8-4V14a2 2 0 002 2h12a2 2 0 002-2V8.118z" /></svg>
- </div>
- <%= email_input(f, :email, class: "focus:ring-indigo-500 focus:border-indigo-500 dark:bg-gray-900 dark:text-gray-300 block w-full rounded-md pl-10 sm:text-sm border-gray-300 dark:border-gray-500", placeholder: "[email protected]", required: "true") %>
- </div>
- <%= error_tag f, :email %>
- </div>
-
- <fieldset x-data="{selectedOption: null}">
- <%= label f, :role, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
- <div class="mt-1 bg-white rounded-md -space-y-px dark:bg-gray-800">
- <label class="border-gray-200 dark:border-gray-500 rounded-tl-md rounded-tr-md relative border p-4 flex cursor-pointer" :class="{'bg-indigo-50 border-indigo-200 dark:bg-indigo-500 dark:border-indigo-800 z-10': selectedOption === 'admin', 'border-gray-200': selectedOption !== 'admin'}">
- <%= radio_button(f, :role, "admin", class: "dark:bg-gray-900 h-4 w-4 mt-0.5 cursor-pointer text-indigo-600 border-gray-300 dark:border-gray-500 focus:ring-indigo-500", "x-model": "selectedOption", required: "true") %>
- <div class="ml-3 flex flex-col">
- <span class="text-gray-900 dark:text-gray-100 block text-sm font-medium" :class="{'text-indigo-900 dark:text-white': selectedOption === 'admin', 'text-gray-900 dark:text-gray-100': selectedOption !== 'admin'}">
- Admin
- </span>
- <span class="text-gray-500 dark:text-gray-200 block text-sm" :class="{'text-indigo-700 dark:text-gray-100': selectedOption === 'admin', 'text-gray-500 dark:text-gray-200': selectedOption !== 'admin'}">
- Can view stats, change site settings and invite other members
- </span>
- </div>
- </label>
-
- <label class="border-gray-200 dark:border-gray-500 rounded-bl-md rounded-br-md relative border p-4 flex cursor-pointer" :class="{'bg-indigo-50 border-indigo-200 dark:bg-indigo-500 dark:border-indigo-800 z-10': selectedOption === 'viewer', 'border-gray-200': selectedOption !== 'viewer'}">
- <%= radio_button(f, :role, "viewer", class: "dark:bg-gray-900 h-4 w-4 mt-0.5 cursor-pointer text-indigo-600 border-gray-300 dark:border-gray-500 focus:ring-indigo-500", "x-model": "selectedOption", required: "true") %>
- <div class="ml-3 flex flex-col">
- <span class="text-gray-900 dark:text-gray-100 block text-sm font-medium" :class="{'text-indigo-900 dark:text-white': selectedOption === 'viewer', 'text-gray-900 dark:text-gray-100': selectedOption !== 'viewer'}">
- Viewer
- </span>
- <span class="text-gray-500 dark:text-gray-200 block text-sm" :class="{'text-indigo-700 dark:text-gray-100': selectedOption === 'viewer', 'text-gray-500 dark:text-gray-200': selectedOption !== 'viewer'}">
- Can view stats but cannot access settings or invite members
- </span>
- </div>
- </label>
- </div>
- </fieldset>
-
- <div class="mt-6">
- <%= submit(class: "button w-full") do %>
- <svg class="w-5 h-5 mr-1" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M8 9a3 3 0 100-6 3 3 0 000 6zM8 11a6 6 0 016 6H2a6 6 0 016-6zM16 7a1 1 0 10-2 0v1h-1a1 1 0 100 2h1v1a1 1 0 102 0v-1h1a1 1 0 100-2h-1V7z"></path></svg>
- <span>Invite</span>
- <% end %>
- </div>
-<% end %>
diff --git a/lib/plausible_web/templates/site/membership/invite_member_form.html.heex b/lib/plausible_web/templates/site/membership/invite_member_form.html.heex
new file mode 100644
index 0000000000..96bb1568ed
--- /dev/null
+++ b/lib/plausible_web/templates/site/membership/invite_member_form.html.heex
@@ -0,0 +1,121 @@
+<%= form_for @conn, Routes.membership_path(@conn, :invite_member, @site.domain), [class: "max-w-lg w-full mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 pt-6 pb-8 mb-4 mt-8"], fn f -> %>
+ <h2 class="text-xl font-black dark:text-gray-100 mb-4">Invite member to <%= @site.domain %></h2>
+
+ <PlausibleWeb.Components.Billing.limit_exceeded_notice
+ :if={Map.get(assigns, :is_at_limit, false)}
+ current_user={@current_user}
+ billable_user={@site.owner}
+ limit={Map.get(assigns, :team_member_limit, 0)}
+ resource="team members"
+ />
+
+ <p class="mt-4 max-w-2xl text-sm text-gray-500 dark:text-gray-200">
+ Enter the email address and role of the person you want to invite. We will contact them over email to offer them access to <%= @site.domain %> analytics.
+ </p>
+
+ <p class="mt-4 max-w-2xl text-sm text-gray-500 dark:text-gray-200">
+ The invitation will expire in 48 hours
+ </p>
+
+ <%= if @conn.assigns[:error] do %>
+ <div class="text-red-500 text-xs italic mt-4"><%= @conn.assigns[:error] %></div>
+ <% end %>
+
+ <div class="my-6">
+ <%= label(f, :email, "Email address",
+ class: "block text-sm font-medium text-gray-700 dark:text-gray-300"
+ ) %>
+ <div class="mt-1 relative rounded-md shadow-sm">
+ <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
+ <svg
+ class="h-5 w-5 text-gray-500 dark:text-gray-400"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+ >
+ <path d="M2.003 5.884L10 9.882l7.997-3.998A2 2 0 0016 4H4a2 2 0 00-1.997 1.884z" /><path d="M18 8.118l-8 4-8-4V14a2 2 0 002 2h12a2 2 0 002-2V8.118z" />
+ </svg>
+ </div>
+ <%= email_input(f, :email,
+ class:
+ "focus:ring-indigo-500 focus:border-indigo-500 dark:bg-gray-900 dark:text-gray-300 block w-full rounded-md pl-10 sm:text-sm border-gray-300 dark:border-gray-500",
+ placeholder: "[email protected]",
+ required: "true"
+ ) %>
+ </div>
+ <%= error_tag(f, :email) %>
+ </div>
+
+ <fieldset x-data="{selectedOption: null}">
+ <%= label(f, :role, class: "block text-sm font-medium text-gray-700 dark:text-gray-300") %>
+ <div class="mt-1 bg-white rounded-md -space-y-px dark:bg-gray-800">
+ <label
+ class="border-gray-200 dark:border-gray-500 rounded-tl-md rounded-tr-md relative border p-4 flex cursor-pointer"
+ x-class="{'bg-indigo-50 border-indigo-200 dark:bg-indigo-500 dark:border-indigo-800 z-10': selectedOption === 'admin', 'border-gray-200': selectedOption !== 'admin'}"
+ >
+ <%= radio_button(f, :role, "admin",
+ class:
+ "dark:bg-gray-900 h-4 w-4 mt-0.5 cursor-pointer text-indigo-600 border-gray-300 dark:border-gray-500 focus:ring-indigo-500",
+ "x-model": "selectedOption",
+ required: "true"
+ ) %>
+ <div class="ml-3 flex flex-col">
+ <span
+ class="text-gray-900 dark:text-gray-100 block text-sm font-medium"
+ x-class="{'text-indigo-900 dark:text-white': selectedOption === 'admin', 'text-gray-900 dark:text-gray-100': selectedOption !== 'admin'}"
+ >
+ Admin
+ </span>
+ <span
+ class="text-gray-500 dark:text-gray-200 block text-sm"
+ x-class="{'text-indigo-700 dark:text-gray-100': selectedOption === 'admin', 'text-gray-500 dark:text-gray-200': selectedOption !== 'admin'}"
+ >
+ Can view stats, change site settings and invite other members
+ </span>
+ </div>
+ </label>
+
+ <label
+ class="border-gray-200 dark:border-gray-500 rounded-bl-md rounded-br-md relative border p-4 flex cursor-pointer"
+ x-class="{'bg-indigo-50 border-indigo-200 dark:bg-indigo-500 dark:border-indigo-800 z-10': selectedOption === 'viewer', 'border-gray-200': selectedOption !== 'viewer'}"
+ >
+ <%= radio_button(f, :role, "viewer",
+ class:
+ "dark:bg-gray-900 h-4 w-4 mt-0.5 cursor-pointer text-indigo-600 border-gray-300 dark:border-gray-500 focus:ring-indigo-500",
+ "x-model": "selectedOption",
+ required: "true"
+ ) %>
+ <div class="ml-3 flex flex-col">
+ <span
+ class="text-gray-900 dark:text-gray-100 block text-sm font-medium"
+ x-class="{'text-indigo-900 dark:text-white': selectedOption === 'viewer', 'text-gray-900 dark:text-gray-100': selectedOption !== 'viewer'}"
+ >
+ Viewer
+ </span>
+ <span
+ class="text-gray-500 dark:text-gray-200 block text-sm"
+ x-class="{'text-indigo-700 dark:text-gray-100': selectedOption === 'viewer', 'text-gray-500 dark:text-gray-200': selectedOption !== 'viewer'}"
+ >
+ Can view stats but cannot access settings or invite members
+ </span>
+ </div>
+ </label>
+ </div>
+ </fieldset>
+
+ <div class="mt-6">
+ <%= submit(class: "button w-full disabled:cursor-not-allowed", disabled: Map.get(assigns, :is_at_limit, false)) do %>
+ <svg
+ class="w-5 h-5 mr-1"
+ fill="currentColor"
+ viewBox="0 0 20 20"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path d="M8 9a3 3 0 100-6 3 3 0 000 6zM8 11a6 6 0 016 6H2a6 6 0 016-6zM16 7a1 1 0 10-2 0v1h-1a1 1 0 100 2h1v1a1 1 0 102 0v-1h1a1 1 0 100-2h-1V7z">
+ </path>
+ </svg>
+ <span>Invite</span>
+ <% end %>
+ </div>
+<% end %>
diff --git a/lib/plausible_web/templates/site/new.html.eex b/lib/plausible_web/templates/site/new.html.eex
deleted file mode 100644
index 14cf241f9e..0000000000
--- a/lib/plausible_web/templates/site/new.html.eex
+++ /dev/null
@@ -1,89 +0,0 @@
-<div class="w-full max-w-3xl mt-4 mx-auto flex">
- <%= form_for @changeset, "/sites", [class: "max-w-lg w-full mx-auto bg-white dark:bg-gray-800 shadow-lg rounded px-8 pt-6 pb-8 mb-4 mt-8"], fn f -> %>
- <h2 class="text-xl font-black dark:text-gray-100">Your website details</h2>
-
- <%= if @is_at_limit do %>
- <div class="rounded-md bg-yellow-50 dark:bg-transparent dark:border border-yellow-200 p-4 mt-4">
- <div class="flex">
- <div class="flex-shrink-0">
- <svg class="h-5 w-5 text-yellow-400 dark:text-yellow-300" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
- <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
- </svg>
- </div>
- <div class="ml-3">
- <h3 class="text-sm font-medium text-yellow-800 dark:text-yellow-400">
- Upgrade required
- </h3>
- <div class="mt-2 text-sm text-yellow-700 dark:text-yellow-300">
- <p>
- Your account is limited to <%= @site_limit %> sites. Please contact [email protected] to add more sites.
- </p>
- </div>
- </div>
- </div>
- </div>
- <% end %>
-
- <%= if is_nil(@current_user.trial_expiry_date) do %>
- <div class="rounded-md bg-blue-50 dark:bg-transparent dark:border border-blue-200 p-4 mt-4">
- <div class="flex">
- <div class="flex-shrink-0">
- <svg class="h-5 w-5 text-blue-500 dark:text-blue-300" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
- <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
- </svg>
- </div>
- <div class="ml-3">
- <div class="text-sm text-blue-700 dark:text-blue-300">
- <p>
- When you create your first site, your account will enter a 30 day free trial.
- </p>
- </div>
- </div>
- </div>
- </div>
- <% end %>
-
- <div class="my-6">
- <%= label f, :domain, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
- <p class="text-gray-500 dark:text-gray-400 text-xs mt-1">Just the naked domain or subdomain without 'www'</p>
- <div class="mt-2 flex rounded-md shadow-sm">
- <span class="inline-flex items-center px-3 rounded-l-md border border-r-0 border-gray-300 dark:border-gray-500 bg-gray-50 dark:bg-gray-850 text-gray-500 dark:text-gray-400 sm:text-sm">
- https://
- </span>
- <%= text_input f, :domain, class: "focus:ring-indigo-500 focus:border-indigo-500 dark:bg-gray-800 flex-1 block w-full px-3 py-2 rounded-none rounded-r-md sm:text-sm border-gray-300 dark:border-gray-500 dark:bg-gray-900 dark:text-gray-300", placeholder: "example.com", disabled: @is_at_limit %>
- </div>
- <%= error_tag f, :domain %>
- </div>
- <div class="my-6">
- <%= label f, :timezone, "Reporting Timezone", class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
- <p class="text-gray-500 dark:text-gray-400 text-xs mt-1">To make sure we agree on what 'today' means</p>
-
- <div class="inline-block relative w-full">
- <%= select f, :timezone, Plausible.Timezones.options(), id: "tz-select", selected: "Etc/Greenwich", class: "mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 dark:bg-gray-900 dark:text-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md", disabled: @is_at_limit %>
- </div>
- </div>
- <script>
- var option;
-
- if (typeof Intl !== "undefined") {
- var timezoneName = Intl.DateTimeFormat().resolvedOptions().timeZone
- option = document.querySelector('#tz-select option[value="' + timezoneName + '"]')
- }
-
- if (!option) {
- var offset = (new Date()).getTimezoneOffset()
- option = document.querySelector('#tz-select option[offset="' + offset + '"]')
- }
-
- if (option) { option.selected = "selected"}
- </script>
-
- <%= submit "Add snippet →", class: "button mt-4 w-full", disabled: @is_at_limit %>
- <% end %>
-
- <%= if @is_first_site do %>
- <div class="pt-12 pl-8 hidden md:block">
- <%= render(PlausibleWeb.AuthView, "_onboarding_steps.html", current_step: 2) %>
- </div>
- <% end %>
-</div>
diff --git a/lib/plausible_web/templates/site/new.html.heex b/lib/plausible_web/templates/site/new.html.heex
new file mode 100644
index 0000000000..a24059ff0a
--- /dev/null
+++ b/lib/plausible_web/templates/site/new.html.heex
@@ -0,0 +1,104 @@
+<div class="w-full max-w-3xl mt-4 mx-auto flex">
+ <%= form_for @changeset, "/sites", [class: "max-w-lg w-full mx-auto bg-white dark:bg-gray-800 shadow-lg rounded px-8 pt-6 pb-8 mb-4 mt-8"], fn f -> %>
+ <h2 class="text-xl font-black dark:text-gray-100 mb-4">Your website details</h2>
+
+ <PlausibleWeb.Components.Billing.limit_exceeded_notice
+ current_user={@current_user}
+ billable_user={@current_user}
+ limit={Map.get(assigns, :site_limit, 0)}
+ resource="sites"
+ />
+
+ <%= if is_nil(@current_user.trial_expiry_date) do %>
+ <div class="rounded-md bg-blue-50 dark:bg-transparent dark:border border-blue-200 p-4">
+ <div class="flex">
+ <div class="flex-shrink-0">
+ <svg
+ class="h-5 w-5 text-blue-500 dark:text-blue-300"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+ >
+ <path
+ fill-rule="evenodd"
+ d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z"
+ clip-rule="evenodd"
+ />
+ </svg>
+ </div>
+ <div class="ml-3">
+ <div class="text-sm text-blue-700 dark:text-blue-300">
+ <p>
+ When you create your first site, your account will enter a 30 day free trial.
+ </p>
+ </div>
+ </div>
+ </div>
+ </div>
+ <% end %>
+
+ <div class="my-6">
+ <%= label(f, :domain, class: "block text-sm font-medium text-gray-700 dark:text-gray-300") %>
+ <p class="text-gray-500 dark:text-gray-400 text-xs mt-1">
+ Just the naked domain or subdomain without 'www'
+ </p>
+ <div class="mt-2 flex rounded-md shadow-sm">
+ <span class="inline-flex items-center px-3 rounded-l-md border border-r-0 border-gray-300 dark:border-gray-500 bg-gray-50 dark:bg-gray-850 text-gray-500 dark:text-gray-400 sm:text-sm">
+ https://
+ </span>
+ <%= text_input(f, :domain,
+ class:
+ "focus:ring-indigo-500 focus:border-indigo-500 dark:bg-gray-800 flex-1 block w-full px-3 py-2 rounded-none rounded-r-md sm:text-sm border-gray-300 dark:border-gray-500 dark:bg-gray-900 dark:text-gray-300",
+ placeholder: "example.com",
+ disabled: Map.get(assigns, :is_at_limit, false)
+ ) %>
+ </div>
+ <%= error_tag(f, :domain) %>
+ </div>
+ <div class="my-6">
+ <%= label(f, :timezone, "Reporting Timezone",
+ class: "block text-sm font-medium text-gray-700 dark:text-gray-300"
+ ) %>
+ <p class="text-gray-500 dark:text-gray-400 text-xs mt-1">
+ To make sure we agree on what 'today' means
+ </p>
+
+ <div class="inline-block relative w-full">
+ <%= select(f, :timezone, Plausible.Timezones.options(),
+ id: "tz-select",
+ selected: "Etc/Greenwich",
+ class:
+ "mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 dark:bg-gray-900 dark:text-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md",
+ disabled: Map.get(assigns, :is_at_limit, false)
+ ) %>
+ </div>
+ </div>
+ <script>
+ var option;
+
+ if (typeof Intl !== "undefined") {
+ var timezoneName = Intl.DateTimeFormat().resolvedOptions().timeZone
+ option = document.querySelector('#tz-select option[value="' + timezoneName + '"]')
+ }
+
+ if (!option) {
+ var offset = (new Date()).getTimezoneOffset()
+ option = document.querySelector('#tz-select option[offset="' + offset + '"]')
+ }
+
+ if (option) { option.selected = "selected"}
+ </script>
+
+ <%= submit("Add snippet →",
+ class: "button mt-4 w-full disabled:cursor-not-allowed",
+ disabled: Map.get(assigns, :is_at_limit, false)
+ ) %>
+ <% end %>
+
+ <%= if @is_first_site do %>
+ <div class="pt-12 pl-8 hidden md:block">
+ <%= render(PlausibleWeb.AuthView, "_onboarding_steps.html", current_step: 2) %>
+ </div>
+ <% end %>
+</div>
diff --git a/test/plausible/billing/feature_test.exs b/test/plausible/billing/feature_test.exs
index 2167867d16..8466e0fa39 100644
--- a/test/plausible/billing/feature_test.exs
+++ b/test/plausible/billing/feature_test.exs
@@ -63,6 +63,18 @@ defmodule Plausible.Billing.FeatureTest do
Plausible.Billing.Feature.StatsAPI.check_availability(user)
end
+ test "Plausible.Billing.Feature.StatsAPI.check_availability/2 returns :ok when user trial hasn't started and was created before the business tier launch" do
+ user = insert(:user, inserted_at: ~N[2020-01-01T00:00:00], trial_expiry_date: nil)
+ assert :ok == Plausible.Billing.Feature.StatsAPI.check_availability(user)
+ end
+
+ test "Plausible.Billing.Feature.StatsAPI.check_availability/2 returns error when user trial hasn't started and was created after the business tier launch" do
+ user = insert(:user, inserted_at: ~N[2024-01-01T00:00:00], trial_expiry_date: nil)
+
+ assert {:error, :upgrade_required} ==
+ Plausible.Billing.Feature.StatsAPI.check_availability(user)
+ end
+
test "Plausible.Billing.Feature.Props.check_availability/1 applies grandfathering to old plans" do
user = insert(:user, subscription: build(:subscription, paddle_plan_id: @v1_plan_id))
assert :ok == Plausible.Billing.Feature.Props.check_availability(user)
diff --git a/test/plausible_web/components/billing_test.exs b/test/plausible_web/components/billing_test.exs
index d8bc28bc10..aff369bce9 100644
--- a/test/plausible_web/components/billing_test.exs
+++ b/test/plausible_web/components/billing_test.exs
@@ -26,7 +26,7 @@ defmodule PlausibleWeb.Components.BillingTest do
assert rendered =~ "Custom Properties is part of the Plausible Business plan."
assert rendered =~ "upgrade your subscription"
- assert rendered =~ "/billing/upgrade"
+ assert rendered =~ "/billing/choose-plan"
end
test "premium_feature_notice/1 does not render an upgrade link when user is not the site owner" do
@@ -43,7 +43,7 @@ defmodule PlausibleWeb.Components.BillingTest do
assert rendered =~
"Funnels is part of the Plausible Business plan. To get access to it, please reach out to the site owner to upgrade your subscription to the Business plan."
- refute rendered =~ "/billing/upgrade"
+ refute rendered =~ "/billing/choose-plan"
end
test "premium_feature_notice/1 does not render a notice when the user has access to the feature" do
@@ -58,4 +58,85 @@ defmodule PlausibleWeb.Components.BillingTest do
assert rendered == ""
end
+
+ test "limit_exceeded_notice/1 when billable user is on growth displays upgrade link" do
+ me = insert(:user, subscription: build(:growth_subscription))
+
+ rendered =
+ render_component(&Billing.limit_exceeded_notice/1,
+ billable_user: me,
+ current_user: me,
+ limit: 10,
+ resource: "users"
+ )
+
+ assert rendered =~ "Your account is limited to 10 users. To increase this limit"
+ assert rendered =~ "upgrade your subscription"
+ assert rendered =~ "/billing/choose-plan"
+ end
+
+ test "limit_exceeded_notice/1 when billable user is on growth but is not current user does not display upgrade link" do
+ me = insert(:user, subscription: build(:growth_subscription))
+
+ rendered =
+ render_component(&Billing.limit_exceeded_notice/1,
+ billable_user: me,
+ current_user: insert(:user),
+ limit: 10,
+ resource: "users"
+ )
+
+ assert rendered =~
+ "This account is limited to 10 users. To increase this limit, please reach out to the site owner to upgrade their subscription"
+ end
+
+ test "limit_exceeded_notice/1 when billable user is on trial displays upgrade link" do
+ me = insert(:user)
+
+ rendered =
+ render_component(&Billing.limit_exceeded_notice/1,
+ billable_user: me,
+ current_user: me,
+ limit: 10,
+ resource: "users"
+ )
+
+ assert rendered =~ "Your account is limited to 10 users. To increase this limit"
+ assert rendered =~ "upgrade your subscription"
+ assert rendered =~ "/billing/choose-plan"
+ end
+
+ test "limit_exceeded_notice/1 when billable user is on an enterprise plan displays support email" do
+ me =
+ insert(:user,
+ enterprise_plan: build(:enterprise_plan, paddle_plan_id: "123321"),
+ subscription: build(:subscription, paddle_plan_id: "123321")
+ )
+
+ rendered =
+ render_component(&Billing.limit_exceeded_notice/1,
+ billable_user: me,
+ current_user: me,
+ limit: 10,
+ resource: "users"
+ )
+
+ assert rendered =~
+ "Your account is limited to 10 users. To increase this limit, please contact [email protected] about the Enterprise plan"
+ end
+
+ test "limit_exceeded_notice/1 when billable user is on a business plan displays support email" do
+ me = insert(:user, subscription: build(:business_subscription))
+
+ rendered =
+ render_component(&Billing.limit_exceeded_notice/1,
+ billable_user: me,
+ current_user: me,
+ limit: 10,
+ resource: "users"
+ )
+
+ assert rendered =~
+ "Your account is limited to 10 users. To increase this limit, please contact [email protected] about the Enterprise plan"
+ end
end
diff --git a/test/plausible_web/controllers/auth_controller_test.exs b/test/plausible_web/controllers/auth_controller_test.exs
index 9bac44cf51..a2622e9530 100644
--- a/test/plausible_web/controllers/auth_controller_test.exs
+++ b/test/plausible_web/controllers/auth_controller_test.exs
@@ -510,7 +510,7 @@ defmodule PlausibleWeb.AuthControllerTest do
assert html_response(conn, 200) =~ "yearly billing"
end
- test "links to upgrade to a plan", %{conn: conn} do
+ test "renders two links to '/billing/choose-plan` with the text 'Upgrade'", %{conn: conn} do
doc =
get(conn, "/settings")
|> html_response(200)
@@ -525,7 +525,7 @@ defmodule PlausibleWeb.AuthControllerTest do
assert text_of_attr(upgrade_link_2, "href") == Routes.billing_path(conn, :choose_plan)
end
- test "links to change existing plan", %{
+ test "renders a link to '/billing/choose-plan' with the text 'Change plan' + cancel link", %{
conn: conn,
user: user
} do
@@ -544,7 +544,7 @@ defmodule PlausibleWeb.AuthControllerTest do
assert text_of_attr(change_plan_link, "href") == Routes.billing_path(conn, :choose_plan)
end
- test "upgrade_to_enterprise_plan link does not show up when subscription is past_due", %{
+ test "/billing/choose-plan link does not show up when enterprise subscription is past_due", %{
conn: conn,
user: user
} do
@@ -564,7 +564,7 @@ defmodule PlausibleWeb.AuthControllerTest do
refute element_exists?(doc, "#upgrade-or-change-plan-link")
end
- test "upgrade_to_enterprise_plan link does not show up when subscription is paused", %{
+ test "/billing/choose-plan link does not show up when enterprise subscription is paused", %{
conn: conn,
user: user
} do
@@ -584,7 +584,7 @@ defmodule PlausibleWeb.AuthControllerTest do
refute element_exists?(doc, "#upgrade-or-change-plan-link")
end
- test "links to upgrade to enterprise plan",
+ test "renders two links to '/billing/choose-plan' with the text 'Upgrade' for a configured enterprise plan",
%{conn: conn, user: user} do
configure_enterprise_plan(user)
@@ -598,15 +598,15 @@ defmodule PlausibleWeb.AuthControllerTest do
assert text(upgrade_link_1) == "Upgrade"
assert text_of_attr(upgrade_link_1, "href") ==
- Routes.billing_path(conn, :upgrade_to_enterprise_plan)
+ Routes.billing_path(conn, :choose_plan)
assert text(upgrade_link_2) == "Upgrade"
assert text_of_attr(upgrade_link_2, "href") ==
- Routes.billing_path(conn, :upgrade_to_enterprise_plan)
+ Routes.billing_path(conn, :choose_plan)
end
- test "links to change enterprise plan and cancel subscription",
+ test "links to '/billing/choose-plan' with the text 'Change plan' for a configured enterprise plan with an existing subscription + renders cancel button",
%{conn: conn, user: user} do
insert(:subscription, paddle_plan_id: @v3_plan_id, user: user)
@@ -624,7 +624,7 @@ defmodule PlausibleWeb.AuthControllerTest do
assert text(change_plan_link) == "Change plan"
assert text_of_attr(change_plan_link, "href") ==
- Routes.billing_path(conn, :upgrade_to_enterprise_plan)
+ Routes.billing_path(conn, :choose_plan)
end
test "shows invoices for subscribed user", %{conn: conn, user: user} do
diff --git a/test/plausible_web/controllers/billing_controller_test.exs b/test/plausible_web/controllers/billing_controller_test.exs
index 88ca8110bb..41171be2d0 100644
--- a/test/plausible_web/controllers/billing_controller_test.exs
+++ b/test/plausible_web/controllers/billing_controller_test.exs
@@ -10,19 +10,6 @@ defmodule PlausibleWeb.BillingControllerTest do
describe "GET /upgrade" do
setup [:create_user, :log_in]
- test "shows upgrade page when user does not have a subcription already", %{conn: conn} do
- conn = get(conn, Routes.billing_path(conn, :upgrade))
-
- assert html_response(conn, 200) =~ "Upgrade your free trial"
- end
-
- test "redirects user to change plan if they already have a plan", %{conn: conn, user: user} do
- insert(:subscription, user: user)
- conn = get(conn, Routes.billing_path(conn, :upgrade))
-
- assert redirected_to(conn) == Routes.billing_path(conn, :change_plan_form)
- end
-
test "redirects user to enteprise plan page if they are configured with one", %{
conn: conn,
user: user
@@ -33,35 +20,22 @@ defmodule PlausibleWeb.BillingControllerTest do
end
end
- describe "GET /upgrade/enterprise/:plan_id (deprecated)" do
+ describe "GET /choose-plan" do
setup [:create_user, :log_in]
- test "redirects to the new :upgrade_to_enterprise_plan action", %{conn: conn} do
- conn = get(conn, Routes.billing_path(conn, :upgrade_enterprise_plan, "123"))
+ test "redirects to enterprise upgrade page if user has an enterprise plan configured",
+ %{conn: conn, user: user} do
+ insert(:enterprise_plan, user: user, paddle_plan_id: "123")
+ conn = get(conn, Routes.billing_path(conn, :choose_plan))
assert redirected_to(conn) == Routes.billing_path(conn, :upgrade_to_enterprise_plan)
end
end
- describe "GET /change-plan" do
+ describe "GET /upgrade/enterprise/:plan_id (deprecated)" do
setup [:create_user, :log_in]
- test "shows change plan page if user has subsription", %{conn: conn, user: user} do
- insert(:subscription, user: user)
- conn = get(conn, Routes.billing_path(conn, :change_plan_form))
-
- assert html_response(conn, 200) =~ "Change subscription plan"
- end
-
- test "redirects to /upgrade if user does not have a subscription", %{conn: conn} do
- conn = get(conn, Routes.billing_path(conn, :change_plan_form))
-
- assert redirected_to(conn) == Routes.billing_path(conn, :upgrade)
- end
-
- test "redirects to enterprise upgrade page if user has an enterprise plan configured",
- %{conn: conn, user: user} do
- insert(:enterprise_plan, user: user, paddle_plan_id: "123")
- conn = get(conn, Routes.billing_path(conn, :change_plan_form))
+ test "redirects to the new :upgrade_to_enterprise_plan action", %{conn: conn} do
+ conn = get(conn, Routes.billing_path(conn, :upgrade_enterprise_plan, "123"))
assert redirected_to(conn) == Routes.billing_path(conn, :upgrade_to_enterprise_plan)
end
end
diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exs
index ada9c0fdd1..09dbf0425e 100644
--- a/test/plausible_web/controllers/site_controller_test.exs
+++ b/test/plausible_web/controllers/site_controller_test.exs
@@ -271,9 +271,7 @@ defmodule PlausibleWeb.SiteControllerTest do
})
assert html = html_response(conn, 200)
- assert html =~ "Upgrade required"
assert html =~ "Your account is limited to 10 sites"
- assert html =~ "Please contact support"
refute Repo.get_by(Plausible.Site, domain: "over-limit.example.com")
end
diff --git a/test/plausible_web/live/choose_plan_test.exs b/test/plausible_web/live/choose_plan_test.exs
index a95315ab4d..5583aa5d79 100644
--- a/test/plausible_web/live/choose_plan_test.exs
+++ b/test/plausible_web/live/choose_plan_test.exs
@@ -49,7 +49,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
assert growth_box =~ "Email/Slack reports"
assert growth_box =~ "Google Analytics import"
assert growth_box =~ "Goals and custom events"
- assert growth_box =~ "Stats API"
+ assert growth_box =~ "Stats API (600 requests per hour)"
assert growth_box =~ "Custom Properties"
assert business_box =~ "Everything in Growth"
@@ -94,7 +94,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
assert business_box =~ "Everything in Growth"
assert business_box =~ "Up to 10 team members"
assert business_box =~ "Up to 50 sites"
- assert business_box =~ "Stats API"
+ assert business_box =~ "Stats API (600 requests per hour)"
assert business_box =~ "Custom Properties"
assert business_box =~ "Funnels"
assert business_box =~ "Ecommerce revenue attribution"
@@ -105,6 +105,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
assert enterprise_box =~ "Everything in Business"
assert enterprise_box =~ "10+ team members"
assert enterprise_box =~ "50+ sites"
+ assert enterprise_box =~ "600+ Stats API requests per hour"
assert enterprise_box =~ "Sites API access for"
assert enterprise_box =~ "Technical onboarding"
@@ -293,7 +294,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
assert business_box =~ "Everything in Growth"
assert business_box =~ "Up to 10 team members"
assert business_box =~ "Up to 50 sites"
- assert business_box =~ "Stats API"
+ assert business_box =~ "Stats API (600 requests per hour)"
assert business_box =~ "Custom Properties"
assert business_box =~ "Funnels"
assert business_box =~ "Ecommerce revenue attribution"
@@ -304,6 +305,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
assert enterprise_box =~ "Everything in Business"
assert enterprise_box =~ "10+ team members"
assert enterprise_box =~ "50+ sites"
+ assert enterprise_box =~ "600+ Stats API requests per hour"
assert enterprise_box =~ "Sites API access for"
assert enterprise_box =~ "Technical onboarding"
@@ -510,7 +512,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
assert business_box =~ "Everything in Growth"
assert business_box =~ "Unlimited team members"
assert business_box =~ "Up to 50 sites"
- assert business_box =~ "Stats API"
+ assert business_box =~ "Stats API (600 requests per hour)"
assert business_box =~ "Custom Properties"
assert business_box =~ "Funnels"
assert business_box =~ "Ecommerce revenue attribution"
@@ -520,6 +522,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
assert enterprise_box =~ "Everything in Business"
assert enterprise_box =~ "50+ sites"
+ assert enterprise_box =~ "600+ Stats API requests per hour"
assert enterprise_box =~ "Sites API access for"
assert enterprise_box =~ "Technical onboarding"
@@ -638,7 +641,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
doc = lv |> element(@slider_input) |> render_change(%{slider: 9})
assert text_of_element(doc, @slider_value) == "50M"
assert text_of_element(doc, @business_plan_box) =~ "Contact us"
- assert text_of_element(doc, @growth_price_tag_amount) == "€1K"
+ assert text_of_element(doc, @growth_price_tag_amount) == "€1,000"
assert text_of_element(doc, @growth_price_tag_interval) == "/year"
doc = lv |> element(@slider_input) |> render_change(%{slider: 10})
@@ -673,11 +676,12 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
refute business_box =~ "Goals and custom events"
refute business_box =~ "Unlimited team members"
refute business_box =~ "Up to 50 sites"
- refute business_box =~ "Stats API"
+ refute business_box =~ "Stats API (600 requests per hour)"
refute business_box =~ "Custom Properties"
assert enterprise_box =~ "Everything in Business"
assert enterprise_box =~ "50+ sites"
+ assert enterprise_box =~ "600+ Stats API requests per hour"
assert enterprise_box =~ "Sites API access for"
assert enterprise_box =~ "Technical onboarding"