Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Make sure that deleting an account also deletes stats

Uku Taht37d3f2e36e43
diff --git a/lib/plausible/sites.ex b/lib/plausible/sites.ex
index 555ee1088b..fd64058eb5 100644
--- a/lib/plausible/sites.ex
+++ b/lib/plausible/sites.ex
@@ -145,6 +145,11 @@ defmodule Plausible.Sites do
)
end
+ def delete!(site) do
+ Repo.delete!(site)
+ Plausible.ClickhouseRepo.clear_stats_for(site.domain)
+ end
+
def add_custom_domain(site, custom_domain) do
CustomDomain.changeset(%CustomDomain{}, %{
site_id: site.id,
diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex
index 27d24bd4de..8583d02af6 100644
--- a/lib/plausible_web/controllers/auth_controller.ex
+++ b/lib/plausible_web/controllers/auth_controller.ex
@@ -516,7 +516,7 @@ defmodule PlausibleWeb.AuthController do
Repo.delete!(membership)
if membership.role == :owner do
- Repo.delete!(membership.site)
+ Plausible.Sites.delete!(membership.site)
end
end
diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex
index 35ddcc97e5..20eec9746c 100644
--- a/lib/plausible_web/controllers/site_controller.ex
+++ b/lib/plausible_web/controllers/site_controller.ex
@@ -331,8 +331,7 @@ defmodule PlausibleWeb.SiteController do
def delete_site(conn, _params) do
site = conn.assigns[:site]
- Repo.delete!(site)
- Plausible.ClickhouseRepo.clear_stats_for(site.domain)
+ Plausible.Sites.delete!(site)
conn
|> put_flash(:success, "Site deleted successfully along with all pageviews")
diff --git a/lib/plausible_web/templates/auth/user_settings.html.eex b/lib/plausible_web/templates/auth/user_settings.html.eex
index 16e1c4b36f..97eb93ea61 100644
--- a/lib/plausible_web/templates/auth/user_settings.html.eex
+++ b/lib/plausible_web/templates/auth/user_settings.html.eex
@@ -223,9 +223,9 @@
<p class="dark:text-gray-100">Deleting your account removes all sites and stats you've collected</p>
<%= if @subscription && @subscription.status == "active" do %>
- <span class="mt-6 bg-gray-300 button dark:bg-gray-800 hover:shadow-none">Delete my account</span>
+ <span class="mt-6 bg-gray-300 button dark:bg-gray-800 hover:shadow-none hover:bg-gray-300">Delete my account</span>
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">Your account cannot be deleted because you have an active subscription. If you want to delete your account, please cancel your subscription first.</p>
<% else %>
- <%= link("Delete my account", to: "/me", class: "inline-block mt-4 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 dark:hover:text-red-400 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150", method: "delete", data: [confirm: "Deleting your account will also delete all the sites that you own. This action cannot be reversed. Are you sure?"]) %>
+ <%= link("Delete my account", to: "/me", class: "inline-block mt-4 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 dark:hover:text-red-400 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150", method: "delete", data: [confirm: "Deleting your account will also delete all the sites and data that you own. This action cannot be reversed. Are you sure?"]) %>
<% end %>
</div>