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
Warn user about Stats API when downgrading (#3471)
Vini Brasil3b28a8d418f0
diff --git a/lib/plausible/billing/quota.ex b/lib/plausible/billing/quota.exindex cc5c6f37cc..d11f7333e4 100644--- a/lib/plausible/billing/quota.ex+++ b/lib/plausible/billing/quota.ex@@ -6,7 +6,7 @@ defmodule Plausible.Billing.Quota doimport Ecto.Queryalias Plausible.Billingalias Plausible.Billing.{Plan, Plans, Subscription, EnterprisePlan, Feature}- alias Plausible.Billing.Feature.{Goals, RevenueGoals, Funnels, Props}+ alias Plausible.Billing.Feature.{Goals, RevenueGoals, Funnels, Props, StatsAPI}def usage(user, opts \\ []) dobasic_usage = %{@@ -177,10 +177,13 @@ defmodule Plausible.Billing.Quota doon: g.site_id == os.site_id,where: not is_nil(g.currency)+ stats_api_usage = from a in Plausible.Auth.ApiKey, where: a.user_id == ^user.id+queries = [{Props, props_usage_query},{Funnels, funnels_usage_query},- {RevenueGoals, revenue_goals_usage}+ {RevenueGoals, revenue_goals_usage},+ {StatsAPI, stats_api_usage}]Enum.reduce(queries, [], fn {feature, query}, acc ->diff --git a/test/plausible/billing/quota_test.exs b/test/plausible/billing/quota_test.exsindex c16e6e9c5e..157be54b34 100644--- a/test/plausible/billing/quota_test.exs+++ b/test/plausible/billing/quota_test.exs@@ -426,6 +426,13 @@ defmodule Plausible.Billing.QuotaTest doassert [RevenueGoals] == Quota.features_usage(user)end+ test "returns [StatsAPI] when user has a stats api key" do+ user = insert(:user)+ insert(:api_key, user: user)++ assert [StatsAPI] == Quota.features_usage(user)+ end+test "returns multiple features" douser = insert(:user)diff --git a/test/plausible_web/live/choose_plan_test.exs b/test/plausible_web/live/choose_plan_test.exsindex 938d857e86..f2c34a1642 100644--- a/test/plausible_web/live/choose_plan_test.exs+++ b/test/plausible_web/live/choose_plan_test.exs@@ -438,14 +438,15 @@ defmodule PlausibleWeb.Live.ChoosePlanTest dotest "warns about losing access to a feature", %{conn: conn, user: user} dosite = insert(:site, members: [user])- Plausible.Props.allow(site, ["author"])+ Plausible.Props.allow(site, ["author"])insert(:goal, currency: :USD, site: site, event_name: "Purchase")+ insert(:api_key, user: user){:ok, _lv, doc} = get_liveview(conn)assert text_of_attr(find(doc, @growth_checkout_button), "onclick") =~- "if (!confirm(\"This plan does not support Custom Properties and Revenue Goals, which you are currently using. Please note that by subscribing to this plan you will lose access to these features.\")) {e.preventDefault()}"+ "if (!confirm(\"This plan does not support Custom Properties, Revenue Goals and Stats API, which you are currently using. Please note that by subscribing to this plan you will lose access to these features.\")) {e.preventDefault()}"endend