Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
add a test and fix rendering the dashboard link
Robertfbe3a4e6f1ac
diff --git a/lib/plausible_web/templates/email/spike_notification.html.eex b/lib/plausible_web/templates/email/spike_notification.html.eexindex 47a9f27a87..2243ca1bdd 100644--- a/lib/plausible_web/templates/email/spike_notification.html.eex+++ b/lib/plausible_web/templates/email/spike_notification.html.eex@@ -10,7 +10,7 @@ There are currently <%= @current_visitors %> visitors on <%= link(@site.domain,<%= if @link do %><br /><br />-View dashboard: @link+View dashboard: <%= link(@link, to: @link) %><% end %><br /><br />--diff --git a/lib/workers/spike_notifier.ex b/lib/workers/spike_notifier.exindex ddd0331b11..4e0b0c4100 100644--- a/lib/workers/spike_notifier.ex+++ b/lib/workers/spike_notifier.ex@@ -31,7 +31,7 @@ defmodule Plausible.Workers.SpikeNotifier do:okend- def notify(notification, current_visitors, sources) do+ defp notify(notification, current_visitors, sources) dofor recipient <- notification.recipients dosend_notification(recipient, notification.site, current_visitors, sources)end@@ -45,7 +45,7 @@ defmodule Plausible.Workers.SpikeNotifier dosite = Repo.preload(site, :members)dashboard_link =- if Enum.member?(site.members, recipient) do+ if Enum.any?(site.members, &(&1.email == recipient)) doPlausibleWeb.Endpoint.url() <> "/" <> URI.encode_www_form(site.domain)enddiff --git a/test/workers/spike_notifier_test.exs b/test/workers/spike_notifier_test.exsindex 5dbea18e03..dea8f6fc90 100644--- a/test/workers/spike_notifier_test.exs+++ b/test/workers/spike_notifier_test.exs@@ -85,4 +85,18 @@ defmodule Plausible.Workers.SpikeNotifierTest doassert_no_emails_delivered()end++ test "adds a dashboard link if recipient has access to the site" do+ user = insert(:user, email: "[email protected]")+ site = insert(:site, domain: "example.com", members: [user])+ insert(:spike_notification, site: site, threshold: 10, recipients: ["[email protected]"])++ clickhouse_stub =+ stub(Plausible.Stats.Clickhouse, :current_visitors, fn _site, _query -> 10 end)+ |> stub(:top_sources, fn _site, _query, _limit, _page, _show_noref -> [] end)++ SpikeNotifier.perform(nil, clickhouse_stub)++ assert_email_delivered_with(html_body: ~r/View dashboard: <a href=\"http.+\/example.com/)+ endend