mirror of
https://github.com/plausible/analytics.git
synced 2024-09-11 18:07:33 +03:00
Bugfix: Allow breakdown by internally used prop keys for Growth plans (#3562)
* fix bug - allow internally used prop key breakdown for Growth plans * use case instead of with
This commit is contained in:
parent
be48ca2826
commit
ff2c3346d2
@ -96,6 +96,14 @@ defmodule Plausible.Props do
|
||||
"""
|
||||
def internal_keys, do: @internal_keys
|
||||
|
||||
def ensure_prop_key_accessible(prop_key, user) do
|
||||
if prop_key in @internal_keys do
|
||||
:ok
|
||||
else
|
||||
Plausible.Billing.Feature.Props.check_availability(user)
|
||||
end
|
||||
end
|
||||
|
||||
@spec suggest_keys_to_allow(Plausible.Site.t(), non_neg_integer()) :: [String.t()]
|
||||
@doc """
|
||||
Queries the events table to fetch the #{@max_props} most frequent prop keys
|
||||
|
@ -1185,8 +1185,9 @@ defmodule PlausibleWeb.Api.StatsController do
|
||||
|
||||
def custom_prop_values(conn, params) do
|
||||
site = Plausible.Repo.preload(conn.assigns.site, :owner)
|
||||
prop_key = Map.fetch!(params, "prop_key")
|
||||
|
||||
case Plausible.Billing.Feature.Props.check_availability(site.owner) do
|
||||
case Plausible.Props.ensure_prop_key_accessible(prop_key, site.owner) do
|
||||
:ok ->
|
||||
props = breakdown_custom_prop_values(site, params)
|
||||
json(conn, props)
|
||||
|
@ -177,17 +177,6 @@ defmodule PlausibleWeb.Api.StatsController.CustomPropBreakdownTest do
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
test "errors when site owner is on a growth plan", %{conn: conn, site: site, user: user} do
|
||||
insert(:growth_subscription, user: user)
|
||||
|
||||
conn = get(conn, "/api/stats/#{site.domain}/custom-prop-values/prop?period=day")
|
||||
|
||||
assert json_response(conn, 402) == %{
|
||||
"error" =>
|
||||
"Custom Properties is part of the Plausible Business plan. To get access to this feature, please upgrade your account."
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/stats/:domain/custom-prop-values/:prop_key - with goal filter" do
|
||||
@ -1058,4 +1047,42 @@ defmodule PlausibleWeb.Api.StatsController.CustomPropBreakdownTest do
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/stats/:domain/custom-prop-values/:prop_key - for a Growth subscription" do
|
||||
setup [:create_user, :log_in, :create_new_site]
|
||||
|
||||
setup %{user: user, site: site} do
|
||||
insert(:growth_subscription, user: user)
|
||||
|
||||
populate_stats(site, [
|
||||
build(:pageview,
|
||||
"meta.key": ["url", "path", "author"],
|
||||
"meta.value": ["one", "two", "three"]
|
||||
)
|
||||
])
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "returns breakdown for internally used prop keys", %{conn: conn, site: site} do
|
||||
[%{"visitors" => 1, "name" => "one"}] =
|
||||
conn
|
||||
|> get("/api/stats/#{site.domain}/custom-prop-values/url?period=day")
|
||||
|> json_response(200)
|
||||
|
||||
[%{"visitors" => 1, "name" => "two"}] =
|
||||
conn
|
||||
|> get("/api/stats/#{site.domain}/custom-prop-values/path?period=day")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "returns 402 'upgrade required' for any other prop key", %{conn: conn, site: site} do
|
||||
conn = get(conn, "/api/stats/#{site.domain}/custom-prop-values/prop?period=day")
|
||||
|
||||
assert json_response(conn, 402) == %{
|
||||
"error" =>
|
||||
"Custom Properties is part of the Plausible Business plan. To get access to this feature, please upgrade your account."
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user