Skip to content

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

Plugins API: allow prop enable for internal keys (always) (#5302)

hq159fa96863f71
diff --git a/lib/plausible/props.ex b/lib/plausible/props.ex
index da1d9054b5..be74acb324 100644
--- a/lib/plausible/props.ex
+++ b/lib/plausible/props.ex
@@ -79,7 +79,7 @@ defmodule Plausible.Props do
"""
def allow(site, prop_or_props) do
with site <- Plausible.Repo.preload(site, :team),
- :ok <- Plausible.Billing.Feature.Props.check_availability(site.team) do
+ :ok <- ensure_prop_key_accessible(prop_or_props, site.team) do
site
|> allow_changeset(prop_or_props)
|> Plausible.Repo.update()
@@ -139,6 +139,15 @@ defmodule Plausible.Props do
allow(site, props_to_allow)
end
+ def ensure_prop_key_accessible(prop_keys, team) when is_list(prop_keys) do
+ Enum.reduce_while(prop_keys, :ok, fn prop_key, :ok ->
+ case ensure_prop_key_accessible(prop_key, team) do
+ :ok -> {:cont, :ok}
+ error -> {:halt, error}
+ end
+ end)
+ end
+
def ensure_prop_key_accessible(prop_key, team) do
if prop_key in @internal_keys do
:ok
diff --git a/test/plausible_web/plugins/api/controllers/custom_props_test.exs b/test/plausible_web/plugins/api/controllers/custom_props_test.exs
index 12589c5dd1..3ba556d55c 100644
--- a/test/plausible_web/plugins/api/controllers/custom_props_test.exs
+++ b/test/plausible_web/plugins/api/controllers/custom_props_test.exs
@@ -37,6 +37,60 @@ defmodule PlausibleWeb.Plugins.API.Controllers.CustomPropsTest do
describe "business tier" do
@describetag :ee_only
+
+ test "allows prop enable for special key", %{
+ site: site,
+ token: token,
+ conn: conn
+ } do
+ [owner | _] = Plausible.Repo.preload(site, :owners).owners
+ subscribe_to_growth_plan(owner)
+
+ url = Routes.plugins_api_custom_props_url(PlausibleWeb.Endpoint, :enable)
+
+ payload = %{
+ custom_prop: %{key: "search_query"}
+ }
+
+ assert_request_schema(payload, "CustomProp.EnableRequest", spec())
+
+ conn
+ |> authenticate(site.domain, token)
+ |> put_req_header("content-type", "application/json")
+ |> put(url, payload)
+ |> json_response(201)
+ |> assert_schema("CustomProp.ListResponse", spec())
+ end
+
+ test "allows bulk prop enable for special keys", %{
+ site: site,
+ token: token,
+ conn: conn
+ } do
+ [owner | _] = Plausible.Repo.preload(site, :owners).owners
+ subscribe_to_growth_plan(owner)
+
+ url = Routes.plugins_api_custom_props_url(PlausibleWeb.Endpoint, :enable)
+
+ payload = %{
+ custom_props: [
+ %{
+ custom_prop: %{key: "search_query"}
+ },
+ %{
+ custom_prop: %{key: "url"}
+ }
+ ]
+ }
+
+ conn
+ |> authenticate(site.domain, token)
+ |> put_req_header("content-type", "application/json")
+ |> put(url, payload)
+ |> json_response(201)
+ |> assert_schema("CustomProp.ListResponse", spec())
+ end
+
test "fails on custom prop enable attempt with insufficient plan", %{
site: site,
token: token,
@@ -76,6 +130,9 @@ defmodule PlausibleWeb.Plugins.API.Controllers.CustomPropsTest do
%{
custom_prop: %{key: "author"}
},
+ %{
+ custom_prop: %{key: "search_query"}
+ },
%{
custom_prop: %{key: "category"}
}