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 presence check when unsubscribing from email reports
Uku Tahtd30f6def0f82
diff --git a/lib/plausible_web/controllers/unsubscribe_controller.ex b/lib/plausible_web/controllers/unsubscribe_controller.exindex f8eff5feea..eb38813b8b 100644--- a/lib/plausible_web/controllers/unsubscribe_controller.ex+++ b/lib/plausible_web/controllers/unsubscribe_controller.ex@@ -5,10 +5,13 @@ defmodule PlausibleWeb.UnsubscribeController dodef weekly_report(conn, %{"website" => website, "email" => email}) dosite = Repo.get_by(Plausible.Site, domain: website)+ weekly_report = site && Repo.get_by(WeeklyReport, site_id: site.id)- Repo.get_by(WeeklyReport, site_id: site.id)- |> WeeklyReport.remove_recipient(email)- |> Repo.update!()+ if weekly_report do+ weekly_report+ |> WeeklyReport.remove_recipient(email)+ |> Repo.update!()+ endconn|> assign(:skip_plausible_tracking, true)@@ -21,10 +24,13 @@ defmodule PlausibleWeb.UnsubscribeController dodef monthly_report(conn, %{"website" => website, "email" => email}) dosite = Repo.get_by(Plausible.Site, domain: website)+ monthly_report = site && Repo.get_by(MonthlyReport, site_id: site.id)- Repo.get_by(MonthlyReport, site_id: site.id)- |> MonthlyReport.remove_recipient(email)- |> Repo.update!()+ if monthly_report do+ monthly_report+ |> MonthlyReport.remove_recipient(email)+ |> Repo.update!()+ endconn|> assign(:skip_plausible_tracking, true)diff --git a/test/plausible_web/controllers/unsubscribe_controller_test.exs b/test/plausible_web/controllers/unsubscribe_controller_test.exsindex 20eb779797..56f1afc677 100644--- a/test/plausible_web/controllers/unsubscribe_controller_test.exs+++ b/test/plausible_web/controllers/unsubscribe_controller_test.exs@@ -15,6 +15,13 @@ defmodule PlausibleWeb.UnsubscribeControllerTest doreport = Repo.get_by(Plausible.Site.WeeklyReport, site_id: site.id)assert report.recipients == []end++ test "renders success if site or weekly report does not exist in the database", %{conn: conn} do+ conn =+ get(conn, "/sites/nonexistent.com/weekly-report/[email protected]")++ assert html_response(conn, 200) =~ "Unsubscribe successful"+ endenddescribe "GET /sites/:website/monthly-report/unsubscribe" do@@ -30,5 +37,12 @@ defmodule PlausibleWeb.UnsubscribeControllerTest doreport = Repo.get_by(Plausible.Site.MonthlyReport, site_id: site.id)assert report.recipients == []end++ test "renders success if site or weekly report does not exist in the database", %{conn: conn} do+ conn =+ get(conn, "/sites/nonexistent.com/monthly-report/[email protected]")++ assert html_response(conn, 200) =~ "Unsubscribe successful"+ endendend