Keep google auth deletions idempotent (#5656)
This commit is contained in:
parent
ac739da694
commit
3a720b5d60
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue