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
Do not send email reports for locked sites
Uku Taht27f99da8ad0f
diff --git a/lib/workers/schedule_email_reports.ex b/lib/workers/schedule_email_reports.exindex 5c87daec49..3a9ebe4836 100644--- a/lib/workers/schedule_email_reports.ex+++ b/lib/workers/schedule_email_reports.ex@@ -34,6 +34,7 @@ defmodule Plausible.Workers.ScheduleEmailReports dofragment("(? -> 'site_id')::int", job.args) == s.id andjob.state not in ["completed", "discarded"],where: is_nil(job),+ where: not s.locked,preload: [weekly_report: wr])@@ -73,6 +74,7 @@ defmodule Plausible.Workers.ScheduleEmailReports dofragment("(? -> 'site_id')::int", job.args) == s.id andjob.state not in ["completed", "discarded"],where: is_nil(job),+ where: not s.locked,preload: [monthly_report: mr])diff --git a/lib/workers/spike_notifier.ex b/lib/workers/spike_notifier.exindex a588b29a00..bac715adf0 100644--- a/lib/workers/spike_notifier.ex+++ b/lib/workers/spike_notifier.ex@@ -12,7 +12,10 @@ defmodule Plausible.Workers.SpikeNotifier dofrom sn in SpikeNotification,where: is_nil(sn.last_sent),or_where: sn.last_sent < fragment("now() - INTERVAL ?", @at_most_every),- preload: :site+ join: s in Plausible.Site,+ on: sn.site_id == s.id,+ where: not s.locked,+ preload: [site: s])for notification <- notifications dodiff --git a/test/workers/schedule_email_reports_test.exs b/test/workers/schedule_email_reports_test.exsindex 3a05430442..489b29f700 100644--- a/test/workers/schedule_email_reports_test.exs+++ b/test/workers/schedule_email_reports_test.exs@@ -27,6 +27,15 @@ defmodule Plausible.Workers.ScheduleEmailReportsTest doassert Enum.count(all_enqueued(worker: SendEmailReport)) == 1end+ test "does not schedule a weekly report for locked site" do+ site = insert(:site, locked: true, domain: "test-site.com", timezone: "US/Eastern")+ insert(:weekly_report, site: site, recipients: ["[email protected]"])++ perform_job(ScheduleEmailReports, %{})++ assert Enum.empty?(all_enqueued(worker: SendEmailReport))+ end+test "schedules a new report as soon as a previous one is completed" dosite = insert(:site, domain: "test-site.com", timezone: "US/Eastern")insert(:weekly_report, site: site, recipients: ["[email protected]"])@@ -57,11 +66,21 @@ defmodule Plausible.Workers.ScheduleEmailReportsTest dosite = insert(:site, domain: "test-site.com", timezone: "US/Eastern")insert(:monthly_report, site: site, recipients: ["[email protected]"])+ perform_job(ScheduleEmailReports, %{})perform_job(ScheduleEmailReports, %{})assert Enum.count(all_enqueued(worker: SendEmailReport)) == 1end+ test "does not schedule a monthly report for locked site" do+ site = insert(:site, locked: true, domain: "test-site.com", timezone: "US/Eastern")+ insert(:monthly_report, site: site, recipients: ["[email protected]"])++ perform_job(ScheduleEmailReports, %{})++ assert Enum.empty?(all_enqueued(worker: SendEmailReport))+ end+test "schedules a new report as soon as a previous one is completed" dosite = insert(:site, domain: "test-site.com", timezone: "US/Eastern")insert(:monthly_report, site: site, recipients: ["[email protected]"])diff --git a/test/workers/spike_notifier_test.exs b/test/workers/spike_notifier_test.exsindex 4deb9b2952..055cffe6f3 100644--- a/test/workers/spike_notifier_test.exs+++ b/test/workers/spike_notifier_test.exs@@ -48,6 +48,24 @@ defmodule Plausible.Workers.SpikeNotifierTest do)end+ test "does not check site if it is locked" do+ site = insert(:site, locked: true)++ 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_no_emails_delivered()+ end+test "does not notify anyone if a notification already went out in the last 12 hours" dosite = insert(:site)insert(:spike_notification, site: site, threshold: 10, recipients: ["[email protected]"])