Skip to content

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

List only premium features on the CRM (#3530)

Vinicius Brasil0175158e8101
diff --git a/lib/plausible/billing/ecto/feature.ex b/lib/plausible/billing/ecto/feature.ex
index 98ac24e8c5..a1356f2e7c 100644
--- a/lib/plausible/billing/ecto/feature.ex
+++ b/lib/plausible/billing/ecto/feature.ex
@@ -49,7 +49,7 @@ defmodule Plausible.Billing.Ecto.FeatureList do
features = Ecto.Changeset.get_field(changeset, field)
checkboxes =
- for mod <- Plausible.Billing.Feature.list() do
+ for mod <- Plausible.Billing.Feature.list(), not mod.free?() do
[
{:safe, ~s(<label style="padding-right: 15px;">)},
Phoenix.HTML.Tag.tag(
diff --git a/lib/plausible/billing/feature.ex b/lib/plausible/billing/feature.ex
index 3c5ed0b47c..16008950bc 100644
--- a/lib/plausible/billing/feature.ex
+++ b/lib/plausible/billing/feature.ex
@@ -38,6 +38,11 @@ defmodule Plausible.Billing.Feature do
"""
@callback toggle_field() :: atom()
+ @doc """
+ Returns whether the feature is free to use or not.
+ """
+ @callback free?() :: boolean()
+
@doc """
Toggles the feature on and off for a site. Returns
`{:error, :upgrade_required}` when toggling a feature the site owner does not
@@ -87,6 +92,9 @@ defmodule Plausible.Billing.Feature do
@impl true
def toggle_field, do: Keyword.get(unquote(opts), :toggle_field)
+ @impl true
+ def free?, do: Keyword.get(unquote(opts), :free, false)
+
@impl true
def enabled?(%Plausible.Site{} = site) do
site = Plausible.Repo.preload(site, :owner)
@@ -101,7 +109,7 @@ defmodule Plausible.Billing.Feature do
@impl true
def check_availability(%Plausible.Auth.User{} = user) do
cond do
- Keyword.get(unquote(opts), :free) -> :ok
+ free?() -> :ok
__MODULE__ in Quota.allowed_features_for(user) -> :ok
true -> {:error, :upgrade_required}
end