From 37d3f2e36e43011deaf471fa7eb811189291f3a0 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Fri, 26 Nov 2021 15:39:42 +0200 Subject: [PATCH] Make sure that deleting an account also deletes stats --- lib/plausible/sites.ex | 5 +++++ lib/plausible_web/controllers/auth_controller.ex | 2 +- lib/plausible_web/controllers/site_controller.ex | 3 +-- lib/plausible_web/templates/auth/user_settings.html.eex | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/plausible/sites.ex b/lib/plausible/sites.ex index 555ee1088..fd64058eb 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 27d24bd4d..8583d02af 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 35ddcc97e..20eec9746 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 16e1c4b36..97eb93ea6 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 @@

Deleting your account removes all sites and stats you've collected

<%= if @subscription && @subscription.status == "active" do %> - Delete my account + Delete my account

Your account cannot be deleted because you have an active subscription. If you want to delete your account, please cancel your subscription first.

<% 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 %>