diff --git a/.gitignore b/.gitignore index babedc52d..d3e8509c2 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,9 @@ npm-debug.log # Ignore Elixir Language Server files .elixir_ls plausible-report.xml + +*.sh +.idea +*.iml +*.log +*.code-workspace \ No newline at end of file diff --git a/HOSTING.md b/HOSTING.md index 2efcf9b87..f7001ca8f 100644 --- a/HOSTING.md +++ b/HOSTING.md @@ -116,6 +116,8 @@ Following are the variables that can be used to configure the availability of th - Note: This option is **not recommended** for production deployments. - DISABLE_REGISTRATION - Disables registration of new users, keep your admin credentials handy ;) _defaults to `false`_ +- DISABLE_SUBSCRIPTION + - Disables changing of subscription and removes the trial notice banner (use with caution!) _defaults to `false`_ ### Default User Generation For self-hosting, a default user is generated during the [Database Migration](#Database Migration) to access Plausible. To be noted that, a default user is a user whose trial period expires in 100 Years ;). @@ -154,7 +156,7 @@ In case of `Bamboo.SMTPAdapter` you need to supply the following variables: ### Database -Plausible uses postgresql as database for storing all the user-data. Use the following the variables to configure it. +Plausible uses [postgresql as database](https://www.tutorialspoint.com/postgresql/postgresql_environment.htm) for storing all the user-data. Use the following the variables to configure it. - DATABASE_URL (*String*) - The repo Url as dictated [here](https://hexdocs.pm/ecto/Ecto.Repo.html#module-urls) @@ -163,7 +165,7 @@ Plausible uses postgresql as database for storing all the user-data. Use the fol - DATABASE_TLS_ENABLED (*Boolean String*) - A flag that says whether to connect to the database via TLS, read [here](https://www.postgresql.org/docs/10/ssl-tcp.html) -For performance reasons, all the analytics events are stored in clickhouse: +For performance reasons, all the analytics events are stored in [clickhouse](https://clickhouse.tech/docs/en/getting-started/tutorial/): - CLICKHOUSE_DATABASE_HOST (*String*) - CLICKHOUSE_DATABASE_NAME (*String*) diff --git a/assets/js/dashboard/stats/modals/referrers.js b/assets/js/dashboard/stats/modals/referrers.js index 24249d6ef..e20c996b2 100644 --- a/assets/js/dashboard/stats/modals/referrers.js +++ b/assets/js/dashboard/stats/modals/referrers.js @@ -23,7 +23,7 @@ class ReferrersModal extends React.Component { } else { const include = this.showExtra() ? 'bounce_rate,visit_duration' : null - api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/referrers`, this.state.query, {limit: 100, include: include}) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/referrers`, this.state.query, { limit: 100, include: include, show_noref: true}) .then((res) => this.setState({loading: false, referrers: res})) } } diff --git a/assets/package-lock.json b/assets/package-lock.json index 96c13dd55..6e394ff5e 100644 --- a/assets/package-lock.json +++ b/assets/package-lock.json @@ -6779,7 +6779,7 @@ }, "pretty-hrtime": { "version": "1.0.3", - "resolved": "http://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz", + "resolved": "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz", "integrity": "sha1-t+PqQkNaTJsnWdmeDyAesZWALuE=" }, "private": { @@ -7752,7 +7752,7 @@ }, "strip-eof": { "version": "1.0.0", - "resolved": "http://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=" }, "stylehacks": { diff --git a/config/config.exs b/config/config.exs index f25fa5313..4a8945d1c 100644 --- a/config/config.exs +++ b/config/config.exs @@ -12,6 +12,7 @@ disable_auth = String.to_existing_atom(System.get_env("DISABLE_AUTH", "false")) config :plausible, :selfhost, disable_authentication: disable_auth, + disable_subscription: String.to_existing_atom(System.get_env("DISABLE_SUBSCRIPTION", "false")), disable_registration: if(disable_auth, do: true, @@ -98,7 +99,7 @@ cron_enabled = String.to_existing_atom(System.get_env("CRON_ENABLED", "false")) base_cron = [ # Daily at midnight - {"0 0 * * *", Plausible.Workers.RotateSalts}, + {"0 0 * * *", Plausible.Workers.RotateSalts} ] extra_cron = [ @@ -117,6 +118,7 @@ extra_cron = [ ] base_queues = [rotate_salts: 1] + extra_queues = [ provision_ssl_certificates: 1, fetch_tweets: 1, diff --git a/config/releases.exs b/config/releases.exs index 29d071580..2a6056132 100644 --- a/config/releases.exs +++ b/config/releases.exs @@ -34,7 +34,7 @@ ck_host = System.get_env("CLICKHOUSE_DATABASE_HOST", "localhost") ck_db = System.get_env("CLICKHOUSE_DATABASE_NAME", "plausible_dev") ck_db_user = System.get_env("CLICKHOUSE_DATABASE_USER") ck_db_pwd = System.get_env("CLICKHOUSE_DATABASE_PASSWORD") -ck_db_pool = String.to_integer(System.get_env("CLICKHOUSE_DATABASE_POOLSIZE", "10")) +ck_db_pool = String.to_integer(System.get_env("CLICKHOUSE_DATABASE_POOLSIZE", "10")) ### Mandatory params End sentry_dsn = System.get_env("SENTRY_DSN") @@ -63,6 +63,7 @@ config :plausible, config :plausible, :selfhost, disable_authentication: disable_auth, + disable_subscription: String.to_existing_atom(System.get_env("DISABLE_SUBSCRIPTION", "false")), disable_registration: if(!disable_auth, do: String.to_existing_atom(System.get_env("DISABLE_REGISTRATION", "false")), @@ -148,7 +149,7 @@ config :plausible, :custom_domain_server, base_cron = [ # Daily at midnight - {"0 0 * * *", Plausible.Workers.RotateSalts}, + {"0 0 * * *", Plausible.Workers.RotateSalts} ] extra_cron = [ @@ -167,6 +168,7 @@ extra_cron = [ ] base_queues = [rotate_salts: 1] + extra_queues = [ provision_ssl_certificates: 1, fetch_tweets: 1, diff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.ex index 22f2c82f9..a5214bf18 100644 --- a/lib/plausible/billing/billing.ex +++ b/lib/plausible/billing/billing.ex @@ -102,9 +102,11 @@ defmodule Plausible.Billing do defp subscription_is_active?(%Subscription{status: "active"}), do: true defp subscription_is_active?(%Subscription{status: "past_due"}), do: true + defp subscription_is_active?(%Subscription{status: "deleted"} = subscription) do subscription.next_bill_date && !Timex.before?(subscription.next_bill_date, Timex.today()) end + defp subscription_is_active?(_), do: false def on_trial?(user), do: trial_days_left(user) >= 0 diff --git a/lib/plausible/clickhouse.ex b/lib/plausible/clickhouse.ex index 1f0102d45..bdcddd678 100644 --- a/lib/plausible/clickhouse.ex +++ b/lib/plausible/clickhouse.ex @@ -14,8 +14,13 @@ defmodule Plausible.Clickhouse do delete_events = "ALTER TABLE events DELETE WHERE domain = ?" delete_sessions = "ALTER TABLE sessions DELETE WHERE domain = ?" - Clickhousex.query!(:clickhouse, delete_events, [site.domain], log: {Plausible.Clickhouse, :log, []}) - Clickhousex.query!(:clickhouse, delete_sessions, [site.domain], log: {Plausible.Clickhouse, :log, []}) + Clickhousex.query!(:clickhouse, delete_events, [site.domain], + log: {Plausible.Clickhouse, :log, []} + ) + + Clickhousex.query!(:clickhouse, delete_sessions, [site.domain], + log: {Plausible.Clickhouse, :log, []} + ) end def insert_events(events) do diff --git a/lib/plausible/session/salts.ex b/lib/plausible/session/salts.ex index a28048c06..ceb6fc54f 100644 --- a/lib/plausible/session/salts.ex +++ b/lib/plausible/session/salts.ex @@ -3,19 +3,27 @@ defmodule Plausible.Session.Salts do use Plausible.Repo def start_link(_opts) do - Agent.start_link(fn -> - clean_old_salts() - salts = Repo.all(from s in "salts", select: s.salt, order_by: [desc: s.inserted_at], limit: 2) - case salts do - [current, prev] -> - %{previous: prev, current: current} - [current] -> - %{previous: nil, current: current} - [] -> - new = generate_and_persist_new_salt() - %{previous: nil, current: new} - end - end, name: __MODULE__) + Agent.start_link( + fn -> + clean_old_salts() + + salts = + Repo.all(from s in "salts", select: s.salt, order_by: [desc: s.inserted_at], limit: 2) + + case salts do + [current, prev] -> + %{previous: prev, current: current} + + [current] -> + %{previous: nil, current: current} + + [] -> + new = generate_and_persist_new_salt() + %{previous: nil, current: new} + end + end, + name: __MODULE__ + ) end def fetch() do @@ -41,6 +49,8 @@ defmodule Plausible.Session.Salts do end defp clean_old_salts() do - Repo.delete_all(from s in "salts", where: s.inserted_at < fragment("now() - '48 hours'::interval")) + Repo.delete_all( + from s in "salts", where: s.inserted_at < fragment("now() - '48 hours'::interval") + ) end end diff --git a/lib/plausible/stats/clickhouse.ex b/lib/plausible/stats/clickhouse.ex index 7a8ac4625..a24302046 100644 --- a/lib/plausible/stats/clickhouse.ex +++ b/lib/plausible/stats/clickhouse.ex @@ -2,6 +2,7 @@ defmodule Plausible.Stats.Clickhouse do use Plausible.Repo alias Plausible.Stats.Query alias Plausible.Clickhouse + @no_ref "Direct Traffic" def compare_pageviews_and_visitors(site, query, {pageviews, visitors}) do query = Query.shift_back(query) @@ -256,8 +257,8 @@ defmodule Plausible.Stats.Clickhouse do end) end - def top_referrers(site, query, limit, include) do - q = + def top_referrers(site, query, limit \\ 5, show_noref \\ false, include \\ []) do + referrers = from(s in base_session_query(site, query), group_by: s.referrer_source, where: s.referrer_source != "", @@ -265,9 +266,10 @@ defmodule Plausible.Stats.Clickhouse do limit: ^limit ) - q = if "bounce_rate" in include do + referrers = + if "bounce_rate" in include do from( - s in q, + s in referrers, select: {fragment("? as name", s.referrer_source), fragment("any(?) as url", s.referrer), fragment("uniq(user_id) as count"), @@ -276,17 +278,35 @@ defmodule Plausible.Stats.Clickhouse do ) else from( - s in q, + s in referrers, select: - {fragment("? as name", s.referrer_source), fragment("any(?) as url", s.referrer), - fragment("uniq(user_id) as count")} + {fragment("? as name", s.referrer_source), fragment("any(?) as url", s.referrer), + fragment("uniq(user_id) as count")} ) end - Clickhouse.all(q) - |> Enum.map(fn ref -> - Map.update(ref, "url", nil, fn url -> url && URI.parse("http://" <> url).host end) - end) + referrers = + Clickhouse.all(referrers) + |> Enum.map(fn ref -> + Map.update(ref, "url", nil, fn url -> url && URI.parse("http://" <> url).host end) + end) + + show_noref = if length(referrers) == 0, do: true, else: show_noref + + if show_noref do + no_referrers = + Clickhouse.all( + from e in base_session_query(site, query), + select: + {fragment("? as name", @no_ref), fragment("any(?) as url", e.referrer), + fragment("uniq(user_id) as count")}, + where: e.referrer_source == "" + ) + + if no_referrers |> hd |> Map.get("count") > 0, do: referrers ++ no_referrers, else: [] + else + referrers + end end def visitors_from_referrer(site, query, referrer) do @@ -320,25 +340,40 @@ defmodule Plausible.Stats.Clickhouse do end def referrer_drilldown(site, query, referrer, include \\ []) do - q = from( - s in base_session_query(site, query), - group_by: s.referrer, - where: s.referrer_source == ^referrer, - order_by: [desc: fragment("count")], - limit: 100 - ) + referrer = if referrer == @no_ref, do: "", else: referrer - q = if "bounce_rate" in include do + referring_urls = + Clickhouse.all( + from e in base_session_query(site, query), + select: {fragment("? as name", e.referrer), fragment("uniq(user_id) as count")}, + group_by: e.referrer, + where: e.referrer_source == ^referrer, + order_by: [desc: fragment("count")], + limit: 100 + ) + + q = + from( + s in base_session_query(site, query), + group_by: s.referrer, + where: s.referrer_source == ^referrer, + order_by: [desc: fragment("count")], + limit: 100 + ) + + q = + if "bounce_rate" in include do from( s in q, select: - {fragment("? as name", s.referrer), - fragment("uniq(user_id) as count"), + {fragment("? as name", s.referrer), fragment("uniq(user_id) as count"), fragment("round(sum(is_bounce * sign) / sum(sign) * 100) as bounce_rate"), fragment("round(avg(duration * sign)) as visit_duration")} ) else - from(s in q, select: {fragment("? as name", s.referrer), fragment("uniq(user_id) as count")}) + from(s in q, + select: {fragment("? as name", s.referrer), fragment("uniq(user_id) as count")} + ) end referring_urls = Clickhouse.all(q) @@ -391,21 +426,27 @@ defmodule Plausible.Stats.Clickhouse do end def top_pages(site, query, limit, include) do - q = from( - e in base_query(site, query), - group_by: e.pathname, - order_by: [desc: fragment("count")], - limit: ^limit - ) - - q = if "unique_visitors" in include do + q = from( - e in q, - select: {fragment("? as name", e.pathname), fragment("count(?) as count", e.pathname), fragment("uniq(?) as unique_visitors", e.user_id)} + e in base_query(site, query), + group_by: e.pathname, + order_by: [desc: fragment("count")], + limit: ^limit ) - else - from(e in q, select: {fragment("? as name", e.pathname), fragment("count(?) as count", e.pathname)}) - end + + q = + if "unique_visitors" in include do + from( + e in q, + select: + {fragment("? as name", e.pathname), fragment("count(?) as count", e.pathname), + fragment("uniq(?) as unique_visitors", e.user_id)} + ) + else + from(e in q, + select: {fragment("? as name", e.pathname), fragment("count(?) as count", e.pathname)} + ) + end pages = Clickhouse.all(q) diff --git a/lib/plausible_release.ex b/lib/plausible_release.ex index da2c9f70b..21d4ef3b7 100644 --- a/lib/plausible_release.ex +++ b/lib/plausible_release.ex @@ -37,6 +37,8 @@ defmodule Plausible.Release do prepare() Enum.each(repos(), &run_migrations_for/1) init_admin() + prepare_clickhouse() + run_migrations_for_ch() IO.puts("Migrations successful!") end @@ -44,7 +46,6 @@ defmodule Plausible.Release do prepare() # Run seed script Enum.each(repos(), &run_seeds_for/1) - # Signal shutdown IO.puts("Success!") end @@ -52,6 +53,8 @@ defmodule Plausible.Release do def createdb do prepare() do_create_db() + prepare_clickhouse(:default_db) + do_create_ch_db() IO.puts("Creation of Db successful!") end @@ -117,23 +120,11 @@ defmodule Plausible.Release do {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true)) end - defp do_create_db do - for repo <- repos() do - :ok = ensure_repo_created(repo) - end - - do_create_ch_db() - end - - defp do_create_ch_db() do - db_to_create = Keyword.get(Application.get_env(:plausible, :clickhouse), :database) - - IO.puts("create #{inspect(db_to_create)} clickhouse database/tables if it doesn't exist") - - Clickhousex.query(:clickhouse, "CREATE DATABASE IF NOT EXISTS #{db_to_create}", []) + defp run_migrations_for_ch() do + db = Keyword.get(Application.get_env(:plausible, :clickhouse), :database) tb_events = """ - CREATE TABLE IF NOT EXISTS #{db_to_create}.events ( + CREATE TABLE IF NOT EXISTS #{db}.events ( timestamp DateTime, name String, domain String, @@ -156,7 +147,7 @@ defmodule Plausible.Release do Clickhousex.query(:clickhouse, tb_events, []) tb_sessions = """ - CREATE TABLE IF NOT EXISTS #{db_to_create}.sessions ( + CREATE TABLE IF NOT EXISTS #{db}.sessions ( session_id UInt64, sign Int8, domain String, @@ -185,6 +176,18 @@ defmodule Plausible.Release do Clickhousex.query(:clickhouse, tb_sessions, []) end + defp do_create_db do + for repo <- repos() do + :ok = ensure_repo_created(repo) + end + end + + defp do_create_ch_db() do + db_to_create = Keyword.get(Application.get_env(:plausible, :clickhouse), :database) + IO.puts("create #{inspect(db_to_create)} clickhouse database/tables if it doesn't exist") + Clickhousex.query(:clickhouse, "CREATE DATABASE IF NOT EXISTS #{db_to_create}", []) + end + defp ensure_repo_created(repo) do IO.puts("create #{inspect(repo)} database if it doesn't exist") @@ -208,8 +211,6 @@ defmodule Plausible.Release do # Load the code for myapp, but don't start it :ok = Application.load(@app) - prepare_clickhouse() - IO.puts("Starting dependencies..") # Start apps necessary for executing migrations Enum.each(@start_apps, &Application.ensure_all_started/1) @@ -219,7 +220,8 @@ defmodule Plausible.Release do Enum.each(repos(), & &1.start_link(pool_size: 2)) end - defp prepare_clickhouse do + # connect to the default db for creating the required db + defp prepare_clickhouse(:default_db) do Application.ensure_all_started(:db_connection) Application.ensure_all_started(:hackney) @@ -228,7 +230,24 @@ defmodule Plausible.Release do port: 8123, name: :clickhouse, database: "default", - hostname: Keyword.get(Application.get_env(:plausible, :clickhouse), :hostname) + username: "default", + hostname: Keyword.get(Application.get_env(:plausible, :clickhouse), :hostname), + password: Keyword.get(Application.get_env(:plausible, :clickhouse), :password) + ) + end + + defp prepare_clickhouse() do + Application.ensure_all_started(:db_connection) + Application.ensure_all_started(:hackney) + + Clickhousex.start_link( + scheme: :http, + port: 8123, + name: :clickhouse, + username: Keyword.get(Application.get_env(:plausible, :clickhouse), :username), + database: Keyword.get(Application.get_env(:plausible, :clickhouse), :database), + hostname: Keyword.get(Application.get_env(:plausible, :clickhouse), :hostname), + password: Keyword.get(Application.get_env(:plausible, :clickhouse), :password) ) end diff --git a/lib/plausible_web/controllers/api/external_controller.ex b/lib/plausible_web/controllers/api/external_controller.ex index 3924a83da..e2e58ad70 100644 --- a/lib/plausible_web/controllers/api/external_controller.ex +++ b/lib/plausible_web/controllers/api/external_controller.ex @@ -29,25 +29,28 @@ defmodule PlausibleWeb.Api.ExternalController do end def health(conn, _params) do - postgres_health = case Ecto.Adapters.SQL.query(Plausible.Repo, "SELECT 1", []) do - {:ok, _} -> "ok" - e -> "error: #{inspect e}" - end + postgres_health = + case Ecto.Adapters.SQL.query(Plausible.Repo, "SELECT 1", []) do + {:ok, _} -> "ok" + e -> "error: #{inspect(e)}" + end - clickhouse_health = case Clickhousex.query(:clickhouse, "SELECT 1", []) do - {:ok, _} -> "ok" - e -> "error: #{inspect e}" - end + clickhouse_health = + case Clickhousex.query(:clickhouse, "SELECT 1", []) do + {:ok, _} -> "ok" + e -> "error: #{inspect(e)}" + end - status = case {postgres_health, clickhouse_health} do - {"ok", "ok"} ->200 - _ -> 500 - end + status = + case {postgres_health, clickhouse_health} do + {"ok", "ok"} -> 200 + _ -> 500 + end put_status(conn, status) |> json(%{ postgres: postgres_health, - clickhouse: clickhouse_health, + clickhouse: clickhouse_health }) end diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.ex index c57faa72b..884f97946 100644 --- a/lib/plausible_web/controllers/api/stats_controller.ex +++ b/lib/plausible_web/controllers/api/stats_controller.ex @@ -27,11 +27,11 @@ defmodule PlausibleWeb.Api.StatsController do [ %{ name: "Active visitors", - count: Stats.current_visitors(site), + count: Stats.current_visitors(site) }, %{ name: "Pageviews (last 30 min)", - count: Stats.total_pageviews(site, query), + count: Stats.total_pageviews(site, query) } ] end @@ -94,7 +94,11 @@ defmodule PlausibleWeb.Api.StatsController do change: percent_change(prev_pageviews, pageviews) }, %{name: "Bounce rate", percentage: bounce_rate, change: change_bounce_rate}, - %{name: "Visit duration", count: visit_duration, change: percent_change(prev_visit_duration, visit_duration)} + %{ + name: "Visit duration", + count: visit_duration, + change: percent_change(prev_visit_duration, visit_duration) + } ] end @@ -116,8 +120,8 @@ defmodule PlausibleWeb.Api.StatsController do query = Query.from(site.timezone, params) include = if params["include"], do: String.split(params["include"], ","), else: [] limit = if params["limit"], do: String.to_integer(params["limit"]) - - json(conn, Stats.top_referrers(site, query, limit || 9, include)) + show_noref = if params["show_noref"], do: "true", else: false + json(conn, Stats.top_referrers(site, query, limit || 9, show_noref, include)) end def referrers_for_goal(conn, params) do diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex index 4444a4204..79aea31c2 100644 --- a/lib/plausible_web/controllers/auth_controller.ex +++ b/lib/plausible_web/controllers/auth_controller.ex @@ -236,7 +236,11 @@ defmodule PlausibleWeb.AuthController do def user_settings(conn, _params) do changeset = Auth.User.changeset(conn.assigns[:current_user]) - render(conn, "user_settings.html", changeset: changeset, subscription: conn.assigns[:current_user].subscription) + + render(conn, "user_settings.html", + changeset: changeset, + subscription: conn.assigns[:current_user].subscription + ) end def save_settings(conn, %{"user" => user_params}) do diff --git a/lib/plausible_web/controllers/page_controller.ex b/lib/plausible_web/controllers/page_controller.ex index e41cb1511..64e217d08 100644 --- a/lib/plausible_web/controllers/page_controller.ex +++ b/lib/plausible_web/controllers/page_controller.ex @@ -8,7 +8,7 @@ defmodule PlausibleWeb.PageController do user = conn.assigns[:current_user] |> Repo.preload(:sites) render(conn, "sites.html", sites: user.sites) else - render(conn, "index.html" ) + render(conn, "index.html") end end end diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex index 538d7c9dd..445a77972 100644 --- a/lib/plausible_web/controllers/site_controller.ex +++ b/lib/plausible_web/controllers/site_controller.ex @@ -160,8 +160,7 @@ defmodule PlausibleWeb.SiteController do end def reset_stats(conn, %{"website" => website}) do - site = - Sites.get_for_user!(conn.assigns[:current_user].id, website) + site = Sites.get_for_user!(conn.assigns[:current_user].id, website) Plausible.Clickhouse.delete_stats!(site) conn @@ -417,8 +416,9 @@ defmodule PlausibleWeb.SiteController do end def delete_custom_domain(conn, %{"website" => website}) do - site = Sites.get_for_user!(conn.assigns[:current_user].id, website) - |> Repo.preload(:custom_domain) + site = + Sites.get_for_user!(conn.assigns[:current_user].id, website) + |> Repo.preload(:custom_domain) Repo.delete!(site.custom_domain) diff --git a/lib/plausible_web/plugs/auth_plug.ex b/lib/plausible_web/plugs/auth_plug.ex index 8a81b8c0c..f4ffda03b 100644 --- a/lib/plausible_web/plugs/auth_plug.ex +++ b/lib/plausible_web/plugs/auth_plug.ex @@ -14,7 +14,10 @@ defmodule PlausibleWeb.AuthPlug do id -> user = Repo.get_by(Plausible.Auth.User, id: id) - |> Repo.preload(subscription: from(s in Plausible.Billing.Subscription, order_by: [desc: s.inserted_at])) + |> Repo.preload( + subscription: + from(s in Plausible.Billing.Subscription, order_by: [desc: s.inserted_at]) + ) if user do Sentry.Context.set_user_context(%{id: user.id, name: user.name}) diff --git a/lib/plausible_web/plugs/auto_auth_plug.ex b/lib/plausible_web/plugs/auto_auth_plug.ex index 5de238d5e..b56c4fc8f 100644 --- a/lib/plausible_web/plugs/auto_auth_plug.ex +++ b/lib/plausible_web/plugs/auto_auth_plug.ex @@ -20,7 +20,6 @@ defmodule PlausibleWeb.AutoAuthPlug do Plug.Conn.put_session(conn, :login_dest, conn.request_path) |> Phoenix.Controller.redirect(to: "/login") |> halt - end end end diff --git a/lib/plausible_web/templates/auth/user_settings.html.eex b/lib/plausible_web/templates/auth/user_settings.html.eex index f293700e2..56402c705 100644 --- a/lib/plausible_web/templates/auth/user_settings.html.eex +++ b/lib/plausible_web/templates/auth/user_settings.html.eex @@ -1,3 +1,4 @@ +<%= if !Keyword.fetch!(Application.get_env(:plausible, :selfhost), :disable_subscription) do %>