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
Export email copy change when the site will be deleted before the link expires (#6796)
Marko Saric57f734e3dbc5
diff --git a/lib/plausible_web/email.ex b/lib/plausible_web/email.exindex 3a32d30b5b..991d18e305 100644--- a/lib/plausible_web/email.ex+++ b/lib/plausible_web/email.ex@@ -512,6 +512,8 @@ defmodule PlausibleWeb.Email dodownload_url =url(~p"/#{site.domain}/download/export?#{[__team: site.team.identifier]}")+ deletion_date = export_deletion_date(site.team, expires_at)+priority_email()|> to(user)|> tag("export-success")@@ -520,7 +522,8 @@ defmodule PlausibleWeb.Email douser: user,site: site,download_url: download_url,- expires_in: expires_in+ expires_in: expires_in,+ deletion_date: deletion_date)end@@ -721,4 +724,21 @@ defmodule PlausibleWeb.Email do|> Enum.join(" ")end)end++ # The download only works while the site exists. When the team's scheduled+ # deletion lands before the export link expires, the email says so, so the+ # export isn't lost to the deletion. A deletion on the same day as the expiry+ # counts too, since it may run earlier in the day. A snoozed schedule is on hold, and an+ # export without an expiry (local storage) only ends with the deletion.+ defp export_deletion_date(team, expires_at) do+ case Plausible.TeamDeletionSchedules.active_schedule_for_team(team) do+ %{status: status, deletion_date: %Date{} = deletion_date} when status != :snoozed ->+ if is_nil(expires_at) or Date.compare(deletion_date, DateTime.to_date(expires_at)) != :gt do+ deletion_date+ end++ _ ->+ nil+ end+ endenddiff --git a/lib/plausible_web/templates/email/export_success.html.heex b/lib/plausible_web/templates/email/export_success.html.heexindex 2b6fe55679..98af5ff928 100644--- a/lib/plausible_web/templates/email/export_success.html.heex+++ b/lib/plausible_web/templates/email/export_success.html.heex@@ -1,6 +1,10 @@Your {Plausible.product_name()} export for {@site.domain} is now ready for download.Please click <a href={@download_url}>here</a>to start the download process.-<%= if @expires_in do %>- Note that this link will expire {@expires_in}.+<%= cond do %>+ <% @deletion_date -> %>+ Your stats for {@site.domain} are scheduled to be deleted on {date_format(@deletion_date)}, and this link stops working then, so please download your export before that date.+ <% @expires_in -> %>+ Note that this link will expire {@expires_in}.+ <% true -> %><% end %>diff --git a/test/plausible_web/email_test.exs b/test/plausible_web/email_test.exsindex dbefcbcbab..2719afa03f 100644--- a/test/plausible_web/email_test.exs+++ b/test/plausible_web/email_test.exs@@ -596,6 +596,68 @@ defmodule PlausibleWeb.EmailTest doendend+ describe "export_success/3" do+ setup do+ user = new_user()+ site = new_site(owner: user) |> Plausible.Repo.preload(:team)++ {:ok, user: user, site: site}+ end++ test "warns when the team's deletion falls before the link expires", %{user: user, site: site} do+ insert(:team_deletion_schedule, team: site.team, deletion_date: ~D[2026-10-21])++ %{html_body: body} = Email.export_success(user, site, ~U[2026-10-27 03:10:00Z])++ assert text(body) =~+ "Your stats for #{site.domain} are scheduled to be deleted on 21 Oct 2026, and this link stops working then"++ refute body =~ "Note that this link will expire"+ end++ test "warns when the deletion falls on the same day the link expires", %{+ user: user,+ site: site+ } do+ insert(:team_deletion_schedule, team: site.team, deletion_date: ~D[2026-10-27])++ %{html_body: body} = Email.export_success(user, site, ~U[2026-10-27 03:10:00Z])++ assert text(body) =~+ "Your stats for #{site.domain} are scheduled to be deleted on 27 Oct 2026"++ refute body =~ "Note that this link will expire"+ end++ test "says nothing when the deletion falls after the link expires", %{user: user, site: site} do+ insert(:team_deletion_schedule, team: site.team, deletion_date: ~D[2026-11-30])++ %{html_body: body} = Email.export_success(user, site, ~U[2026-10-27 03:10:00Z])++ refute body =~ "scheduled to be deleted"+ assert body =~ "Note that this link will expire"+ end++ test "says nothing while the deletion is snoozed", %{user: user, site: site} do+ insert(:team_deletion_schedule,+ team: site.team,+ deletion_date: ~D[2026-10-21],+ status: :snoozed,+ snoozed_until: ~D[2026-12-01]+ )++ %{html_body: body} = Email.export_success(user, site, ~U[2026-10-27 03:10:00Z])++ refute body =~ "scheduled to be deleted"+ end++ test "says nothing when no deletion is scheduled", %{user: user, site: site} do+ %{html_body: body} = Email.export_success(user, site, ~U[2026-10-27 03:10:00Z])++ refute body =~ "scheduled to be deleted"+ end+ end+describe "text_body" dotest "welcome email" doemail =