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
CRM: email suppressions (#6715)
Adamf61ae30901a4
diff --git a/extra/lib/plausible_web/live/customer_support/components/layout.ex b/extra/lib/plausible_web/live/customer_support/components/layout.exindex 42d5aa73e8..1a3983a027 100644--- a/extra/lib/plausible_web/live/customer_support/components/layout.ex+++ b/extra/lib/plausible_web/live/customer_support/components/layout.ex@@ -100,12 +100,20 @@ defmodule PlausibleWeb.CustomerSupport.Components.Layout do💬 Customer Support</.link></h2>- <.styled_link- class="text-sm flex-shrink-0"- patch={~p"/cs/trial-prospects"}- >- 🔥 Trial prospects- </.styled_link>+ <div class="flex justify-end space-x-2">+ <.styled_link+ class="text-sm"+ patch={~p"/cs/email-suppressions"}+ >+ 📩 E-mail suppressions+ </.styled_link>+ <.styled_link+ class="text-sm"+ patch={~p"/cs/trial-prospects"}+ >+ 🔥 Trial prospects+ </.styled_link>+ </div></div>"""enddiff --git a/extra/lib/plausible_web/live/customer_support/components/search_result.ex b/extra/lib/plausible_web/live/customer_support/components/search_result.exindex bdc0ca66a1..142dd5167c 100644--- a/extra/lib/plausible_web/live/customer_support/components/search_result.ex+++ b/extra/lib/plausible_web/live/customer_support/components/search_result.ex@@ -4,6 +4,8 @@ defmodule PlausibleWeb.CustomerSupport.Components.SearchResult do"""use PlausibleWeb, :live_component+ import PlausibleWeb.CustomerSupport.Components.SuppressionWarning+def favicon(assigns) do~H"""<img src={"/favicon/sources/#{@domain}"} class={@class} />@@ -74,8 +76,9 @@ defmodule PlausibleWeb.CustomerSupport.Components.SearchResult do<hr class="mt-4 mb-4 flex-grow border-t border-gray-200 dark:border-gray-600" /><div class="text-sm truncate">- {@resource.object.name} <{@resource.object.email}> <br />- Owns {length(@resource.object.owned_teams)} team(s)+ {@resource.object.name} <{@resource.object.email}>+ <.suppression_warning email={@resource.object.email} linked?={false} />+ <br /> Owns {length(@resource.object.owned_teams)} team(s)</div></div>"""diff --git a/extra/lib/plausible_web/live/customer_support/components/suppression_warning.ex b/extra/lib/plausible_web/live/customer_support/components/suppression_warning.exnew file mode 100644index 0000000000..b9100bef59--- /dev/null+++ b/extra/lib/plausible_web/live/customer_support/components/suppression_warning.ex@@ -0,0 +1,34 @@+defmodule PlausibleWeb.CustomerSupport.Components.SuppressionWarning do+ @moduledoc """+ A warning icon next to e-mail address, optionally linking to suppressions list+ """++ use Phoenix.Component+ use PlausibleWeb.VerifiedRoutes++ import PlausibleWeb.Components.Generic++ attr :email, :string, required: true+ attr :linked?, :boolean, default: true++ def suppression_warning(assigns) do+ assigns =+ assign(assigns, :suppressed?, Plausible.EmailSuppressions.suppressed?(assigns.email))++ ~H"""+ <.styled_link+ :if={@suppressed? && @linked?}+ patch={~p"/cs/email-suppressions?#{[search: @email]}"}+ title="This address is suppressed"+ >+ <Heroicons.exclamation_triangle solid class="w-4 h-4 text-yellow-500 inline" />+ </.styled_link>+ <Heroicons.exclamation_triangle+ :if={@suppressed? && !@linked?}+ solid+ class="w-4 h-4 text-yellow-500 inline"+ title="This address is suppressed"+ />+ """+ end+enddiff --git a/extra/lib/plausible_web/live/customer_support/email_suppressions.ex b/extra/lib/plausible_web/live/customer_support/email_suppressions.exnew file mode 100644index 0000000000..560b0e1cbc--- /dev/null+++ b/extra/lib/plausible_web/live/customer_support/email_suppressions.ex@@ -0,0 +1,231 @@+defmodule PlausibleWeb.Live.CustomerSupport.EmailSuppressions do+ @moduledoc """+ Customer Support page for reviewing e-mail suppressions (Postmark bounces+ and spam complaints) and manually reactivating false positives. See+ `Plausible.EmailSuppressions` for how suppressions are recorded and+ enforced.+ """+ use PlausibleWeb.CustomerSupport.Live++ alias Plausible.EmailSuppressions++ @reasons Ecto.Enum.values(Plausible.EmailSuppression, :reason)++ def mount(params, session, socket) do+ {:ok, socket} = super(params, session, socket)+ {:ok, assign(socket, :reasons, @reasons)}+ end++ def handle_params(params, _uri, socket) do+ reason = if params["reason"] in reason_strings(), do: params["reason"]+ pagination_params = Map.take(params, ["after", "before"])++ socket =+ socket+ |> assign(reason: reason, search: params["search"], pagination_params: pagination_params)+ |> assign(:page, list_suppressions(reason, params["search"], pagination_params))++ {:noreply, socket}+ end++ def handle_event("filter", params, socket) do+ query = [reason: params["reason"], search: params["search"]]++ {:noreply, push_patch(socket, to: ~p"/cs/email-suppressions?#{query}")}+ end++ def handle_event("reactivate", %{"email" => email}, socket) do+ socket =+ case EmailSuppressions.reactivate(email, socket.assigns.current_user) do+ {:ok, _suppression} ->+ socket+ |> put_live_flash(:success, "#{email} is no longer suppressed.")+ |> assign(+ :page,+ list_suppressions(+ socket.assigns.reason,+ socket.assigns.search,+ socket.assigns.pagination_params+ )+ )++ {:error, reason} ->+ put_live_flash(socket, :error, reactivate_error_message(email, reason))+ end++ {:noreply, socket}+ end++ defp reactivate_error_message(email, :cannot_delete_spam_complaint) do+ "Postmark won't allow #{email} to be reactivated automatically."+ end++ defp reactivate_error_message(email, reason) do+ "Could not reactivate #{email}: (#{inspect(reason)})."+ end++ defp list_suppressions(reason, search, pagination_params) do+ EmailSuppressions.list(+ [reason: reason && String.to_existing_atom(reason), search: search],+ pagination_params+ )+ end++ def render(assigns) do+ ~H"""+ <Layout.layout show_search={false} flash={@flash}>+ <h2 class="text-xl font-bold sm:text-2xl">✉️ E-mail suppressions</h2>++ <form phx-change="filter" class="mt-4 flex flex-wrap items-center gap-3">+ <select+ name="reason"+ class="rounded-md border-gray-300 dark:border-gray-600 dark:bg-gray-800 text-sm"+ >+ <option value="">All reasons</option>+ <option+ :for={reason <- @reasons}+ value={reason}+ selected={Atom.to_string(reason) == @reason}+ >+ {reason_label(reason)}+ </option>+ </select>++ <input+ type="text"+ name="search"+ value={@search}+ placeholder="Search by e-mail…"+ class="rounded-md border-gray-300 dark:border-gray-600 dark:bg-gray-800 text-sm"+ />+ </form>++ <div class="mt-4">+ <.table rows={@page.entries}>+ <:thead>+ <.th>E-mail</.th>+ <.th>Reason</.th>+ <.th>Source</.th>+ <.th>Status</.th>+ <.th>Suppressed</.th>+ <.th>Action</.th>+ </:thead>+ <:tbody :let={s}>+ <.td>{s.email}</.td>+ <.td>+ <.pill color={reason_color(s.reason)}>{reason_label(s.reason)}</.pill>+ </.td>+ <.td class="capitalize">{s.source}</.td>+ <.td>+ <div :if={is_nil(s.reactivated_at)}>+ <.pill color={:red}>Suppressed</.pill>+ </div>+ <div :if={s.reactivated_at}>+ <.pill color={:green}>Reactivated</.pill>+ <div class="text-xs text-gray-500 dark:text-gray-400 mt-1">+ by {reactivated_by_label(s)} on {format_datetime(s.reactivated_at)}+ </div>+ </div>+ </.td>+ <.td>{format_datetime(s.inserted_at)}</.td>+ <.td>+ <div class="flex flex-col items-start gap-1">+ <.styled_link+ :if={is_nil(s.reactivated_at) and s.reason != :spam_complaint}+ 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>++ <.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">+ Details+ </:button>+ <:menu class="w-80 p-3 text-xs text-gray-500 dark:text-gray-400 space-y-2">+ <div class="flex flex-wrap gap-x-4">+ <span :if={s.postmark_bounce_id}>+ <span class="font-medium">Bounce ID:</span> {s.postmark_bounce_id}+ </span>+ <span :if={s.postmark_inactive} class="font-medium">Inactive</span>+ </div>+ <.input_with_clipboard+ :if={s.details not in [nil, ""]}+ id={"suppression-details-input-#{s.id}"}+ name={"suppression-details-input-#{s.id}"}+ label="Postmark details"+ value={s.details}+ />+ </:menu>+ </.dropdown>+ </div>+ </.td>+ </:tbody>+ </.table>++ <div+ :if={@page.metadata.before || @page.metadata.after}+ class="flex justify-between items-center mt-4"+ >+ <.styled_link+ :if={@page.metadata.before}+ patch={+ ~p"/cs/email-suppressions?#{pagination_query(@reason, @search, before: @page.metadata.before)}"+ }+ >+ ← Previous+ </.styled_link>+ <div></div>+ <.styled_link+ :if={@page.metadata.after}+ patch={+ ~p"/cs/email-suppressions?#{pagination_query(@reason, @search, after: @page.metadata.after)}"+ }+ >+ Next →+ </.styled_link>+ </div>++ <p :if={@page.entries == []} class="text-sm text-gray-500 dark:text-gray-400">+ No suppressions found.+ </p>+ </div>+ </Layout.layout>+ """+ end++ defp has_postmark_details?(s) do+ not is_nil(s.postmark_bounce_id) or s.postmark_inactive or s.details not in [nil, ""]+ end++ defp reason_strings, do: Enum.map(@reasons, &Atom.to_string/1)++ defp pagination_query(reason, search, cursor) do+ [reason: reason, search: search]+ |> Keyword.merge(cursor)+ |> Enum.reject(fn {_key, value} -> value in [nil, ""] end)+ end++ defp reactivated_by_label(%{reactivated_by: %{email: email}}), do: email+ defp reactivated_by_label(_suppression), do: "unknown"++ defp format_datetime(nil), do: "—"+ defp format_datetime(%NaiveDateTime{} = dt), do: Calendar.strftime(dt, "%Y-%m-%d %H:%M UTC")++ defp reason_label(:hard_bounce), do: "Hard bounce"+ defp reason_label(:bad_email_address), do: "Bad address"+ defp reason_label(:blocked), do: "Blocked"+ defp reason_label(:spam_complaint), do: "Spam complaint"+ defp reason_label(:spam_notification), do: "Spam notification"+ defp reason_label(:unsubscribe), do: "Unsubscribed"+ defp reason_label(:manual), do: "Manual"++ defp reason_color(:spam_complaint), do: :red+ defp reason_color(:spam_notification), do: :red+ defp reason_color(:hard_bounce), do: :red+ defp reason_color(:blocked), do: :red+ defp reason_color(:bad_email_address), do: :yellow+ defp reason_color(:unsubscribe), do: :yellow+ defp reason_color(:manual), do: :gray+enddiff --git a/extra/lib/plausible_web/live/customer_support/team/components/members.ex b/extra/lib/plausible_web/live/customer_support/team/components/members.exindex 433a2390ef..603654a482 100644--- a/extra/lib/plausible_web/live/customer_support/team/components/members.ex+++ b/extra/lib/plausible_web/live/customer_support/team/components/members.ex@@ -4,6 +4,7 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.Members do"""use PlausibleWeb, :live_componentimport PlausibleWeb.CustomerSupport.Live+ import PlausibleWeb.CustomerSupport.Components.SuppressionWarningalias Plausible.Teamsdef update(%{team: team}, socket) do@@ -22,7 +23,7 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.Members do</:thead><:tbody :let={{_, member}}><.td truncate>- <div :if={member.id != 0}>+ <div :if={member.id != 0} class="flex items-center"><.styled_linkpatch={~p"/cs/users/user/#{member.id}"}class="cursor-pointer flex block items-center"@@ -33,13 +34,14 @@ defmodule PlausibleWeb.CustomerSupport.Team.Components.Members do/>{member.name} <{member.email}></.styled_link>+ <.suppression_warning email={member.email} /></div><div :if={member.id == 0} class="flex items-center"><imgsrc={Plausible.Auth.User.profile_img_url(%Plausible.Auth.User{email: member.email})}class="mr-4 w-6 rounded-full bg-gray-300"/>- {member.name} <{member.email}>+ {member.name} <{member.email}> <.suppression_warning email={member.email} /></div></.td><.td>diff --git a/extra/lib/plausible_web/live/customer_support/user.ex b/extra/lib/plausible_web/live/customer_support/user.exindex b658f2e3fe..510bda9ce2 100644--- a/extra/lib/plausible_web/live/customer_support/user.ex+++ b/extra/lib/plausible_web/live/customer_support/user.ex@@ -8,6 +8,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.User douse PlausibleWeb.CustomerSupport.Liveimport Ecto.Query+ import PlausibleWeb.CustomerSupport.Components.SuppressionWarningalias Plausible.Repoalias PlausibleWeb.CustomerSupport.User.Components.{@@ -73,7 +74,10 @@ defmodule PlausibleWeb.Live.CustomerSupport.User do</span></div></p>- <p class="text-sm font-medium">{@user.email}</p>+ <p class="text-sm font-medium flex items-center gap-x-1">+ {@user.email}+ <.suppression_warning email={@user.email} />+ </p></div></div>diff --git a/lib/plausible_web/live/super_admin_live_auth.ex b/lib/plausible_web/live/super_admin_live_auth.exindex 10d14069af..71ed577e4b 100644--- a/lib/plausible_web/live/super_admin_live_auth.ex+++ b/lib/plausible_web/live/super_admin_live_auth.ex@@ -5,6 +5,7 @@ defmodule PlausibleWeb.Live.SuperAdminLiveAuth do"""import Phoenix.LiveView, only: [redirect: 2]+ import Phoenix.Component, only: [assign: 3]alias PlausibleWeb.UserAuth@@ -16,7 +17,7 @@ defmodule PlausibleWeb.Live.SuperAdminLiveAuth doendif Plausible.Auth.super_admin?(current_user) do- {:cont, socket}+ {:cont, assign(socket, :current_user, current_user)}else{:halt, redirect(socket, to: "/")}enddiff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.exindex ee746d6951..a47f5609d6 100644--- a/lib/plausible_web/router.ex+++ b/lib/plausible_web/router.ex@@ -130,6 +130,9 @@ defmodule PlausibleWeb.Router dolive "/cs/trial-prospects", CustomerSupport.TrialProspects, :index,as: :customer_support_trial_prospects+ live "/cs/email-suppressions", CustomerSupport.EmailSuppressions, :index,+ as: :customer_support_email_suppressions+live "/cs/teams/team/:id", CustomerSupport.Team, :show, as: :customer_support_teamlive "/cs/users/user/:id", CustomerSupport.User, :show, as: :customer_support_userlive "/cs/sites/site/:id", CustomerSupport.Site, :show, as: :customer_support_sitediff --git a/test/plausible/email_suppressions_test.exs b/test/plausible/email_suppressions_test.exsindex 3fc3d07b82..497fe6cf7f 100644--- a/test/plausible/email_suppressions_test.exs+++ b/test/plausible/email_suppressions_test.exs@@ -6,8 +6,8 @@ defmodule Plausible.EmailSuppressionsTest do@moduletag :ee_only- # Suppressions without Bounce ID (backfilled)- # go through delete suppressions API call on reactivate.+ # Suppressions without Bounce ID (backfilled)+ # go through delete suppressions API call on reactivate.# Tests that expect different result may override this.setup doReq.Test.stub(Postmark, fn conn ->diff --git a/test/plausible_web/live/customer_support/email_suppressions_test.exs b/test/plausible_web/live/customer_support/email_suppressions_test.exsnew file mode 100644index 0000000000..6b716d5d25--- /dev/null+++ b/test/plausible_web/live/customer_support/email_suppressions_test.exs@@ -0,0 +1,245 @@+defmodule PlausibleWeb.Live.CustomerSupport.EmailSuppressionsTest do+ use PlausibleWeb.ConnCase, async: false+ @moduletag :ee_only++ on_ee do+ import Phoenix.LiveViewTest++ alias Plausible.EmailSuppressions+ alias Plausible.Postmark+ alias Plausible.Repo++ defp open_suppressions(qs \\ []) do+ ~p"/cs/email-suppressions?#{qs}"+ end++ setup [:create_user, :log_in]++ setup %{user: user} do+ patch_env(:super_admin_user_ids, [user.id])+ end++ # default to end 2 end success+ # tests can overwrite this stub+ setup do+ Req.Test.stub(Postmark, fn conn ->+ Req.Test.json(conn, %{+ "Message" => "OK",+ "Suppressions" => [%{"Status" => "Deleted"}]+ })+ end)++ :ok+ end++ test "renders suppressions, most recently suppressed first", %{conn: conn} do+ {:ok, _} =+ EmailSuppressions.create_from_bounce(%{+ email: "[email protected]",+ reason: :hard_bounce,+ source: :webhook,+ postmark_bounce_id: 12_345,+ postmark_inactive: true,+ can_activate: true,+ details: "Unknown user"+ })++ {:ok, _} =+ EmailSuppressions.create_from_spam_complaint(%{+ email: "[email protected]",+ source: :backfill+ })++ {:ok, _lv, html} = live(conn, open_suppressions())+ text = text(html)++ assert text =~ "E-mail suppressions"+ assert text =~ "[email protected]"+ assert text =~ "[email protected]"+ assert text =~ "Hard bounce"+ assert text =~ "Spam complaint"++ hard_row = text_of_element(html, "tbody tr:last-child")+ assert hard_row =~ "Details"+ assert hard_row =~ "Bounce ID: 12345"+ assert hard_row =~ "Inactive"++ assert html =~ "Unknown user"++ # most recently suppressed (complainer) listed first+ assert text_of_element(html, "tbody tr:first-child") =~ "[email protected]"+ end++ test "filters by reason", %{conn: conn} do+ {:ok, _} =+ EmailSuppressions.create_from_bounce(%{+ email: "[email protected]",+ reason: :hard_bounce,+ source: :webhook+ })++ {:ok, _} =+ EmailSuppressions.create_from_bounce(%{+ email: "[email protected]",+ reason: :blocked,+ source: :webhook+ })++ {:ok, _lv, html} = live(conn, open_suppressions(reason: "blocked"))+ text = text(html)++ assert text =~ "[email protected]"+ refute text =~ "[email protected]"+ end++ test "filters by an e-mail substring", %{conn: conn} do+ {:ok, _} =+ EmailSuppressions.create_from_bounce(%{+ email: "[email protected]",+ reason: :hard_bounce,+ source: :webhook+ })++ {:ok, _} =+ EmailSuppressions.create_from_bounce(%{+ email: "[email protected]",+ reason: :hard_bounce,+ source: :webhook+ })++ {:ok, _lv, html} = live(conn, open_suppressions(search: "findme"))+ text = text(html)++ assert text =~ "[email protected]"+ refute text =~ "[email protected]"+ end++ test "reactivates a suppressed address and records who did it", %{conn: conn, user: user} do+ {:ok, _} =+ EmailSuppressions.create_from_bounce(%{+ email: "[email protected]",+ reason: :hard_bounce,+ source: :webhook+ })++ {:ok, lv, _html} = live(conn, open_suppressions())++ html =+ lv+ |> element(~s|a[phx-value-email="[email protected]"]|, "Reactivate")+ |> render_click()++ assert text(html) =~ "no longer suppressed"+ assert text(html) =~ "Reactivated"++ suppression = Repo.get_by!(Plausible.EmailSuppression, email: "[email protected]")+ assert suppression.reactivated_at+ assert suppression.reactivated_by_user_id == user.id+ refute EmailSuppressions.suppressed?("[email protected]")+ end++ test "also deletes the suppression in Postmark when reactivating", %{conn: conn} do+ {:ok, _} =+ EmailSuppressions.create_from_bounce(%{+ email: "[email protected]",+ reason: :hard_bounce,+ source: :backfill+ })++ Req.Test.stub(Postmark, fn conn ->+ assert conn.request_path in [+ "/message-streams/outbound/suppressions/delete",+ "/message-streams/priority/suppressions/delete"+ ]++ Req.Test.json(conn, %{+ "Suppressions" => [+ %{"EmailAddress" => "[email protected]", "Status" => "Deleted"}+ ]+ })+ end)++ {:ok, lv, _html} = live(conn, open_suppressions())++ html =+ lv+ |> element(~s|a[phx-value-email="[email protected]"]|, "Reactivate")+ |> render_click()++ assert text(html) =~ "no longer suppressed"+ end++ test "does not offer to reactivate a spam complaint", %{conn: conn} do+ {:ok, _} =+ EmailSuppressions.create_from_spam_complaint(%{+ email: "[email protected]",+ source: :backfill+ })++ {:ok, lv, _html} = live(conn, open_suppressions())++ refute lv+ |> element(~s|a[phx-value-email="[email protected]"]|)+ |> has_element?()+ end++ test "refuses to reactivate when Postmark's deletion call fails", %{conn: conn} do+ {:ok, _} =+ EmailSuppressions.create_from_bounce(%{+ email: "[email protected]",+ reason: :hard_bounce,+ source: :backfill+ })++ Req.Test.stub(Postmark, fn conn ->+ conn |> Plug.Conn.put_status(500) |> Req.Test.json(%{"Message" => "boom"})+ end)++ {:ok, lv, _html} = live(conn, open_suppressions())++ html =+ lv+ |> element(~s|a[phx-value-email="[email protected]"]|, "Reactivate")+ |> render_click()++ assert text(html) =~ "Could not reactivate [email protected]"+ assert EmailSuppressions.suppressed?("[email protected]")+ end++ test "does not offer to reactivate an address that's already reactivated", %{+ conn: conn,+ user: user+ } do+ {:ok, _} =+ EmailSuppressions.create_from_bounce(%{+ email: "[email protected]",+ reason: :hard_bounce,+ source: :webhook+ })++ {:ok, _} = EmailSuppressions.reactivate("[email protected]", user)++ {:ok, lv, _html} = live(conn, open_suppressions())++ refute lv+ |> element(~s|a[phx-value-email="[email protected]"]|)+ |> has_element?()+ end++ test "does not offer a Details popup when a suppression has no Postmark metadata", %{+ conn: conn+ } do+ {:ok, _} =+ EmailSuppressions.create_from_bounce(%{+ email: "[email protected]",+ reason: :hard_bounce,+ source: :webhook+ })++ {:ok, _lv, html} = live(conn, open_suppressions())++ assert elem_count(html, "tbody tr") == 1+ refute text_of_element(html, "tbody tr") =~ "Details"+ end+ end+enddiff --git a/test/plausible_web/live/customer_support/teams_test.exs b/test/plausible_web/live/customer_support/teams_test.exsindex 5e1b138a31..bbeabfd107 100644--- a/test/plausible_web/live/customer_support/teams_test.exs+++ b/test/plausible_web/live/customer_support/teams_test.exs@@ -312,6 +312,43 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest doendend+ describe "members" do+ test "shows no suppression warning for a member whose e-mail isn't suppressed", %{+ conn: conn,+ user: user+ } do+ team = team_of(user)+ member = add_member(team, user: new_user(email: "[email protected]"), role: :editor)++ {:ok, _lv, html} = live(conn, open_team(team.id, tab: "members"))++ refute element_exists?(+ html,+ ~s|a[href="#{~p"/cs/email-suppressions?#{[search: member.email]}"}"]|+ )+ end++ test "shows a suppression warning linking to the suppression search for a suppressed member",+ %{conn: conn, user: user} do+ team = team_of(user)+ member = add_member(team, user: new_user(email: "[email protected]"), role: :editor)++ {:ok, _} =+ Plausible.EmailSuppressions.create_from_bounce(%{+ email: member.email,+ reason: :hard_bounce,+ source: :webhook+ })++ {:ok, _lv, html} = live(conn, open_team(team.id, tab: "members"))++ assert element_exists?(+ html,+ ~s|a[href="#{~p"/cs/email-suppressions?#{[search: member.email]}"}"]|+ )+ end+ end+describe "sites" do@arrow_down "↓"@arrow_up "↑"diff --git a/test/plausible_web/live/customer_support/users_test.exs b/test/plausible_web/live/customer_support/users_test.exsindex 4ab38f2bd9..8e8e1d5314 100644--- a/test/plausible_web/live/customer_support/users_test.exs+++ b/test/plausible_web/live/customer_support/users_test.exs@@ -85,6 +85,43 @@ defmodule PlausibleWeb.Live.CustomerSupport.UsersTest doendend+ describe "e-mail suppression warning" do+ setup [:create_user, :log_in, :create_site]++ setup %{user: user} do+ patch_env(:super_admin_user_ids, [user.id])+ end++ test "shows no warning when the user's e-mail isn't suppressed", %{+ conn: conn,+ user: user+ } do+ {:ok, _lv, html} = live(conn, open_user(user.id))++ refute element_exists?(+ html,+ ~s|a[href="#{~p"/cs/email-suppressions?#{[search: user.email]}"}"]|+ )+ end++ test "shows a warning linking to the suppression search when the user's e-mail is suppressed",+ %{conn: conn, user: user} do+ {:ok, _} =+ Plausible.EmailSuppressions.create_from_bounce(%{+ email: user.email,+ reason: :hard_bounce,+ source: :webhook+ })++ {:ok, _lv, html} = live(conn, open_user(user.id))++ assert element_exists?(+ html,+ ~s|a[href="#{~p"/cs/email-suppressions?#{[search: user.email]}"}"]|+ )+ end+ end+describe "keys" dosetup [:create_user, :log_in, :create_site]diff --git a/test/plausible_web/live/customer_support_test.exs b/test/plausible_web/live/customer_support_test.exsindex f7753fa78f..4fbbfa78a1 100644--- a/test/plausible_web/live/customer_support_test.exs+++ b/test/plausible_web/live/customer_support_test.exs@@ -225,6 +225,47 @@ defmodule PlausibleWeb.Live.CustomerSupportTest doassert_search_result(html, "site", site.id)end++ test "does not show a suppression warning for a user whose e-mail isn't suppressed", %{+ conn: conn+ } do+ target = new_user(email: "[email protected]")++ {:ok, lv, _html} = live(conn, @cs_index)++ type_into_input(lv, "filter-text", "user:[email protected]")+ html = render(lv)++ assert_search_result(html, "user", target.id)++ refute element_exists?(+ html,+ ~s|a[data-test-type="user"][data-test-id="#{target.id}"] svg[title*="suppressed"]|+ )+ end++ test "shows a suppression warning for a user whose e-mail is suppressed", %{conn: conn} do+ target = new_user(email: "[email protected]")++ {:ok, _} =+ Plausible.EmailSuppressions.create_from_bounce(%{+ email: target.email,+ reason: :hard_bounce,+ source: :webhook+ })++ {:ok, lv, _html} = live(conn, @cs_index)++ type_into_input(lv, "filter-text", "user:[email protected]")+ html = render(lv)++ assert_search_result(html, "user", target.id)++ assert element_exists?(+ html,+ ~s|a[data-test-type="user"][data-test-id="#{target.id}"] svg[title*="suppressed"]|+ )+ endenddefp assert_search_result(doc, type, id) do