From d6824de1adc4df5cdd421257a4e98bc1b8612baf Mon Sep 17 00:00:00 2001 From: hq1 Date: Mon, 29 Apr 2024 08:05:33 +0200 Subject: [PATCH] Rename internal build symbols (#3942) * Rename internal build symbols * Rename remaining + add `on_ce` macro cc @ruslandoga --- .../workflows/build-public-images-ghcr.yml | 2 +- .github/workflows/build-public-images.yml | 2 +- .github/workflows/elixir.yml | 4 +- Dockerfile | 4 +- config/{small.exs => ce.exs} | 0 config/{small_dev.exs => ce_dev.exs} | 0 config/{small_test.exs => ce_test.exs} | 0 config/runtime.exs | 4 +- lib/plausible.ex | 58 +++++++++++-------- lib/plausible/application.ex | 2 +- lib/plausible/auth/auth.ex | 2 +- lib/plausible/auth/user.ex | 4 +- lib/plausible/auth/user_admin.ex | 2 +- lib/plausible/billing/quota.ex | 6 +- lib/plausible/exports.ex | 2 +- lib/plausible/goal/schema.ex | 6 +- lib/plausible/goals.ex | 6 +- lib/plausible/ingestion/event.ex | 2 +- lib/plausible/ingestion/request.ex | 4 +- lib/plausible/plugins/api/token.ex | 2 +- lib/plausible/s3.ex | 2 +- .../site/memberships/accept_invitation.ex | 2 +- lib/plausible/site/memberships/invitations.ex | 2 +- lib/plausible/stats.ex | 2 +- lib/plausible/stats/aggregate.ex | 4 +- lib/plausible/stats/base.ex | 6 +- lib/plausible/stats/breakdown.ex | 8 +-- lib/plausible/stats/clickhouse.ex | 8 +-- lib/plausible/stats/metrics.ex | 2 +- lib/plausible/stats/query.ex | 2 +- lib/plausible/stats/timeseries.ex | 4 +- lib/plausible/users.ex | 4 +- lib/plausible_release.ex | 2 +- .../controllers/api/stats_controller.ex | 10 ++-- .../controllers/site_controller.ex | 2 +- .../controllers/stats_controller.ex | 4 +- lib/plausible_web/email.ex | 4 +- lib/plausible_web/endpoint.ex | 4 +- lib/plausible_web/live/goal_settings/form.ex | 4 +- lib/plausible_web/live/register_form.ex | 6 +- lib/plausible_web/live/sites.ex | 2 +- lib/plausible_web/router.ex | 20 +++---- .../templates/auth/activate.html.heex | 2 +- .../password_reset_request_success.html.heex | 4 +- .../templates/auth/user_settings.html.heex | 2 +- .../templates/auth/verify_2fa.html.heex | 2 +- .../auth/verify_2fa_recovery_code.html.heex | 2 +- .../templates/email/csv_import.html.heex | 2 +- .../templates/email/export_failure.html.eex | 4 +- .../templates/email/export_success.html.eex | 2 +- .../email/google_analytics_import.html.heex | 2 +- .../templates/error/server_error.html.heex | 6 +- .../templates/layout/_footer.html.heex | 4 +- .../templates/layout/_header.html.heex | 6 +- .../templates/layout/_tracking.html.heex | 2 +- .../templates/layout/base_email.html.eex | 4 +- .../templates/layout/priority_email.html.eex | 2 +- .../templates/site/csv_import.html.heex | 2 +- .../templates/site/settings_goals.html.heex | 2 +- .../site/settings_imports_exports.html.heex | 2 +- .../stats/waiting_first_pageview.html.heex | 4 +- lib/plausible_web/views/error_view.ex | 2 +- lib/plausible_web/views/layout_view.ex | 4 +- lib/workers/clickhouse_clean_sites.ex | 2 +- mix.exs | 22 +++---- test/plausible/auth/users_test.exs | 4 +- test/plausible/billing/billing_test.exs | 6 +- test/plausible/billing/plans_test.exs | 2 +- test/plausible/billing/quota_test.exs | 14 ++--- test/plausible/funnels_test.exs | 4 +- test/plausible/goals_test.exs | 12 ++-- test/plausible/imported/csv_importer_test.exs | 26 ++++----- test/plausible/ingestion/event_test.exs | 2 +- test/plausible/ingestion/request_test.exs | 12 ++-- test/plausible/plugins/api/token_test.exs | 10 ++-- test/plausible/release_test.exs | 8 +-- test/plausible/site/admin_test.exs | 2 +- test/plausible/site/cache_test.exs | 4 +- .../memberships/accept_invitation_test.exs | 22 +++---- .../memberships/create_invitation_test.exs | 14 ++--- test/plausible/site/sites_test.exs | 2 +- test/plausible/stats/query_test.exs | 4 +- .../components/billing/notice_test.exs | 6 +- .../admin_auth_controller_test.exs | 2 +- .../controllers/admin_controller_test.exs | 4 +- .../api/external_controller_test.exs | 6 +- .../api/external_sites_controller_test.exs | 2 +- .../external_stats_controller/auth_test.exs | 2 +- .../api/internal_controller/sync_test.exs | 2 +- .../api/stats_controller/conversions_test.exs | 6 +- .../custom_prop_breakdown_test.exs | 4 +- .../api/stats_controller/funnels_test.exs | 4 +- .../api/stats_controller/main_graph_test.exs | 4 +- .../api/stats_controller/top_stats_test.exs | 4 +- .../controllers/auth_controller_sync_test.exs | 2 +- .../controllers/auth_controller_test.exs | 46 +++++++-------- .../error_report_controller_test.exs | 2 +- .../invitation_controller_test.exs | 4 +- .../site/membership_controller_test.exs | 4 +- .../controllers/site_controller_test.exs | 2 +- .../controllers/stats_controller_test.exs | 2 +- test/plausible_web/email_test.exs | 2 +- test/plausible_web/live/choose_plan_test.exs | 2 +- .../live/funnel_settings/form_test.exs | 2 +- .../live/funnel_settings_test.exs | 4 +- .../live/goal_settings/form_test.exs | 8 +-- .../plausible_web/live/goal_settings_test.exs | 4 +- .../plausible_web/live/register_form_test.exs | 4 +- test/plausible_web/live/sites_test.exs | 6 +- .../api/controllers/custom_props_test.exs | 2 +- .../plugins/api/controllers/goals_test.exs | 20 +++---- .../plugs/first_launch_plug_test.exs | 2 +- test/test_helper.exs | 10 ++-- test/workers/accept_traffic_until_test.exs | 2 +- 114 files changed, 317 insertions(+), 309 deletions(-) rename config/{small.exs => ce.exs} (100%) rename config/{small_dev.exs => ce_dev.exs} (100%) rename config/{small_test.exs => ce_test.exs} (100%) diff --git a/.github/workflows/build-public-images-ghcr.yml b/.github/workflows/build-public-images-ghcr.yml index 0fdbba79c..7794b31c2 100644 --- a/.github/workflows/build-public-images-ghcr.yml +++ b/.github/workflows/build-public-images-ghcr.yml @@ -51,7 +51,7 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max build-args: | - MIX_ENV=small + MIX_ENV=ce BUILD_METADATA=${{ steps.meta.outputs.json }} ERL_FLAGS=+JPperf true diff --git a/.github/workflows/build-public-images.yml b/.github/workflows/build-public-images.yml index 0d12f6331..e88c932b9 100644 --- a/.github/workflows/build-public-images.yml +++ b/.github/workflows/build-public-images.yml @@ -46,7 +46,7 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max build-args: | - MIX_ENV=small + MIX_ENV=ce BUILD_METADATA=${{ steps.meta.outputs.json }} ERL_FLAGS=+JMsingle true diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index 5655b33b1..05a4ff0cf 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - mix_env: ["test", "small_test"] + mix_env: ["test", "ce_test"] postgres_image: ["postgres:16"] test_experimental_reduced_joins: ["0"] @@ -113,7 +113,7 @@ jobs: MINIO_HOST_FOR_CLICKHOUSE: "172.17.0.1" - run: mix test --include slow --max-failures 1 --warnings-as-errors - if: env.MIX_ENV == 'small_test' + if: env.MIX_ENV == 'ce_test' static: name: Static checks (format, credo, dialyzer) diff --git a/Dockerfile b/Dockerfile index 5915fe3cc..617d10e30 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ #### Builder FROM hexpm/elixir:1.16.0-erlang-26.2.1-alpine-3.18.4 as buildcontainer -ARG MIX_ENV=small +ARG MIX_ENV=ce # preparation ENV MIX_ENV=$MIX_ENV @@ -60,7 +60,7 @@ LABEL maintainer="plausible.io " ARG BUILD_METADATA={} ENV BUILD_METADATA=$BUILD_METADATA ENV LANG=C.UTF-8 -ARG MIX_ENV=small +ARG MIX_ENV=ce ENV MIX_ENV=$MIX_ENV RUN adduser -S -H -u 999 -G nogroup plausible -g 'Plausible Analytics' diff --git a/config/small.exs b/config/ce.exs similarity index 100% rename from config/small.exs rename to config/ce.exs diff --git a/config/small_dev.exs b/config/ce_dev.exs similarity index 100% rename from config/small_dev.exs rename to config/ce_dev.exs diff --git a/config/small_test.exs b/config/ce_test.exs similarity index 100% rename from config/small_test.exs rename to config/ce_test.exs diff --git a/config/runtime.exs b/config/runtime.exs index 2f43f0b48..2bec1d0f1 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -6,11 +6,11 @@ if config_env() in [:dev, :test] do Envy.load(["config/.env.#{config_env()}"]) end -if config_env() == :small_dev do +if config_env() == :ce_dev do Envy.load(["config/.env.dev"]) end -if config_env() == :small_test do +if config_env() == :ce_test do Envy.load(["config/.env.test"]) end diff --git a/lib/plausible.ex b/lib/plausible.ex index a8fe326fa..e853b470d 100644 --- a/lib/plausible.ex +++ b/lib/plausible.ex @@ -3,7 +3,7 @@ defmodule Plausible do Build-related macros """ - @small_builds [:small, :small_test, :small_dev] + @ce_builds [:ce, :ce_test, :ce_dev] defmacro __using__(_) do quote do @@ -12,16 +12,42 @@ defmodule Plausible do end end - defmacro on_full_build(clauses) do - do_on_full_build(clauses) + defmacro on_ee(clauses) do + do_on_ee(clauses) end - def do_on_full_build(do: block) do - do_on_full_build(do: block, else: nil) + defmacro on_ce(clauses) do + do_on_ce(clauses) end - def do_on_full_build(do: do_block, else: else_block) do - if Mix.env() not in @small_builds do + defmacro ee?() do + ee? = Mix.env() not in @ce_builds + + # Tricking dialyzer as per: + # https://github.com/elixir-lang/elixir/blob/v1.12.3/lib/elixir/lib/gen_server.ex#L771-L778 + quote do + :erlang.phash2(1, 1) == 0 and unquote(ee?) + end + end + + defmacro ce?() do + ce_build? = Mix.env() in @ce_builds + + quote do + unquote(ce_build?) + end + end + + defp do_on_ce(do: block) do + do_on_ee(do: nil, else: block) + end + + defp do_on_ee(do: block) do + do_on_ee(do: block, else: nil) + end + + defp do_on_ee(do: do_block, else: else_block) do + if Mix.env() not in @ce_builds do quote do unquote(do_block) end @@ -31,22 +57,4 @@ defmodule Plausible do end end end - - defmacro full_build?() do - full_build? = Mix.env() not in @small_builds - - # Tricking dialyzer as per: - # https://github.com/elixir-lang/elixir/blob/v1.12.3/lib/elixir/lib/gen_server.ex#L771-L778 - quote do - :erlang.phash2(1, 1) == 0 and unquote(full_build?) - end - end - - defmacro small_build?() do - small_build? = Mix.env() in @small_builds - - quote do - unquote(small_build?) - end - end end diff --git a/lib/plausible/application.ex b/lib/plausible/application.ex index 2d219ce54..5ed3beaa1 100644 --- a/lib/plausible/application.ex +++ b/lib/plausible/application.ex @@ -7,7 +7,7 @@ defmodule Plausible.Application do require Logger def start(_type, _args) do - on_full_build(do: Plausible.License.ensure_valid_license()) + on_ee(do: Plausible.License.ensure_valid_license()) children = [ Plausible.Cache.Stats, diff --git a/lib/plausible/auth/auth.ex b/lib/plausible/auth/auth.ex index 41cc124f8..4eaf5df78 100644 --- a/lib/plausible/auth/auth.ex +++ b/lib/plausible/auth/auth.ex @@ -57,7 +57,7 @@ defmodule Plausible.Auth do ) end - on_full_build do + on_ee do def is_super_admin?(nil), do: false def is_super_admin?(%Plausible.Auth.User{id: id}), do: is_super_admin?(id) diff --git a/lib/plausible/auth/user.ex b/lib/plausible/auth/user.ex index 80fa87992..03f288121 100644 --- a/lib/plausible/auth/user.ex +++ b/lib/plausible/auth/user.ex @@ -252,7 +252,7 @@ defmodule Plausible.Auth.User do end defp trial_expiry() do - on_full_build do + on_ee do Timex.today() |> Timex.shift(days: 30) else Timex.today() |> Timex.shift(years: 100) @@ -260,7 +260,7 @@ defmodule Plausible.Auth.User do end defp set_email_verification_status(user) do - on_full_build do + on_ee do change(user, email_verified: false) else selfhosted_config = Application.get_env(:plausible, :selfhost) diff --git a/lib/plausible/auth/user_admin.ex b/lib/plausible/auth/user_admin.ex index e8173d2a3..dd9bf98fb 100644 --- a/lib/plausible/auth/user_admin.ex +++ b/lib/plausible/auth/user_admin.ex @@ -134,7 +134,7 @@ defmodule Plausible.Auth.UserAdmin do end end - on_full_build do + on_ee do defp usage_link(user) do path = PlausibleWeb.Router.Helpers.admin_path(PlausibleWeb.Endpoint, :usage, user.id) {:safe, ~s(Usage)} diff --git a/lib/plausible/billing/quota.ex b/lib/plausible/billing/quota.ex index cd8a10446..a6505e5df 100644 --- a/lib/plausible/billing/quota.ex +++ b/lib/plausible/billing/quota.ex @@ -45,7 +45,7 @@ defmodule Plausible.Billing.Quota do end end - on_full_build do + on_ee do @limit_sites_since ~D[2021-05-05] @site_limit_for_trials 10 @team_member_limit_for_trials 3 @@ -349,7 +349,7 @@ defmodule Plausible.Billing.Quota do stats_api_usage = from a in Plausible.Auth.ApiKey, where: a.user_id == ^user.id queries = - on_full_build do + on_ee do funnels_usage_query = from f in "funnels", inner_join: os in subquery(owned_sites_query(user)), @@ -378,7 +378,7 @@ defmodule Plausible.Billing.Quota do props_exist = is_list(site.allowed_event_props) && site.allowed_event_props != [] funnels_exist = - on_full_build do + on_ee do Plausible.Repo.exists?(from f in Plausible.Funnel, where: f.site_id == ^site.id) else false diff --git a/lib/plausible/exports.ex b/lib/plausible/exports.ex index 00b7e4dc4..078e62c41 100644 --- a/lib/plausible/exports.ex +++ b/lib/plausible/exports.ex @@ -254,7 +254,7 @@ defmodule Plausible.Exports do } end - on_full_build do + on_ee do defp sampled(table, date_range) do from(table) |> Plausible.Stats.Sampling.add_query_hint() diff --git a/lib/plausible/goal/schema.ex b/lib/plausible/goal/schema.ex index b4c0967bb..99e335f95 100644 --- a/lib/plausible/goal/schema.ex +++ b/lib/plausible/goal/schema.ex @@ -9,7 +9,7 @@ defmodule Plausible.Goal do field :event_name, :string field :page_path, :string - on_full_build do + on_ee do field :currency, Ecto.Enum, values: Money.Currency.known_current_currencies() many_to_many :funnels, Plausible.Funnel, join_through: Plausible.Funnel.Step else @@ -22,7 +22,7 @@ defmodule Plausible.Goal do timestamps() end - @fields [:id, :site_id, :event_name, :page_path] ++ on_full_build(do: [:currency], else: []) + @fields [:id, :site_id, :event_name, :page_path] ++ on_ee(do: [:currency], else: []) def changeset(goal, attrs \\ %{}) do goal @@ -77,7 +77,7 @@ defmodule Plausible.Goal do end defp maybe_drop_currency(changeset) do - if full_build?() and get_field(changeset, :page_path) do + if ee?() and get_field(changeset, :page_path) do delete_change(changeset, :currency) else changeset diff --git a/lib/plausible/goals.ex b/lib/plausible/goals.ex index 11118ff84..a0b2f8a3a 100644 --- a/lib/plausible/goals.ex +++ b/lib/plausible/goals.ex @@ -22,7 +22,7 @@ defmodule Plausible.Goals do Repo.transaction(fn -> case insert_goal(site, params, upsert?) do {:ok, :insert, goal} -> - on_full_build do + on_ee do now = Keyword.get(opts, :now, DateTime.utc_now()) # credo:disable-for-next-line Credo.Check.Refactor.Nesting if Plausible.Goal.Revenue.revenue?(goal) do @@ -103,7 +103,7 @@ defmodule Plausible.Goals do order_by: [desc: g.id], preload: [:site] - if opts[:preload_funnels?] == true and full_build?() do + if opts[:preload_funnels?] == true and ee?() do from(g in query, left_join: assoc(g, :funnels), group_by: g.id, @@ -136,7 +136,7 @@ defmodule Plausible.Goals do where: g.site_id == ^site_id ) - goal_query = on_full_build(do: preload(goal_query, funnels: :steps), else: goal_query) + goal_query = on_ee(do: preload(goal_query, funnels: :steps), else: goal_query) result = Multi.new() diff --git a/lib/plausible/ingestion/event.ex b/lib/plausible/ingestion/event.ex index 8baf66a92..ec3653b02 100644 --- a/lib/plausible/ingestion/event.ex +++ b/lib/plausible/ingestion/event.ex @@ -292,7 +292,7 @@ defmodule Plausible.Ingestion.Event do defp put_props(%__MODULE__{} = event), do: event defp put_revenue(event) do - on_full_build do + on_ee do attrs = Plausible.Ingestion.Event.Revenue.get_revenue_attrs(event) update_event_attrs(event, attrs) else diff --git a/lib/plausible/ingestion/request.ex b/lib/plausible/ingestion/request.ex index c5f6818e4..fa2218611 100644 --- a/lib/plausible/ingestion/request.ex +++ b/lib/plausible/ingestion/request.ex @@ -42,7 +42,7 @@ defmodule Plausible.Ingestion.Request do field :pathname, :string field :props, :map - on_full_build do + on_ee do field :revenue_source, :map end @@ -95,7 +95,7 @@ defmodule Plausible.Ingestion.Request do end end - on_full_build do + on_ee do defp put_revenue_source(changeset, request_body) do Plausible.Ingestion.Request.Revenue.put_revenue_source(changeset, request_body) end diff --git a/lib/plausible/plugins/api/token.ex b/lib/plausible/plugins/api/token.ex index 4f64ccbe8..7fe3c2f2d 100644 --- a/lib/plausible/plugins/api/token.ex +++ b/lib/plausible/plugins/api/token.ex @@ -64,7 +64,7 @@ defmodule Plausible.Plugins.API.Token do can scan repositories for accidental secret commits. """ def prefix() do - on_full_build do + on_ee do env = Application.get_env(:plausible, :environment) case env do diff --git a/lib/plausible/s3.ex b/lib/plausible/s3.ex index 3db53297b..2cf3ae1d4 100644 --- a/lib/plausible/s3.ex +++ b/lib/plausible/s3.ex @@ -58,7 +58,7 @@ defmodule Plausible.S3 do # to make ClickHouse see MinIO in dev and test envs we replace # the host in the S3 URL with host.docker.internal or whatever's set in $MINIO_HOST_FOR_CLICKHOUSE - if Mix.env() in [:dev, :test, :small_dev, :small_test] do + if Mix.env() in [:dev, :test, :ce_dev, :ce_test] do defp extract_s3_url(presigned_url) do [s3_url, _] = String.split(presigned_url, "?") default_ch_host = unless System.get_env("CI"), do: "host.docker.internal" diff --git a/lib/plausible/site/memberships/accept_invitation.ex b/lib/plausible/site/memberships/accept_invitation.ex index 44f9e20ac..bffe63105 100644 --- a/lib/plausible/site/memberships/accept_invitation.ex +++ b/lib/plausible/site/memberships/accept_invitation.ex @@ -106,7 +106,7 @@ defmodule Plausible.Site.Memberships.AcceptInvitation do |> downgrade_previous_owner(site, user) |> Multi.insert_or_update(:membership, membership) |> Multi.run(:update_locked_sites, fn _, _ -> - on_full_build do + on_ee do # At this point this function should be guaranteed to unlock # the site, via `Invitations.ensure_can_take_ownership/2`. :unlocked = Billing.SiteLocker.update_sites_for(user, send_email?: false) diff --git a/lib/plausible/site/memberships/invitations.ex b/lib/plausible/site/memberships/invitations.ex index 5c2bbe453..c8569aad3 100644 --- a/lib/plausible/site/memberships/invitations.ex +++ b/lib/plausible/site/memberships/invitations.ex @@ -64,7 +64,7 @@ defmodule Plausible.Site.Memberships.Invitations do :ok end - on_full_build do + on_ee do @spec ensure_can_take_ownership(Site.t(), Auth.User.t()) :: :ok | {:error, Quota.over_limits_error() | :no_plan} def ensure_can_take_ownership(site, new_owner) do diff --git a/lib/plausible/stats.ex b/lib/plausible/stats.ex index b37e8fe77..3a5f33a7b 100644 --- a/lib/plausible/stats.ex +++ b/lib/plausible/stats.ex @@ -31,7 +31,7 @@ defmodule Plausible.Stats do CurrentVisitors.current_visitors(site) end - on_full_build do + on_ee do def funnel(site, query, funnel) do include_sentry_replay_info() Plausible.Stats.Funnel.funnel(site, query, funnel) diff --git a/lib/plausible/stats/aggregate.ex b/lib/plausible/stats/aggregate.ex index 45e3010d7..27d4290b0 100644 --- a/lib/plausible/stats/aggregate.ex +++ b/lib/plausible/stats/aggregate.ex @@ -7,7 +7,7 @@ defmodule Plausible.Stats.Aggregate do def aggregate(site, query, metrics) do {currency, metrics} = - on_full_build do + on_ee do Plausible.Stats.Goal.Revenue.get_revenue_tracking_currency(site, query, metrics) else {nil, metrics} @@ -200,7 +200,7 @@ defmodule Plausible.Stats.Aggregate do defp maybe_round_value(entry), do: entry - on_full_build do + on_ee do defp cast_revenue_metrics_to_money(results, revenue_goals) do Plausible.Stats.Goal.Revenue.cast_revenue_metrics_to_money(results, revenue_goals) end diff --git a/lib/plausible/stats/base.ex b/lib/plausible/stats/base.ex index 923ab53b3..50ecc6963 100644 --- a/lib/plausible/stats/base.ex +++ b/lib/plausible/stats/base.ex @@ -48,7 +48,7 @@ defmodule Plausible.Stats.Base do where: e.timestamp >= ^first_datetime and e.timestamp < ^last_datetime ) - on_full_build do + on_ee do q = Plausible.Stats.Sampling.add_query_hint(q, query) end @@ -142,7 +142,7 @@ defmodule Plausible.Stats.Base do from s in q, where: s.start >= ^first_datetime and s.start < ^last_datetime end - on_full_build do + on_ee do sessions_q = Plausible.Stats.Sampling.add_query_hint(sessions_q, query) end @@ -254,7 +254,7 @@ defmodule Plausible.Stats.Base do } end - on_full_build do + on_ee do defp select_event_metric(:total_revenue) do %{total_revenue: Plausible.Stats.Goal.Revenue.total_revenue_query()} end diff --git a/lib/plausible/stats/breakdown.ex b/lib/plausible/stats/breakdown.ex index 9eb64bab2..e2b0b4066 100644 --- a/lib/plausible/stats/breakdown.ex +++ b/lib/plausible/stats/breakdown.ex @@ -13,7 +13,7 @@ defmodule Plausible.Stats.Breakdown do @session_metrics [:bounce_rate, :visit_duration] - @revenue_metrics on_full_build(do: Plausible.Stats.Goal.Revenue.revenue_metrics(), else: []) + @revenue_metrics on_ee(do: Plausible.Stats.Goal.Revenue.revenue_metrics(), else: []) @event_metrics [:visits, :visitors, :pageviews, :events, :percentage] ++ @revenue_metrics @@ -38,7 +38,7 @@ defmodule Plausible.Stats.Breakdown do no_revenue = {nil, metrics -- @revenue_metrics} {revenue_goals, metrics} = - on_full_build do + on_ee do if Plausible.Billing.Feature.RevenueGoals.enabled?(site) do revenue_goals = Enum.filter(event_goals, &Plausible.Goal.Revenue.revenue?/1) metrics = if Enum.empty?(revenue_goals), do: metrics -- @revenue_metrics, else: metrics @@ -122,7 +122,7 @@ defmodule Plausible.Stats.Breakdown do def breakdown(site, query, "event:props:" <> custom_prop = property, metrics, pagination, opts) do {currency, metrics} = - on_full_build do + on_ee do Plausible.Stats.Goal.Revenue.get_revenue_tracking_currency(site, query, metrics) else {nil, metrics} @@ -758,7 +758,7 @@ defmodule Plausible.Stats.Breakdown do ]) end - on_full_build do + on_ee do defp cast_revenue_metrics_to_money(results, revenue_goals) do Plausible.Stats.Goal.Revenue.cast_revenue_metrics_to_money(results, revenue_goals) end diff --git a/lib/plausible/stats/clickhouse.ex b/lib/plausible/stats/clickhouse.ex index 139e92e99..52d2e889c 100644 --- a/lib/plausible/stats/clickhouse.ex +++ b/lib/plausible/stats/clickhouse.ex @@ -113,7 +113,7 @@ defmodule Plausible.Stats.Clickhouse do offset: ^offset ) - on_full_build do + on_ee do referrers = Plausible.Stats.Sampling.add_query_hint(referrers, 10_000_000) end @@ -193,7 +193,7 @@ defmodule Plausible.Stats.Clickhouse do order_by: [e.site_id, fragment("toStartOfHour(timestamp)")] ) - on_full_build do + on_ee do current_q = Plausible.Stats.Sampling.add_query_hint(current_q) end @@ -231,7 +231,7 @@ defmodule Plausible.Stats.Clickhouse do }, group_by: [e.site_id] - on_full_build do + on_ee do query = Plausible.Stats.Sampling.add_query_hint(query) end @@ -260,7 +260,7 @@ defmodule Plausible.Stats.Clickhouse do where: e.timestamp >= ^first_datetime and e.timestamp < ^last_datetime ) - on_full_build do + on_ee do q = Plausible.Stats.Sampling.add_query_hint(q, 10_000_000) end diff --git a/lib/plausible/stats/metrics.ex b/lib/plausible/stats/metrics.ex index b1c34f2bb..36a1c3743 100644 --- a/lib/plausible/stats/metrics.ex +++ b/lib/plausible/stats/metrics.ex @@ -17,7 +17,7 @@ defmodule Plausible.Stats.Metrics do :events, :conversion_rate, :time_on_page - ] ++ on_full_build(do: Plausible.Stats.Goal.Revenue.revenue_metrics(), else: []) + ] ++ on_ee(do: Plausible.Stats.Goal.Revenue.revenue_metrics(), else: []) @metric_mappings Enum.into(@all_metrics, %{}, fn metric -> {to_string(metric), metric} end) diff --git a/lib/plausible/stats/query.ex b/lib/plausible/stats/query.ex index 852f4e372..4d0b51205 100644 --- a/lib/plausible/stats/query.ex +++ b/lib/plausible/stats/query.ex @@ -31,7 +31,7 @@ defmodule Plausible.Stats.Query do |> put_imported_opts(site, params) |> maybe_drop_prop_filter(site) - on_full_build do + on_ee do query = Plausible.Stats.Sampling.put_threshold(query, params) end diff --git a/lib/plausible/stats/timeseries.ex b/lib/plausible/stats/timeseries.ex index 16594594b..3b400907b 100644 --- a/lib/plausible/stats/timeseries.ex +++ b/lib/plausible/stats/timeseries.ex @@ -25,7 +25,7 @@ defmodule Plausible.Stats.Timeseries do Plausible.Stats.TableDecider.partition_metrics(metrics, query) {currency, event_metrics} = - on_full_build do + on_ee do Plausible.Stats.Goal.Revenue.get_revenue_tracking_currency(site, query, event_metrics) else {nil, event_metrics} @@ -245,7 +245,7 @@ defmodule Plausible.Stats.Timeseries do end) end - on_full_build do + on_ee do defp cast_revenue_metrics_to_money(results, revenue_goals) do Plausible.Stats.Goal.Revenue.cast_revenue_metrics_to_money(results, revenue_goals) end diff --git a/lib/plausible/users.ex b/lib/plausible/users.ex index 727e35bb4..03e4f8b88 100644 --- a/lib/plausible/users.ex +++ b/lib/plausible/users.ex @@ -12,7 +12,7 @@ defmodule Plausible.Users do alias Plausible.Repo @spec on_trial?(Auth.User.t()) :: boolean() - on_full_build do + on_ee do def on_trial?(%Auth.User{trial_expiry_date: nil}), do: false def on_trial?(user) do @@ -36,7 +36,7 @@ defmodule Plausible.Users do end @spec accept_traffic_until(Auth.User.t()) :: Date.t() - on_full_build do + on_ee do def accept_traffic_until(user) do user = with_subscription(user) diff --git a/lib/plausible_release.ex b/lib/plausible_release.ex index 057e3bc53..9d23382e7 100644 --- a/lib/plausible_release.ex +++ b/lib/plausible_release.ex @@ -12,7 +12,7 @@ defmodule Plausible.Release do ] def should_be_first_launch? do - on_full_build do + on_ee do false else not (_has_users? = Repo.exists?(Plausible.Auth.User)) diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.ex index 3d90f84e3..8b411eef0 100644 --- a/lib/plausible_web/controllers/api/stats_controller.ex +++ b/lib/plausible_web/controllers/api/stats_controller.ex @@ -10,7 +10,7 @@ defmodule PlausibleWeb.Api.StatsController do require Logger - @revenue_metrics on_full_build(do: Plausible.Stats.Goal.Revenue.revenue_metrics(), else: []) + @revenue_metrics on_ee(do: Plausible.Stats.Goal.Revenue.revenue_metrics(), else: []) plug(:date_validation_plug) @@ -347,13 +347,13 @@ defmodule PlausibleWeb.Api.StatsController do top_stats_entry(results, comparison, "Unique visitors", :total_visitors), top_stats_entry(results, comparison, "Unique conversions", :visitors, graphable?: true), top_stats_entry(results, comparison, "Total conversions", :events, graphable?: true), - on_full_build do + on_ee do top_stats_entry(results, comparison, "Average revenue", :average_revenue, formatter: &format_money/1, graphable?: true ) end, - on_full_build do + on_ee do top_stats_entry(results, comparison, "Total revenue", :total_revenue, formatter: &format_money/1, graphable?: true @@ -480,7 +480,7 @@ defmodule PlausibleWeb.Api.StatsController do end end - on_full_build do + on_ee do def funnel(conn, %{"id" => funnel_id} = params) do site = Plausible.Repo.preload(conn.assigns.site, :owner) @@ -1377,7 +1377,7 @@ defmodule PlausibleWeb.Api.StatsController do end end - on_full_build do + on_ee do defdelegate format_revenue_metric(metric_value), to: PlausibleWeb.Controllers.API.Revenue defdelegate format_money(money), to: PlausibleWeb.Controllers.API.Revenue else diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex index 00e093bb9..a89519821 100644 --- a/lib/plausible_web/controllers/site_controller.ex +++ b/lib/plausible_web/controllers/site_controller.ex @@ -679,7 +679,7 @@ defmodule PlausibleWeb.SiteController do |> redirect(external: Routes.site_path(conn, :settings_integrations, site.domain)) end - on_full_build do + on_ee do # exported archives are downloaded from object storage else alias Plausible.Exports diff --git a/lib/plausible_web/controllers/stats_controller.ex b/lib/plausible_web/controllers/stats_controller.ex index c360c26bf..ca921c045 100644 --- a/lib/plausible_web/controllers/stats_controller.ex +++ b/lib/plausible_web/controllers/stats_controller.ex @@ -89,7 +89,7 @@ defmodule PlausibleWeb.StatsController do end end - on_full_build do + on_ee do defp list_funnels(site) do Plausible.Funnels.list(site) end @@ -356,7 +356,7 @@ defmodule PlausibleWeb.StatsController do defp get_flags(_user, _site), do: %{} defp is_dbip() do - on_full_build do + on_ee do false else Plausible.Geo.database_type() diff --git a/lib/plausible_web/email.ex b/lib/plausible_web/email.ex index 01218d896..3a428b16a 100644 --- a/lib/plausible_web/email.ex +++ b/lib/plausible_web/email.ex @@ -349,7 +349,7 @@ defmodule PlausibleWeb.Email do def export_success(user, site, download_url, expires_at) do subject = - on_full_build do + on_ee do "Your Plausible Analytics export is now ready for download" else "Your export is now ready for download" @@ -377,7 +377,7 @@ defmodule PlausibleWeb.Email do def export_failure(user, site) do subject = - on_full_build do + on_ee do "Your Plausible Analytics export has failed" else "Your export has failed" diff --git a/lib/plausible_web/endpoint.ex b/lib/plausible_web/endpoint.ex index 8b83b084c..7721b7566 100644 --- a/lib/plausible_web/endpoint.ex +++ b/lib/plausible_web/endpoint.ex @@ -36,7 +36,7 @@ defmodule PlausibleWeb.Endpoint do static_paths = ~w(css js images favicon.ico) static_paths = - on_full_build do + on_ee do # NOTE: The Cloud uses custom robots.txt from https://github.com/plausible/website: https://plausible.io/robots.txt static_paths else @@ -50,7 +50,7 @@ defmodule PlausibleWeb.Endpoint do only: static_paths ) - on_full_build do + on_ee do plug(Plug.Static, at: "/kaffy", from: :kaffy, diff --git a/lib/plausible_web/live/goal_settings/form.ex b/lib/plausible_web/live/goal_settings/form.ex index d9d39c420..c6c41a330 100644 --- a/lib/plausible_web/live/goal_settings/form.ex +++ b/lib/plausible_web/live/goal_settings/form.ex @@ -149,7 +149,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do
Plausible.Goal.Revenue.currency_options() diff --git a/lib/plausible_web/live/register_form.ex b/lib/plausible_web/live/register_form.ex index 8b80fc1d7..422a1c447 100644 --- a/lib/plausible_web/live/register_form.ex +++ b/lib/plausible_web/live/register_form.ex @@ -64,7 +64,7 @@ defmodule PlausibleWeb.Live.RegisterForm do ~H"""

- <%= if small_build?() or @live_action == :register_from_invitation_form do %> + <%= if ce?() or @live_action == :register_from_invitation_form do %> Register your Plausible Analytics account <% else %> Register your 30-day free trial @@ -158,7 +158,7 @@ defmodule PlausibleWeb.Live.RegisterForm do <% end %> <% submit_text = - if small_build?() or @invitation do + if ce?() or @invitation do "Create my account →" else "Start my free trial →" @@ -301,7 +301,7 @@ defmodule PlausibleWeb.Live.RegisterForm do defp add_user(socket, user) do case Repo.insert(user) do {:ok, _user} -> - on_full_build do + on_ee do metrics_params = if socket.assigns.invitation do %{ diff --git a/lib/plausible_web/live/sites.ex b/lib/plausible_web/live/sites.ex index 3ef7f2f19..334f3ce45 100644 --- a/lib/plausible_web/live/sites.ex +++ b/lib/plausible_web/live/sites.ex @@ -682,7 +682,7 @@ defmodule PlausibleWeb.Live.Sites do defp check_limits(invitation, _), do: %{invitation: invitation} defp check_features(%{role: :owner, site: site} = invitation, user) do - case Invitations.check_feature_access(site, user, small_build?()) do + case Invitations.check_feature_access(site, user, ce?()) do :ok -> %{invitation: invitation} diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.ex index fabc19256..a0ece8f72 100644 --- a/lib/plausible_web/router.ex +++ b/lib/plausible_web/router.ex @@ -10,7 +10,7 @@ defmodule PlausibleWeb.Router do plug :fetch_live_flash plug :put_secure_browser_headers plug PlausibleWeb.Plugs.NoRobots - on_full_build(do: nil, else: plug(PlausibleWeb.FirstLaunchPlug, redirect_to: "/register")) + on_ee(do: nil, else: plug(PlausibleWeb.FirstLaunchPlug, redirect_to: "/register")) plug PlausibleWeb.SessionTimeoutPlug, timeout_after_seconds: @two_weeks_in_seconds plug PlausibleWeb.AuthPlug plug PlausibleWeb.LastSeenPlug @@ -51,7 +51,7 @@ defmodule PlausibleWeb.Router do plug :accepts, ["json"] end - on_full_build do + on_ee do pipeline :flags do plug :accepts, ["html"] plug :put_secure_browser_headers @@ -62,24 +62,24 @@ defmodule PlausibleWeb.Router do end end - if Mix.env() in [:dev, :small_dev] do + if Mix.env() in [:dev, :ce_dev] do forward "/sent-emails", Bamboo.SentEmailViewerPlug end - on_full_build do + on_ee do use Kaffy.Routes, scope: "/crm", pipe_through: [PlausibleWeb.Plugs.NoRobots, PlausibleWeb.CRMAuthPlug] end - on_full_build do + on_ee do scope "/crm", PlausibleWeb do pipe_through :flags get "/auth/user/:user_id/usage", AdminController, :usage end end - on_full_build do + on_ee do scope path: "/flags" do pipe_through :flags forward "/", FunWithFlags.UI.Router, namespace: "flags" @@ -129,7 +129,7 @@ defmodule PlausibleWeb.Router do scope "/api/stats", PlausibleWeb.Api do pipe_through :internal_stats_api - on_full_build do + on_ee do get "/:domain/funnels/:id", StatsController, :funnel end @@ -168,7 +168,7 @@ defmodule PlausibleWeb.Router do get "/timeseries", ExternalStatsController, :timeseries end - on_full_build do + on_ee do scope "/api/v1/sites", PlausibleWeb.Api do pipe_through [:public_api, PlausibleWeb.AuthorizeSitesApiPlug] @@ -352,7 +352,7 @@ defmodule PlausibleWeb.Router do get "/:website/settings/goals", SiteController, :settings_goals get "/:website/settings/properties", SiteController, :settings_props - on_full_build do + on_ee do get "/:website/settings/funnels", SiteController, :settings_funnels end @@ -391,7 +391,7 @@ defmodule PlausibleWeb.Router do delete "/:website/settings/forget-imported", SiteController, :forget_imported delete "/:website/settings/forget-import/:import_id", SiteController, :forget_import - on_full_build do + on_ee do # exported archives are downloaded from object storage else get "/:website/exported-archive", SiteController, :download_local_export diff --git a/lib/plausible_web/templates/auth/activate.html.heex b/lib/plausible_web/templates/auth/activate.html.heex index b406face6..a1c8e2aa6 100644 --- a/lib/plausible_web/templates/auth/activate.html.heex +++ b/lib/plausible_web/templates/auth/activate.html.heex @@ -45,7 +45,7 @@ method: :post ) %> to <%= @conn.assigns[:current_user].email %> - <%= if full_build?() do %> + <%= if ee?() do %>
  • Contact us diff --git a/lib/plausible_web/templates/auth/password_reset_request_success.html.heex b/lib/plausible_web/templates/auth/password_reset_request_success.html.heex index 846a7c03e..f345d761d 100644 --- a/lib/plausible_web/templates/auth/password_reset_request_success.html.heex +++ b/lib/plausible_web/templates/auth/password_reset_request_success.html.heex @@ -11,13 +11,13 @@ You might have used an email address that's not registered in our database. Please verify the email address associated with your Plausible account and attempt the password reset once more.
  • - + Certain that you're using the correct email address but still aren't receiving the password reset email? Please check your spam folder or ask on our community-supported forum. - + Certain that you're using the correct email address but still aren't receiving the password reset email? Please check your spam folder or - <%= if full_build?() do %> + <%= if ee?() do %>

    Subscription Plan

    diff --git a/lib/plausible_web/templates/auth/verify_2fa.html.heex b/lib/plausible_web/templates/auth/verify_2fa.html.heex index f16601890..fbe78db27 100644 --- a/lib/plausible_web/templates/auth/verify_2fa.html.heex +++ b/lib/plausible_web/templates/auth/verify_2fa.html.heex @@ -30,7 +30,7 @@ > Use recovery code
    - <%= if full_build?() do %> + <%= if ee?() do %>
    Lost your recovery codes? Contact us diff --git a/lib/plausible_web/templates/auth/verify_2fa_recovery_code.html.heex b/lib/plausible_web/templates/auth/verify_2fa_recovery_code.html.heex index 8c893acf5..8905c056e 100644 --- a/lib/plausible_web/templates/auth/verify_2fa_recovery_code.html.heex +++ b/lib/plausible_web/templates/auth/verify_2fa_recovery_code.html.heex @@ -46,7 +46,7 @@ Enter verification code - <%= if full_build?() do %> + <%= if ee?() do %>
    Lost your recovery codes? Contact us diff --git a/lib/plausible_web/templates/email/csv_import.html.heex b/lib/plausible_web/templates/email/csv_import.html.heex index b4ff1a4fc..feef762cb 100644 --- a/lib/plausible_web/templates/email/csv_import.html.heex +++ b/lib/plausible_web/templates/email/csv_import.html.heex @@ -7,7 +7,7 @@ <% else %> Unfortunately, your CSV import for <%= @site_import.site.domain %> did not complete successfully. Sorry about that!

    Please try to do the import once again. - <%= if full_build?() do %> + <%= if ee?() do %>

    Please reply to this email to let us know if you're still experiencing issues with the import. <% end %> diff --git a/lib/plausible_web/templates/email/export_failure.html.eex b/lib/plausible_web/templates/email/export_failure.html.eex index ddcfd53f0..f4163bbfe 100644 --- a/lib/plausible_web/templates/email/export_failure.html.eex +++ b/lib/plausible_web/templates/email/export_failure.html.eex @@ -1,5 +1,5 @@ -Your <%= if full_build?() do %>Plausible Analytics <% end %>export for <%= @site.domain %> has encountered an error and was unsuccessful. +Your <%= if ee?() do %>Plausible Analytics <% end %>export for <%= @site.domain %> has encountered an error and was unsuccessful. Sorry for the trouble this may have caused.

    Please attempt to export your data again. -<%= if full_build?() do %>Should the problem persist, do reply to this email so we can assist. Thanks!<% end %> +<%= if ee?() do %>Should the problem persist, do reply to this email so we can assist. Thanks!<% end %> diff --git a/lib/plausible_web/templates/email/export_success.html.eex b/lib/plausible_web/templates/email/export_success.html.eex index 705daf537..541a0e11b 100644 --- a/lib/plausible_web/templates/email/export_success.html.eex +++ b/lib/plausible_web/templates/email/export_success.html.eex @@ -1,3 +1,3 @@ -Your <%= if full_build?() do %>Plausible Analytics <% end %>export for <%= @site.domain %> is now ready for download. +Your <%= if ee?() do %>Plausible Analytics <% end %>export for <%= @site.domain %> is now ready for download. Please click
    here to start the download process. <%= if @expires_in do %>Note that this link will expire <%= @expires_in %>.<% end %> diff --git a/lib/plausible_web/templates/email/google_analytics_import.html.heex b/lib/plausible_web/templates/email/google_analytics_import.html.heex index c0369fd65..033d0710a 100644 --- a/lib/plausible_web/templates/email/google_analytics_import.html.heex +++ b/lib/plausible_web/templates/email/google_analytics_import.html.heex @@ -8,7 +8,7 @@ Unfortunately, your Google Analytics import for <%= @site_import.site.domain %> did not complete successfully. Sorry about that!

    Please try to do the import once again. Sometimes the Google Analytics API just randomly returns empty data. It's intermittent and random. Trying to do the import again may return what you need. - <%= if full_build?() do %> + <%= if ee?() do %>

    Please reply to this email to let us know if you're still experiencing issues with the import. <% end %> diff --git a/lib/plausible_web/templates/error/server_error.html.heex b/lib/plausible_web/templates/error/server_error.html.heex index 24077e525..41cc9123f 100644 --- a/lib/plausible_web/templates/error/server_error.html.heex +++ b/lib/plausible_web/templates/error/server_error.html.heex @@ -22,14 +22,14 @@

    There has been a server error. - <%= if full_build?() do %> + <%= if ee?() do %> But don't worry, we're on it! <% end %>

    - <%= if assigns[:trace_id] && full_build?() do %> + <%= if assigns[:trace_id] && ee?() do %> If you would like to help, tell us what you were trying to do. Our development team will receive your report. <% else %> We have been notified. @@ -40,7 +40,7 @@

    - <%= if full_build?() do %> + <%= if ee?() do %> <%= if assigns[:trace_id] do %>
    <%= form_for :error, Routes.error_report_path(PlausibleWeb.Endpoint, :submit_error_report), fn f -> %> diff --git a/lib/plausible_web/templates/layout/_footer.html.heex b/lib/plausible_web/templates/layout/_footer.html.heex index bc51a1b6c..d90e774c8 100644 --- a/lib/plausible_web/templates/layout/_footer.html.heex +++ b/lib/plausible_web/templates/layout/_footer.html.heex @@ -14,12 +14,12 @@ ) %>

    - <%= if full_build?() do %> + <%= if ee?() do %> Made and hosted in the EU 🇪🇺
    Solely funded by our subscribers. <% end %> - <%= if small_build?() do %> + <%= if ce?() do %> This dashboard is running on self-managed infrastructure, not tested by Plausible Analytics. We cannot vouch for its performance or reliability. For official managed hosting, check out <.styled_link href="https://plausible.io"> plausible.io diff --git a/lib/plausible_web/templates/layout/_header.html.heex b/lib/plausible_web/templates/layout/_header.html.heex index de0402c7f..f5cd4d944 100644 --- a/lib/plausible_web/templates/layout/_header.html.heex +++ b/lib/plausible_web/templates/layout/_header.html.heex @@ -28,7 +28,7 @@ <% @conn.assigns[:current_user] -> %>

      - <%= if @conn.assigns[:current_user] && full_build?() do %> + <%= if @conn.assigns[:current_user] && ee?() do %>
    • <% end %>
    diff --git a/lib/plausible_web/templates/layout/_tracking.html.heex b/lib/plausible_web/templates/layout/_tracking.html.heex index e999cbc67..d5451dc75 100644 --- a/lib/plausible_web/templates/layout/_tracking.html.heex +++ b/lib/plausible_web/templates/layout/_tracking.html.heex @@ -1,4 +1,4 @@ -<%= on_full_build do %> +<%= on_ee do %> <%= if !@conn.assigns[:skip_plausible_tracking] do %>