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
Keep google auth deletions idempotent (#5656)
Adam Rutkowski3a720b5d6040
diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.exindex 9690a9df78..c3fce2106e 100644--- a/lib/plausible_web/controllers/site_controller.ex+++ b/lib/plausible_web/controllers/site_controller.ex@@ -300,10 +300,11 @@ defmodule PlausibleWeb.SiteController doconn.assigns[:site]|> Repo.preload(:google_auth)- Repo.delete!(site.google_auth)-- conn = put_flash(conn, :success, "Google account unlinked from Plausible")+ if site.google_auth do+ Repo.delete!(site.google_auth)+ end+ put_flash(conn, :success, "Google account unlinked from Plausible")redirect(conn, to: Routes.site_path(conn, :settings_integrations, site.domain))enddiff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exsindex 5c3de15602..894bd9866f 100644--- a/test/plausible_web/controllers/site_controller_test.exs+++ b/test/plausible_web/controllers/site_controller_test.exs@@ -867,6 +867,21 @@ defmodule PlausibleWeb.SiteControllerTest do"/#{URI.encode_www_form(site.domain)}/settings/integrations"end+ test "won't crash if associated google auth has been already deleted", %{+ conn: conn1,+ user: user,+ site: site+ } do+ insert(:google_auth, user: user, site: site)+ delete(conn1, "/#{site.domain}/settings/google-search")+ conn = delete(conn1, "/#{site.domain}/settings/google-search")++ refute Repo.exists?(Plausible.Site.GoogleAuth)++ assert redirected_to(conn, 302) ==+ "/#{URI.encode_www_form(site.domain)}/settings/integrations"+ end+test "fails to delete associated google auth from the outside", %{conn: conn,user: user