Allow exemption list to be provided in config

This commit is contained in:
Uku Taht 2021-05-05 10:45:01 +03:00
parent 7f9057818d
commit c3b24342c6
2 changed files with 7 additions and 2 deletions

View File

@ -81,6 +81,7 @@ log_level = String.to_existing_atom(System.get_env("LOG_LEVEL", "warn"))
log_format = System.get_env("LOG_FORMAT", "elixir")
is_selfhost = String.to_existing_atom(System.get_env("SELFHOST", "true"))
{site_limit, ""} = Integer.parse(System.get_env("SITE_LIMIT", "20"))
no_limit_ids = System.get_env("NO_LIMIT_IDS", "") |> String.split(",") |> Enum.map(&String.trim/1)
disable_cron = String.to_existing_atom(System.get_env("DISABLE_CRON", "false"))
{user_agent_cache_limit, ""} = Integer.parse(System.get_env("USER_AGENT_CACHE_LIMIT", "1000"))
@ -96,6 +97,7 @@ config :plausible,
mailer_email: mailer_email,
admin_emails: admin_emails,
site_limit: site_limit,
no_limit_ids: no_limit_ids,
is_selfhost: is_selfhost
config :plausible, :selfhost,

View File

@ -193,11 +193,14 @@ defmodule Plausible.Billing do
grandfathering old accounts to unlimited websites and ignores site limit on self-hosted
installations.
"""
@limit_accounts_after ~D[2018-05-04]
@limit_accounts_since ~D[2018-05-05]
def sites_limit(user) do
no_limit_ids = Application.get_env(:plausible, :no_limit_ids)
cond do
Timex.before?(user.inserted_at, @limit_accounts_after) -> nil
Timex.before?(user.inserted_at, @limit_accounts_since) -> nil
Application.get_env(:plausible, :is_selfhost) -> nil
user.id in no_limit_ids -> nil
true -> Application.get_env(:plausible, :site_limit)
end
end