Warn user about Stats API when downgrading (#3471)

* Warn user about Stats API when downgrading

* Update test/plausible/billing/quota_test.exs

Co-authored-by: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com>

---------

Co-authored-by: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com>
This commit is contained in:
Vini Brasil 2023-10-31 14:57:21 -03:00 committed by GitHub
parent 3c76053c3f
commit 3b28a8d418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 4 deletions

View File

@ -6,7 +6,7 @@ defmodule Plausible.Billing.Quota do
import Ecto.Query
alias Plausible.Billing
alias 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 \\ []) do
basic_usage = %{
@ -177,10 +177,13 @@ defmodule Plausible.Billing.Quota do
on: 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 ->

View File

@ -426,6 +426,13 @@ defmodule Plausible.Billing.QuotaTest do
assert [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" do
user = insert(:user)

View File

@ -438,14 +438,15 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
test "warns about losing access to a feature", %{conn: conn, user: user} do
site = 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()}"
end
end