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
Supressions fixups (#6726)
Adam8be0427a5e1a
diff --git a/extra/lib/plausible_web/live/customer_support/email_suppressions.ex b/extra/lib/plausible_web/live/customer_support/email_suppressions.exindex 560b0e1cbc..094e48c9cc 100644--- a/extra/lib/plausible_web/live/customer_support/email_suppressions.ex+++ b/extra/lib/plausible_web/live/customer_support/email_suppressions.ex@@ -129,18 +129,21 @@ defmodule PlausibleWeb.Live.CustomerSupport.EmailSuppressions do</.td><.td>{format_datetime(s.inserted_at)}</.td><.td>- <div class="flex flex-col items-start gap-1">- <.styled_link+ <div class="flex items-center gap-2 -ml-3">+ <.button:if={is_nil(s.reactivated_at) and s.reason != :spam_complaint}+ theme="ghost"+ size="sm"+ mt?={false}phx-click="reactivate"phx-value-email={s.email}data-confirm={"Reactivate #{s.email}? Plausible will start sending mail to this address again."}>Reactivate- </.styled_link>+ </.button><.dropdown :if={has_postmark_details?(s)} id={"suppression-details-#{s.id}"}>- <:button class="!py-0 text-sm text-indigo-600 dark:text-indigo-500 hover:text-indigo-700 dark:hover:text-indigo-400">+ <:button theme="ghost" size="sm">Details</:button><:menu class="w-80 p-3 text-xs text-gray-500 dark:text-gray-400 space-y-2">diff --git a/lib/plausible_web/controllers/api/postmark_controller.ex b/lib/plausible_web/controllers/api/postmark_controller.exindex aaee534f60..8a82fe75d9 100644--- a/lib/plausible_web/controllers/api/postmark_controller.ex+++ b/lib/plausible_web/controllers/api/postmark_controller.ex@@ -39,14 +39,16 @@ defmodule PlausibleWeb.Api.PostmarkController doconn,%{"RecordType" => "SubscriptionChange",- "SuppressSending" => true,- "SuppressionReason" => "ManualSuppression"+ "SuppressSending" => suppress?,+ "SuppressionReason" => reason} = params) do- params- |> unsubscribe_attrs()- |> Plausible.EmailSuppressions.create_from_unsubscribe()- |> log_on_error(params)+ if suppress? == true and reason == "ManualSuppression" do+ params+ |> unsubscribe_attrs()+ |> Plausible.EmailSuppressions.create_from_unsubscribe()+ |> log_on_error(params)+ endok(conn)enddiff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exsindex 2ba49ad348..f5f6f87003 100644--- a/priv/repo/seeds.exs+++ b/priv/repo/seeds.exs@@ -99,6 +99,25 @@ on_ee do{:ok, solo_team} = Plausible.Teams.get_or_create(solo_user)Plausible.Billing.DevSubscriptions.create(solo_team.id, "910413")++ {:ok, _} =+ Plausible.EmailSuppressions.create_from_bounce(%{+ email: user2.email,+ reason: :hard_bounce,+ source: :webhook,+ postmark_bounce_id: 123_456_789,+ postmark_inactive: true,+ can_activate: true,+ details: "The email account that you tried to reach does not exist."+ })++ {:ok, _} =+ Plausible.EmailSuppressions.create_from_bounce(%{+ email: "[email protected]",+ reason: :unsubscribe,+ source: :backfill,+ details: "Unsubscribed via Postmark (origin: Recipient)"+ })endPlausible.Factory.insert_list(29, :ip_rule, site: site)diff --git a/test/plausible_web/controllers/api/postmark_controller_test.exs b/test/plausible_web/controllers/api/postmark_controller_test.exsindex 0fb9f80ce5..4f4363f324 100644--- a/test/plausible_web/controllers/api/postmark_controller_test.exs+++ b/test/plausible_web/controllers/api/postmark_controller_test.exs@@ -161,6 +161,10 @@ defmodule PlausibleWeb.Api.PostmarkControllerTest doenddescribe "SubscriptionChange webhook" do+ setup %{test_pid: test_pid} do+ Plausible.Test.Support.Sentry.setup(test_pid)+ end+@subscription_change_payload %{"RecordType" => "SubscriptionChange","MessageID" => "883953f4-6105-42a2-a16a-77a8eac79483",@@ -186,7 +190,9 @@ defmodule PlausibleWeb.Api.PostmarkControllerTest doassert suppression.source == :webhookend- test "ignores a reactivation (SuppressSending: false)", %{conn: conn} do+ test "ignores a reactivation (SuppressSending: false), without reporting to Sentry", %{+ conn: conn+ } dopayload = %{@subscription_change_payload| "SuppressSending" => false,@@ -197,16 +203,27 @@ defmodule PlausibleWeb.Api.PostmarkControllerTest doassert json_response(conn, 200) == %{}refute EmailSuppressions.suppressed?("[email protected]")+ assert Sentry.Test.pop_sentry_reports() == []end- test "ignores HardBounce/SpamComplaint reasons, already handled by their own webhooks", %{- conn: conn- } do+ test "ignores a HardBounce reason, already handled by the Bounce webhook, without reporting to Sentry",+ %{conn: conn} dopayload = %{@subscription_change_payload | "SuppressionReason" => "HardBounce"}conn = post(conn, ~p"/api/postmark/webhook", payload)assert json_response(conn, 200) == %{}refute EmailSuppressions.suppressed?("[email protected]")+ assert Sentry.Test.pop_sentry_reports() == []+ end++ test "ignores a SpamComplaint reason, already handled by the SpamComplaint webhook, without reporting to Sentry",+ %{conn: conn} do+ payload = %{@subscription_change_payload | "SuppressionReason" => "SpamComplaint"}+ conn = post(conn, ~p"/api/postmark/webhook", payload)++ assert json_response(conn, 200) == %{}+ refute EmailSuppressions.suppressed?("[email protected]")+ assert Sentry.Test.pop_sentry_reports() == []endenddiff --git a/test/plausible_web/live/customer_support/email_suppressions_test.exs b/test/plausible_web/live/customer_support/email_suppressions_test.exsindex 6b716d5d25..9a28c753c6 100644--- a/test/plausible_web/live/customer_support/email_suppressions_test.exs+++ b/test/plausible_web/live/customer_support/email_suppressions_test.exs@@ -126,7 +126,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.EmailSuppressionsTest dohtml =lv- |> element(~s|a[phx-value-email="[email protected]"]|, "Reactivate")+ |> element(~s|button[phx-value-email="[email protected]"]|, "Reactivate")|> render_click()assert text(html) =~ "no longer suppressed"@@ -163,7 +163,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.EmailSuppressionsTest dohtml =lv- |> element(~s|a[phx-value-email="[email protected]"]|, "Reactivate")+ |> element(~s|button[phx-value-email="[email protected]"]|, "Reactivate")|> render_click()assert text(html) =~ "no longer suppressed"@@ -179,7 +179,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.EmailSuppressionsTest do{:ok, lv, _html} = live(conn, open_suppressions())refute lv- |> element(~s|a[phx-value-email="[email protected]"]|)+ |> element(~s|button[phx-value-email="[email protected]"]|)|> has_element?()end@@ -199,7 +199,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.EmailSuppressionsTest dohtml =lv- |> element(~s|a[phx-value-email="[email protected]"]|, "Reactivate")+ |> element(~s|button[phx-value-email="[email protected]"]|, "Reactivate")|> render_click()assert text(html) =~ "Could not reactivate [email protected]"@@ -222,7 +222,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.EmailSuppressionsTest do{:ok, lv, _html} = live(conn, open_suppressions())refute lv- |> element(~s|a[phx-value-email="[email protected]"]|)+ |> element(~s|button[phx-value-email="[email protected]"]|)|> has_element?()end