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
Remove google auth from a site
Uku Taht0e17a4ecfd64
diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.exindex 7a8c531a6e..f81c19c411 100644--- a/lib/plausible_web/controllers/site_controller.ex+++ b/lib/plausible_web/controllers/site_controller.ex@@ -128,6 +128,18 @@ defmodule PlausibleWeb.SiteController do|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings#google-auth")end+ def delete_google_auth(conn, %{"website" => website}) do+ site =+ Sites.get_for_user!(conn.assigns[:current_user].id, website)+ |> Repo.preload(:google_auth)++ Repo.delete!(site.google_auth)++ conn+ |> put_flash(:success, "Google account unlinked succesfully")+ |> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings#google-auth")+ end+def update_settings(conn, %{"website" => website, "site" => site_params}) dosite = Sites.get_for_user!(conn.assigns[:current_user].id, website)changeset = site |> Plausible.Site.changeset(site_params)diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.exindex c399e16e29..b170f1b45e 100644--- a/lib/plausible_web/router.ex+++ b/lib/plausible_web/router.ex@@ -151,6 +151,7 @@ defmodule PlausibleWeb.Router dodelete "/:website/goals/:id", SiteController, :delete_goalput "/:website/settings", SiteController, :update_settingsput "/:website/settings/google", SiteController, :update_google_auth+ delete "/:website/settings/google", SiteController, :delete_google_authdelete "/:website", SiteController, :delete_siteget "/share/:slug", StatsController, :shared_linkdiff --git a/lib/plausible_web/templates/site/settings.html.eex b/lib/plausible_web/templates/site/settings.html.eexindex 0eb1125b84..65df0989cc 100644--- a/lib/plausible_web/templates/site/settings.html.eex+++ b/lib/plausible_web/templates/site/settings.html.eex@@ -104,7 +104,9 @@<%= if @site.google_auth do %><div class="py-2"></div>- <span class="text-gray-700">Connected Google account: <b><%= @site.google_auth.email %></b></span>+ <span class="text-gray-700">Linked Google account: <b><%= @site.google_auth.email %></b></span>++ <%= link("Unlink Google account", to: "/#{URI.encode_www_form(@site.domain)}/settings/google", class: "inline-block mt-4 px-4 py-2 border border-gray-300 text-sm leading-5 font-medium rounded-md text-red-700 bg-white hover:text-red-500 focus:outline-none focus:border-blue-300 focus:shadow-outline-blue active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150", method: "delete") %><%= if @site.google_auth.property && !(@site.google_auth.property in @search_console_domains) do %><p class="text-gray-700 mt-6 font-bold">@@ -112,7 +114,7 @@</p><% else %><p class="text-gray-700 mt-6">- Select the Google Search Console property you would like to pull keyword data from. If you don't see your domain, <%= link("set it up and verify", to: "https://docs.#{base_domain()}/google-search-console-integration#1-add-your-site-on-the-search-console", class: "text-indigo-500") %> on Search Console first.+ Select the Google Search Console property you would like to pull keyword data from. If you don't see your domain, <%= link("set it up and verify", to: "https://docs.#{base_domain()}/google-search-console-integration", class: "text-indigo-500") %> on Search Console first.</p><% end %>diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exsindex eeda8fc22a..4fd689816a 100644--- a/test/plausible_web/controllers/site_controller_test.exs+++ b/test/plausible_web/controllers/site_controller_test.exs@@ -147,6 +147,29 @@ defmodule PlausibleWeb.SiteControllerTest doendend+ describe "PUT /:website/settings/google" do+ setup [:create_user, :log_in, :create_site]++ test "updates google auth property", %{conn: conn, user: user, site: site} do+ insert(:google_auth, user: user, site: site)+ put(conn, "/#{site.domain}/settings/google", %{"google_auth" => %{"property" => "some-new-property.com"}})++ updated_auth = Repo.one(Plausible.Site.GoogleAuth)+ assert updated_auth.property == "some-new-property.com"+ end+ end++ describe "DELETE /:website/settings/google" do+ setup [:create_user, :log_in, :create_site]++ test "deletes associated google auth", %{conn: conn, user: user, site: site} do+ insert(:google_auth, user: user, site: site)+ delete(conn, "/#{site.domain}/settings/google")++ refute Repo.exists?(Plausible.Site.GoogleAuth)+ end+ end+describe "GET /:website/goals/new" dosetup [:create_user, :log_in, :create_site]