Keep google auth deletions idempotent (#5656)

This commit is contained in:
Adam Rutkowski 2025-08-20 10:11:02 +02:00 committed by GitHub
parent ac739da694
commit 3a720b5d60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View File

@ -300,10 +300,11 @@ defmodule PlausibleWeb.SiteController do
conn.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))
end

View File

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