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
Clean up legacy trials code + displaying limits (#3620)
RobertJoonas686ffa6ef311
diff --git a/extra/lib/plausible_web/controllers/api/external_sites_controller.ex b/extra/lib/plausible_web/controllers/api/external_sites_controller.exindex 4e901a3233..a7c044df40 100644--- a/extra/lib/plausible_web/controllers/api/external_sites_controller.ex+++ b/extra/lib/plausible_web/controllers/api/external_sites_controller.ex@@ -13,7 +13,7 @@ defmodule PlausibleWeb.Api.ExternalSitesController do{:ok, %{site: site}} ->json(conn, site)- {:error, :limit, limit, _} ->+ {:error, {:over_limit, limit}} ->conn|> put_status(402)|> json(%{diff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.exindex af4cafe468..633446c4ac 100644--- a/lib/plausible/billing/billing.ex+++ b/lib/plausible/billing/billing.ex@@ -234,7 +234,7 @@ defmodule Plausible.Billing docase user.grace_period do%GracePeriod{allowance_required: allowance_required} ->new_monthly_pageview_limit =- Plausible.Billing.Quota.monthly_pageview_limit(user.subscription)+ Plausible.Billing.Quota.monthly_pageview_limit(user)if new_monthly_pageview_limit > allowance_required douserdiff --git a/lib/plausible/billing/plans.ex b/lib/plausible/billing/plans.exindex 3d423348d7..c667988565 100644--- a/lib/plausible/billing/plans.ex+++ b/lib/plausible/billing/plans.ex@@ -36,14 +36,13 @@ defmodule Plausible.Billing.Plans doAs new versions of plans are introduced, users who were on old plans canstill choose from old plans."""- def growth_plans_for(%User{} = user, now \\ Timex.now()) do+ def growth_plans_for(%User{} = user) douser = Plausible.Users.with_subscription(user)v4_available = FunWithFlags.enabled?(:business_tier, for: user)owned_plan = get_regular_plan(user.subscription)cond doApplication.get_env(:plausible, :environment) == "dev" -> @sandbox_plans- is_nil(owned_plan) && grandfathered_trial?(user.trial_expiry_date, now) -> @plans_v3is_nil(owned_plan) && v4_available -> @plans_v4is_nil(owned_plan) -> @plans_v3user.subscription && Subscriptions.expired?(user.subscription) -> @plans_v4@@ -56,13 +55,12 @@ defmodule Plausible.Billing.Plans do|> Enum.filter(&(&1.kind == :growth))end- def business_plans_for(%User{} = user, now \\ Timex.now()) do+ def business_plans_for(%User{} = user) douser = Plausible.Users.with_subscription(user)owned_plan = get_regular_plan(user.subscription)cond doApplication.get_env(:plausible, :environment) == "dev" -> @sandbox_plans- is_nil(owned_plan) && grandfathered_trial?(user.trial_expiry_date, now) -> @plans_v3user.subscription && Subscriptions.expired?(user.subscription) -> @plans_v4owned_plan && owned_plan.generation < 4 -> @plans_v3true -> @plans_v4@@ -70,20 +68,6 @@ defmodule Plausible.Billing.Plans do|> Enum.filter(&(&1.kind == :business))end- # Takes a Date struct argument representing the trial end date of a user.- # If the `trial_expiry` is `nil`, it means that the user has not started- # their trial yet (i.e. invited user), and this function returns false.- defp grandfathered_trial?(nil, _now), do: false-- defp grandfathered_trial?(trial_expiry, now) do- trial_start = Timex.shift(trial_expiry, days: -30)-- joined_before_business_tiers = Timex.before?(trial_start, @business_tier_launch)- trial_active_or_expired_less_than_10d_ago = Timex.diff(now, trial_expiry, :days) <= 10-- joined_before_business_tiers && trial_active_or_expired_less_than_10d_ago- end-def available_plans_for(%User{} = user, opts \\ []) doplans = growth_plans_for(user) ++ business_plans_for(user)diff --git a/lib/plausible/billing/quota.ex b/lib/plausible/billing/quota.exindex a72eaf085e..13a6b89ad0 100644--- a/lib/plausible/billing/quota.ex+++ b/lib/plausible/billing/quota.ex@@ -25,14 +25,11 @@ defmodule Plausible.Billing.Quota doendend- @doc """- Returns the limit of sites a user can have.-- For enterprise customers, returns :unlimited. The site limit is checked in a- background job so as to avoid service disruption.- """on_full_build do@limit_sites_since ~D[2021-05-05]+ @site_limit_for_trials 10+ @team_member_limit_for_trials 3+@spec site_limit(User.t()) :: non_neg_integer() | :unlimiteddef site_limit(user) doif Timex.before?(user.inserted_at, @limit_sites_since) do@@ -42,35 +39,34 @@ defmodule Plausible.Billing.Quota doendend- @site_limit_for_trials 10- @site_limit_for_legacy_trials 50- @site_limit_for_free_10k 50defp get_site_limit_from_plan(user) douser = Plausible.Users.with_subscription(user)case Plans.get_subscription_plan(user.subscription) do- %EnterprisePlan{} ->- :unlimited-- %Plan{site_limit: site_limit} ->- site_limit+ %{site_limit: site_limit} -> site_limit+ :free_10k -> 50+ nil -> @site_limit_for_trials+ end+ end- :free_10k ->- @site_limit_for_free_10k+ @spec team_member_limit(User.t()) :: non_neg_integer()+ def team_member_limit(user) do+ user = Plausible.Users.with_subscription(user)- nil ->- if Timex.before?(user.inserted_at, Plans.business_tier_launch()) do- @site_limit_for_legacy_trials- else- @site_limit_for_trials- end+ case Plans.get_subscription_plan(user.subscription) do+ %{team_member_limit: limit} -> limit+ :free_10k -> :unlimited+ nil -> @team_member_limit_for_trialsendendelse- @spec site_limit(any()) :: non_neg_integer() | :unlimiteddef site_limit(_) do:unlimitedend++ def team_member_limit(_) do+ :unlimited+ endend@spec site_usage(User.t()) :: non_neg_integer()@@ -81,14 +77,36 @@ defmodule Plausible.Billing.Quota doPlausible.Sites.owned_sites_count(user)end+ @doc """+ Enterprise plans are always allowed to add more sites (even when+ over limit) to avoid service disruption. Their usage is checked+ in a background job instead (see `check_usage.ex`).+ """+ def ensure_can_add_new_site(user) do+ user = Plausible.Users.with_subscription(user)++ case Plans.get_subscription_plan(user.subscription) do+ %EnterprisePlan{} ->+ :ok++ _ ->+ usage = site_usage(user)+ limit = site_limit(user)++ if below_limit?(usage, limit), do: :ok, else: {:error, {:over_limit, limit}}+ end+ end+@monthly_pageview_limit_for_free_10k 10_000@monthly_pageview_limit_for_trials :unlimited- @spec monthly_pageview_limit(Subscription.t()) ::+ @spec monthly_pageview_limit(User.t() | Subscription.t()) ::non_neg_integer() | :unlimited- @doc """- Returns the limit of pageviews for a subscription.- """+ def monthly_pageview_limit(%User{} = user) do+ user = Plausible.Users.with_subscription(user)+ monthly_pageview_limit(user.subscription)+ end+def monthly_pageview_limit(subscription) docase Plans.get_subscription_plan(subscription) do%EnterprisePlan{monthly_pageview_limit: limit} ->@@ -202,38 +220,16 @@ defmodule Plausible.Billing.Quota do}end- @team_member_limit_for_trials 3- @team_member_limit_for_legacy_trials :unlimited- @spec team_member_limit(User.t()) :: non_neg_integer()+ @spec team_member_usage(User.t()) :: integer()@doc """- Returns the limit of team members a user can have in their sites.- """- def team_member_limit(user) do- user = Plausible.Users.with_subscription(user)-- case Plans.get_subscription_plan(user.subscription) do- %EnterprisePlan{team_member_limit: limit} ->- limit+ Returns the total count of team members associated with the user's sites.- %Plan{team_member_limit: limit} ->- limit+ * The given user (i.e. the owner) is not counted as a team member.- :free_10k ->- :unlimited+ * Pending invitations are counted as team members even before accepted.- nil ->- if Timex.before?(user.inserted_at, Plans.business_tier_launch()) do- @team_member_limit_for_legacy_trials- else- @team_member_limit_for_trials- end- end- end-- @spec team_member_usage(User.t()) :: integer()- @doc """- Returns the total count of team members and pending invitations associated- with the user's sites.+ * Users are counted uniquely - i.e. even if an account is associated with+ many sites owned by the given user, they still count as one team member."""def team_member_usage(user) doPlausible.Repo.aggregate(team_member_usage_query(user), :count)diff --git a/lib/plausible/site.ex b/lib/plausible/site.exindex 35b9dc2e50..c571619abe 100644--- a/lib/plausible/site.ex+++ b/lib/plausible/site.ex@@ -57,6 +57,8 @@ defmodule Plausible.Site dotimestamps()end+ def new(params), do: changeset(%__MODULE__{}, params)+@domain_unique_error """This domain cannot be registered. Perhaps one of your colleagues registered it? If that's not the case, please contact [email protected]"""diff --git a/lib/plausible/sites.ex b/lib/plausible/sites.exindex f448ae4662..14fc2f0f50 100644--- a/lib/plausible/sites.ex+++ b/lib/plausible/sites.ex@@ -87,7 +87,7 @@ defmodule Plausible.Sites doselected_as(fragment("""- CASE+ CASEWHEN ? IS NOT NULL THEN 'pinned_site'ELSE 'site'END@@ -124,7 +124,7 @@ defmodule Plausible.Sites doselected_as(fragment("""- CASE+ CASEWHEN ? IS NOT NULL THEN 'invitation'WHEN ? IS NOT NULL THEN 'pinned_site'ELSE 'site'@@ -167,21 +167,15 @@ defmodule Plausible.Sites dodefp maybe_filter_by_domain(query, _), do: querydef create(user, params) do- site_changeset = Site.changeset(%Site{}, params)-- Ecto.Multi.new()- |> Ecto.Multi.run(:limit, fn _, _ ->- limit = Quota.site_limit(user)- usage = Quota.site_usage(user)-- if Quota.below_limit?(usage, limit), do: {:ok, usage}, else: {:error, limit}- end)- |> Ecto.Multi.insert(:site, site_changeset)- |> Ecto.Multi.insert(:site_membership, fn %{site: site} ->- Site.Membership.new(site, user)- end)- |> maybe_start_trial(user)- |> Repo.transaction()+ with :ok <- Quota.ensure_can_add_new_site(user) do+ Ecto.Multi.new()+ |> Ecto.Multi.insert(:site, Site.new(params))+ |> Ecto.Multi.insert(:site_membership, fn %{site: site} ->+ Site.Membership.new(site, user)+ end)+ |> maybe_start_trial(user)+ |> Repo.transaction()+ endenddefp maybe_start_trial(multi, user) dodiff --git a/lib/plausible_web/components/billing.ex b/lib/plausible_web/components/billing.exindex 1fea4593c9..16ff004c3a 100644--- a/lib/plausible_web/components/billing.ex+++ b/lib/plausible_web/components/billing.ex@@ -237,7 +237,7 @@ defmodule PlausibleWeb.Components.Billing doendattr(:title, :string, required: true)- attr(:usage, :any, required: true)+ attr(:usage, :integer, required: true)attr(:limit, :integer, default: nil)attr(:pad, :boolean, default: false)attr(:rest, :global)@@ -249,21 +249,13 @@ defmodule PlausibleWeb.Components.Billing do<%= @title %></td><td class="py-4 text-sm sm:whitespace-nowrap text-right">- <%= render_quota(@usage) %>- <%= if @limit, do: "/ #{render_quota(@limit)}" %>+ <%= Cldr.Number.to_string!(@usage) %>+ <%= if is_number(@limit), do: "/ #{Cldr.Number.to_string!(@limit)}" %></td></tr>"""end- defp render_quota(quota) do- case quota do- quota when is_number(quota) -> Cldr.Number.to_string!(quota)- :unlimited -> "∞"- nil -> ""- end- end-def monthly_quota_box(%{business_tier: true} = assigns) do~H"""<divdiff --git a/lib/plausible_web/controllers/admin_controller.ex b/lib/plausible_web/controllers/admin_controller.exindex 264afbe214..d10bab1a53 100644--- a/lib/plausible_web/controllers/admin_controller.ex+++ b/lib/plausible_web/controllers/admin_controller.ex@@ -12,7 +12,7 @@ defmodule PlausibleWeb.AdminController dousage = Quota.usage(user, with_features: true)limits = %{- monthly_pageviews: Quota.monthly_pageview_limit(user.subscription),+ monthly_pageviews: Quota.monthly_pageview_limit(user),sites: Quota.site_limit(user),team_members: Quota.team_member_limit(user)}diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.exindex 439db16187..14cf1554bd 100644--- a/lib/plausible_web/controllers/auth_controller.ex+++ b/lib/plausible_web/controllers/auth_controller.ex@@ -613,7 +613,7 @@ defmodule PlausibleWeb.AuthController doteam_member_usage: Quota.team_member_usage(user),site_limit: Quota.site_limit(user),site_usage: Quota.site_usage(user),- pageview_limit: Quota.monthly_pageview_limit(user.subscription),+ pageview_limit: Quota.monthly_pageview_limit(user),pageview_usage: Quota.monthly_pageview_usage(user),totp_enabled?: Auth.TOTP.enabled?(user))diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.exindex 2b7c7dffad..8ab575fc55 100644--- a/lib/plausible_web/controllers/site_controller.ex+++ b/lib/plausible_web/controllers/site_controller.ex@@ -2,6 +2,7 @@ defmodule PlausibleWeb.SiteController douse PlausibleWeb, :controlleruse Plausible.Repoalias Plausible.Sites+ alias Plausible.Billing.Quotaplug PlausibleWeb.RequireAccountPlug@@ -11,27 +12,22 @@ defmodule PlausibleWeb.SiteController dodef new(conn, _params) docurrent_user = conn.assigns[:current_user]- limit = Plausible.Billing.Quota.site_limit(current_user)- usage = Plausible.Billing.Quota.site_usage(current_user)- below_limit? = Plausible.Billing.Quota.below_limit?(usage, limit)-render(conn, "new.html",changeset: Plausible.Site.changeset(%Plausible.Site{}),- is_first_site: usage == 0,- is_at_limit: !below_limit?,- site_limit: limit,+ first_site?: Quota.site_usage(current_user) == 0,+ site_limit: Quota.site_limit(current_user),+ site_limit_exceeded?: Quota.ensure_can_add_new_site(current_user) != :ok,layout: {PlausibleWeb.LayoutView, "focus.html"})enddef create_site(conn, %{"site" => site_params}) douser = conn.assigns[:current_user]- usage = Plausible.Billing.Quota.site_usage(user)- is_first_site = usage == 0+ first_site? = Quota.site_usage(user) == 0case Sites.create(user, site_params) do{:ok, %{site: site}} ->- if is_first_site do+ if first_site? doPlausibleWeb.Email.welcome_email(user)|> Plausible.Mailer.send()end@@ -40,20 +36,21 @@ defmodule PlausibleWeb.SiteController do|> put_session(site.domain <> "_offer_email_report", true)|> redirect(external: Routes.site_path(conn, :add_snippet, site.domain))- {:error, :limit, limit, _} ->+ {:error, {:over_limit, limit}} ->render(conn, "new.html",changeset: Plausible.Site.changeset(%Plausible.Site{}),- is_first_site: is_first_site,- is_at_limit: true,+ first_site?: first_site?,site_limit: limit,+ site_limit_exceeded?: true,layout: {PlausibleWeb.LayoutView, "focus.html"}){:error, _, changeset, _} ->render(conn, "new.html",changeset: changeset,- is_first_site: is_first_site,- is_at_limit: false,+ first_site?: first_site?,+ site_limit: Quota.site_limit(user),+ site_limit_exceeded?: false,layout: {PlausibleWeb.LayoutView, "focus.html"})enddiff --git a/lib/plausible_web/templates/site/new.html.heex b/lib/plausible_web/templates/site/new.html.heexindex 9ca83c02e7..e60633d895 100644--- a/lib/plausible_web/templates/site/new.html.heex+++ b/lib/plausible_web/templates/site/new.html.heex@@ -3,10 +3,10 @@<h2 class="text-xl font-black dark:text-gray-100 mb-4">Your website details</h2><PlausibleWeb.Components.Billing.limit_exceeded_notice- :if={Map.get(assigns, :is_at_limit, false)}+ :if={@site_limit_exceeded?}current_user={@current_user}billable_user={@current_user}- limit={Map.get(assigns, :site_limit, 0)}+ limit={@site_limit}resource="sites"/>@@ -52,7 +52,7 @@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)+ disabled: @site_limit_exceeded?) %></div><%= error_tag(f, :domain) %>@@ -71,7 +71,7 @@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)+ disabled: @site_limit_exceeded?) %></div></div>@@ -93,11 +93,11 @@<%= submit("Add snippet →",class: "button mt-4 w-full disabled:cursor-not-allowed",- disabled: Map.get(assigns, :is_at_limit, false)+ disabled: @site_limit_exceeded?) %><% end %>- <%= if @is_first_site do %>+ <%= if @first_site? do %><div class="pt-12 pl-8 hidden md:block"><%= render(PlausibleWeb.AuthView, "_onboarding_steps.html", current_step: 2) %></div>diff --git a/lib/workers/check_usage.ex b/lib/workers/check_usage.exindex bdd91b7616..6c3d62f3d3 100644--- a/lib/workers/check_usage.ex+++ b/lib/workers/check_usage.ex@@ -108,7 +108,7 @@ defmodule Plausible.Workers.CheckUsage dodefp check_pageview_usage(subscriber, quota_mod) dousage = quota_mod.monthly_pageview_usage(subscriber)- limit = Quota.monthly_pageview_limit(subscriber.subscription)+ limit = Quota.monthly_pageview_limit(subscriber)if exceeds_last_two_usage_cycles?(usage, limit) do{:over_limit, usage}diff --git a/test/plausible/billing/plans_test.exs b/test/plausible/billing/plans_test.exsindex 7c50052a0f..a9b9b0e4e9 100644--- a/test/plausible/billing/plans_test.exs+++ b/test/plausible/billing/plans_test.exs@@ -38,22 +38,6 @@ defmodule Plausible.Billing.PlansTest do|> assert_generation(4)end- test "growth_plans_for/1 returns v3 plans for pre business tier trials only if their trial is active or expired less than 10 days ago" do- trial_start = ~D[2023-10-27]- trial_expiry = Timex.shift(trial_start, days: 30)- expiry_datetime = Timex.to_datetime(trial_expiry)-- user = insert(:user, trial_expiry_date: trial_expiry)-- now1 = Timex.shift(expiry_datetime, days: -1)- now2 = Timex.shift(expiry_datetime, days: 10)- now3 = Timex.shift(expiry_datetime, days: 11)-- Plans.growth_plans_for(user, now1) |> assert_generation(3)- Plans.growth_plans_for(user, now2) |> assert_generation(3)- Plans.growth_plans_for(user, now3) |> assert_generation(4)- end-test "growth_plans_for/1 returns v4 plans for expired legacy subscriptions" dosubscription =build(:subscription,@@ -114,22 +98,6 @@ defmodule Plausible.Billing.PlansTest do|> assert_generation(4)end- test "business_plans_for/1 returns v3 plans for pre business tier trials only if their trial is active or expired less than 10 days ago" do- trial_start = ~D[2023-10-27]- trial_expiry = Timex.shift(trial_start, days: 30)- expiry_datetime = Timex.to_datetime(trial_expiry)-- user = insert(:user, trial_expiry_date: trial_expiry)-- now1 = Timex.shift(expiry_datetime, days: -1)- now2 = Timex.shift(expiry_datetime, days: 10)- now3 = Timex.shift(expiry_datetime, days: 11)-- Plans.business_plans_for(user, now1) |> assert_generation(3)- Plans.business_plans_for(user, now2) |> assert_generation(3)- Plans.business_plans_for(user, now3) |> assert_generation(4)- end-test "business_plans_for/1 returns v4 plans for expired legacy subscriptions" dosubscription =build(:subscription,diff --git a/test/plausible/billing/quota_test.exs b/test/plausible/billing/quota_test.exsindex 4239ac1f66..105e1cfa94 100644--- a/test/plausible/billing/quota_test.exs+++ b/test/plausible/billing/quota_test.exs@@ -18,6 +18,7 @@ defmodule Plausible.Billing.QuotaTest dodescribe "site_limit/1" do@describetag :full_build_only+test "returns 50 when user is on an old plan" douser_on_v1 = insert(:user, subscription: build(:subscription, paddle_plan_id: @v1_plan_id))user_on_v2 = insert(:user, subscription: build(:subscription, paddle_plan_id: @v2_plan_id))@@ -33,20 +34,13 @@ defmodule Plausible.Billing.QuotaTest doassert 50 == Quota.site_limit(user)end- test "returns unlimited when user is on an enterprise plan" do+ test "returns the configured site limit for enterprise plan" douser = insert(:user)- enterprise_plan =- insert(:enterprise_plan,- user_id: user.id,- monthly_pageview_limit: 100_000,- site_limit: 500- )-- _subscription =- insert(:subscription, user_id: user.id, paddle_plan_id: enterprise_plan.paddle_plan_id)+ enterprise_plan = insert(:enterprise_plan, user_id: user.id, site_limit: 500)+ insert(:subscription, user_id: user.id, paddle_plan_id: enterprise_plan.paddle_plan_id)- assert :unlimited == Quota.site_limit(user)+ assert enterprise_plan.site_limit == Quota.site_limit(user)endtest "returns 10 when user in on trial" do@@ -58,16 +52,6 @@ defmodule Plausible.Billing.QuotaTest doassert 10 == Quota.site_limit(user)end- test "returns 50 when user in on trial but registered before the business tier was live" do- user =- insert(:user,- trial_expiry_date: Timex.shift(Timex.now(), days: 7),- inserted_at: ~U[2023-10-01T00:00:00Z]- )-- assert 50 == Quota.site_limit(user)- end-test "returns the subscription limit for enterprise users who have not paid yet" douser =insert(:user,@@ -87,27 +71,6 @@ defmodule Plausible.Billing.QuotaTest doassert 10 == Quota.site_limit(user)end-- test "is unlimited for enterprise customers" do- user =- insert(:user,- enterprise_plan: build(:enterprise_plan, paddle_plan_id: "123321"),- subscription: build(:subscription, paddle_plan_id: "123321")- )-- assert :unlimited == Quota.site_limit(user)- end-- test "is unlimited for enterprise customers who are due to change a plan" do- user =- insert(:user,- enterprise_plan: build(:enterprise_plan, paddle_plan_id: "old-paddle-plan-id"),- subscription: build(:subscription, paddle_plan_id: "old-paddle-plan-id")- )-- insert(:enterprise_plan, user_id: user.id, paddle_plan_id: "new-paddle-plan-id")- assert :unlimited == Quota.site_limit(user)- endendtest "site_usage/1 returns the amount of sites the user owns" do@@ -399,6 +362,7 @@ defmodule Plausible.Billing.QuotaTest doenddescribe "team_member_limit/1" do+ @describetag :full_build_onlytest "returns unlimited when user is on an old plan" douser_on_v1 = insert(:user, subscription: build(:subscription, paddle_plan_id: @v1_plan_id))user_on_v2 = insert(:user, subscription: build(:subscription, paddle_plan_id: @v2_plan_id))@@ -423,16 +387,6 @@ defmodule Plausible.Billing.QuotaTest doassert 3 == Quota.team_member_limit(user)end- test "returns unlimited when user in on trial but registered before the business tier was live" do- user =- insert(:user,- trial_expiry_date: Timex.shift(Timex.now(), days: 7),- inserted_at: ~U[2023-10-01T00:00:00Z]- )-- assert :unlimited == Quota.team_member_limit(user)- end-test "returns the enterprise plan limit" douser =insert(:user,diff --git a/test/plausible/site/memberships/create_invitation_test.exs b/test/plausible/site/memberships/create_invitation_test.exsindex 5b8e6f7205..84462560dd 100644--- a/test/plausible/site/memberships/create_invitation_test.exs+++ b/test/plausible/site/memberships/create_invitation_test.exs@@ -66,6 +66,7 @@ defmodule Plausible.Site.Memberships.CreateInvitationTest do)end+ @tag :full_build_onlytest "returns error when owner is over their team member limit" do[owner, inviter, invitee] = insert_list(3, :user)@@ -186,6 +187,7 @@ defmodule Plausible.Site.Memberships.CreateInvitationTest doCreateInvitation.create_invitation(site, inviter, "[email protected]", :admin)end+ @tag :full_build_onlytest "does not allow transferring ownership when site does not fit the new owner subscription" doold_owner = insert(:user, subscription: build(:business_subscription))new_owner = insert(:user, subscription: build(:growth_subscription))diff --git a/test/plausible_web/controllers/auth_controller_test.exs b/test/plausible_web/controllers/auth_controller_test.exsindex 03dc95192b..d0595273b0 100644--- a/test/plausible_web/controllers/auth_controller_test.exs+++ b/test/plausible_web/controllers/auth_controller_test.exs@@ -863,12 +863,14 @@ defmodule PlausibleWeb.AuthControllerTest doassert text_of_element(doc, "#pageviews_current_cycle") =~ "Pageviews 1"assert text_of_element(doc, "#custom_events_current_cycle") =~ "Custom events 0"- assert text_of_element(doc, "#total_pageviews_last_cycle") =~ "Total billable pageviews 1"+ assert text_of_element(doc, "#total_pageviews_last_cycle") =~+ "Total billable pageviews 1 / 10,000"+assert text_of_element(doc, "#pageviews_last_cycle") =~ "Pageviews 0"assert text_of_element(doc, "#custom_events_last_cycle") =~ "Custom events 1"assert text_of_element(doc, "#total_pageviews_penultimate_cycle") =~- "Total billable pageviews 2"+ "Total billable pageviews 2 / 10,000"assert text_of_element(doc, "#pageviews_penultimate_cycle") =~ "Pageviews 1"assert text_of_element(doc, "#custom_events_penultimate_cycle") =~ "Custom events 1"@@ -1097,6 +1099,19 @@ defmodule PlausibleWeb.AuthControllerTest doassert team_member_usage_row_text =~ "Team members 0 / 3"end+ @tag :full_build_only+ test "renders team member usage without limit if it's unlimited", %{conn: conn, user: user} do+ insert(:subscription, paddle_plan_id: @v3_plan_id, user: user)++ team_member_usage_row_text =+ conn+ |> get("/settings")+ |> html_response(200)+ |> text_of_element("#team-member-usage-row")++ assert team_member_usage_row_text == "Team members 0"+ end+test "redners 2FA section in disabled state", %{conn: conn} doconn = get(conn, "/settings")diff --git a/test/plausible_web/controllers/site/membership_controller_test.exs b/test/plausible_web/controllers/site/membership_controller_test.exsindex 7ada235bac..42dbaf634a 100644--- a/test/plausible_web/controllers/site/membership_controller_test.exs+++ b/test/plausible_web/controllers/site/membership_controller_test.exs@@ -21,6 +21,7 @@ defmodule PlausibleWeb.Site.MembershipControllerTest dorefute element_exists?(html, ~s/button[type=submit][disabled]/)end+ @tag :full_build_onlytest "disables invite form when is over limit", %{conn: conn, user: user} domemberships = [build(:site_membership, user: user, role: :owner) | build_list(5, :site_membership)@@ -53,6 +54,7 @@ defmodule PlausibleWeb.Site.MembershipControllerTest doassert redirected_to(conn) == "/#{URI.encode_www_form(site.domain)}/settings/people"end+ @tag :full_build_onlytest "fails to create invitation when is over limit", %{conn: conn, user: user} domemberships = [build(:site_membership, user: user, role: :owner) | build_list(5, :site_membership)diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exsindex 2bbceb9999..cc65ddb377 100644--- a/test/plausible_web/controllers/site_controller_test.exs+++ b/test/plausible_web/controllers/site_controller_test.exs@@ -8,6 +8,8 @@ defmodule PlausibleWeb.SiteControllerTest doimport Moximport Plausible.Test.Support.HTML+ @v4_business_plan_id "857105"+setup :verify_on_exit!describe "GET /sites/new" do@@ -302,7 +304,7 @@ defmodule PlausibleWeb.SiteControllerTest doconn: conn,user: user} do- insert_list(50, :site, members: [user])+ insert_list(10, :site, members: [user])conn =post(conn, "/sites", %{@@ -317,18 +319,15 @@ defmodule PlausibleWeb.SiteControllerTest dorefute Repo.get_by(Plausible.Site, domain: "over-limit.example.com")end- test "allows accounts registered before 2021-05-05 to go over the limit", %{+ test "does not limit accounts registered before 2021-05-05", %{conn: conn,user: user} do- Repo.update_all(from(u in "users", where: u.id == ^user.id),- set: [inserted_at: ~N[2020-01-01 00:00:00]]- )+ insert(:subscription, paddle_plan_id: @v4_business_plan_id, user: user)+ insert_list(51, :site, members: [user])- insert(:site, members: [user])- insert(:site, members: [user])- insert(:site, members: [user])- insert(:site, members: [user])+ Ecto.Changeset.change(user, %{inserted_at: ~N[2021-05-04 00:00:00]})+ |> Repo.update()conn =post(conn, "/sites", %{@@ -342,16 +341,13 @@ defmodule PlausibleWeb.SiteControllerTest doassert Repo.get_by(Plausible.Site, domain: "example.com")end- test "allows enterprise accounts to create unlimited sites", %{+ test "does not limit enterprise accounts", %{conn: conn,user: user} do- ep = insert(:enterprise_plan, user: user)+ ep = insert(:enterprise_plan, user: user, site_limit: 1)insert(:subscription, user: user, paddle_plan_id: ep.paddle_plan_id)-- insert(:site, members: [user])- insert(:site, members: [user])- insert(:site, members: [user])+ insert_list(2, :site, members: [user])conn =post(conn, "/sites", %{@@ -362,7 +358,7 @@ defmodule PlausibleWeb.SiteControllerTest do})assert redirected_to(conn) == "/example.com/snippet"- assert Repo.get_by(Plausible.Site, domain: "example.com")+ assert Plausible.Billing.Quota.site_usage(user) == 3endfor url <- ["https://Example.com/", "HTTPS://EXAMPLE.COM/", "/Example.com/", "//Example.com/"] do