Remove custom domains - including migration

pull/3559/head
Adam Rutkowski 3 years ago
parent 6893886d0a
commit 4f77d837fe

@ -39,7 +39,6 @@ defmodule Plausible.Site do
has_one :google_auth, GoogleAuth
has_one :weekly_report, Plausible.Site.WeeklyReport
has_one :monthly_report, Plausible.Site.MonthlyReport
has_one :custom_domain, Plausible.Site.CustomDomain
has_one :spike_notification, Plausible.Site.SpikeNotification
has_one :ownership, Plausible.Site.Membership, where: [role: :owner]
has_one :owner, through: [:ownership, :user]
@ -49,7 +48,7 @@ defmodule Plausible.Site do
# strictly necessary.
field :from_cache?, :boolean, virtual: true, default: false
# Used in the context of paginated sites list to order in relation to
# Used in the context of paginated sites list to order in relation to
# user's membership state. Currently it can be either "invitation",
# "pinned_site" or "site", where invitations are first.
field :entry_type, :string, virtual: true

@ -1,11 +0,0 @@
defmodule Plausible.Site.CustomDomain do
use Ecto.Schema
schema "custom_domains" do
field :domain, :string
field :has_ssl_certificate, :boolean
belongs_to :site, Plausible.Site
timestamps()
end
end

@ -61,7 +61,7 @@ defmodule PlausibleWeb.SiteController do
def add_snippet(conn, _params) do
user = conn.assigns[:current_user]
site = conn.assigns[:site] |> Repo.preload(:custom_domain)
site = conn.assigns[:site]
is_first_site =
!Repo.exists?(
@ -121,9 +121,7 @@ defmodule PlausibleWeb.SiteController do
end
def settings_general(conn, _params) do
site =
conn.assigns[:site]
|> Repo.preload([:custom_domain])
site = conn.assigns[:site]
conn
|> render("settings_general.html",
@ -137,7 +135,7 @@ defmodule PlausibleWeb.SiteController do
def settings_people(conn, _params) do
site =
conn.assigns[:site]
|> Repo.preload(memberships: :user, invitations: [], custom_domain: [])
|> Repo.preload(memberships: :user, invitations: [])
conn
|> render("settings_people.html",
@ -148,7 +146,7 @@ defmodule PlausibleWeb.SiteController do
end
def settings_visibility(conn, _params) do
site = conn.assigns[:site] |> Repo.preload(:custom_domain)
site = conn.assigns[:site]
shared_links = Repo.all(from l in Plausible.Site.SharedLink, where: l.site_id == ^site.id)
conn
@ -161,7 +159,7 @@ defmodule PlausibleWeb.SiteController do
end
def settings_goals(conn, _params) do
site = Repo.preload(conn.assigns[:site], [:custom_domain, :owner])
site = Repo.preload(conn.assigns[:site], [:owner])
owner = Plausible.Users.with_subscription(site.owner)
site = Map.put(site, :owner, owner)
@ -175,7 +173,7 @@ defmodule PlausibleWeb.SiteController do
end
def settings_funnels(conn, _params) do
site = Repo.preload(conn.assigns[:site], [:custom_domain, :owner])
site = Repo.preload(conn.assigns[:site], [:owner])
owner = Plausible.Users.with_subscription(site.owner)
site = Map.put(site, :owner, owner)
@ -189,7 +187,7 @@ defmodule PlausibleWeb.SiteController do
end
def settings_props(conn, _params) do
site = Repo.preload(conn.assigns[:site], [:custom_domain, :owner])
site = Repo.preload(conn.assigns[:site], [:owner])
owner = Plausible.Users.with_subscription(site.owner)
site = Map.put(site, :owner, owner)
@ -203,7 +201,7 @@ defmodule PlausibleWeb.SiteController do
end
def settings_email_reports(conn, _params) do
site = conn.assigns[:site] |> Repo.preload(:custom_domain)
site = conn.assigns[:site]
conn
|> render("settings_email_reports.html",
@ -216,21 +214,8 @@ defmodule PlausibleWeb.SiteController do
)
end
def settings_custom_domain(conn, _params) do
site =
conn.assigns[:site]
|> Repo.preload(:custom_domain)
conn
|> assign(:skip_plausible_tracking, true)
|> render("settings_custom_domain.html",
site: site,
layout: {PlausibleWeb.LayoutView, "site_settings.html"}
)
end
def settings_danger_zone(conn, _params) do
site = conn.assigns[:site] |> Repo.preload(:custom_domain)
site = conn.assigns[:site]
conn
|> render("settings_danger_zone.html",
@ -243,7 +228,7 @@ defmodule PlausibleWeb.SiteController do
def settings_integrations(conn, _params) do
site =
conn.assigns.site
|> Repo.preload([:google_auth, :custom_domain])
|> Repo.preload([:google_auth])
search_console_domains =
if site.google_auth do
@ -295,7 +280,7 @@ defmodule PlausibleWeb.SiteController do
end
def update_settings(conn, %{"site" => site_params}) do
site = conn.assigns[:site] |> Repo.preload(:custom_domain)
site = conn.assigns[:site]
changeset = Plausible.Site.update_changeset(site, site_params)
case Repo.update(changeset) do
@ -624,27 +609,6 @@ defmodule PlausibleWeb.SiteController do
end
end
def delete_custom_domain(conn, %{"id" => domain_id}) do
site = conn.assigns[:site]
site_id = site.id
case Repo.delete_all(
from d in Plausible.Site.CustomDomain,
where: d.site_id == ^site_id,
where: d.id == ^domain_id
) do
{1, _} ->
conn
|> put_flash(:success, "Custom domain deleted successfully")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/general")
{0, _} ->
conn
|> put_flash(:error, "Failed to delete custom domain")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/general")
end
end
def import_from_google_user_metric_notice(conn, %{
"view_id" => view_id,
"access_token" => access_token,
@ -874,7 +838,7 @@ defmodule PlausibleWeb.SiteController do
end
def add_snippet_after_domain_change(conn, _params) do
site = conn.assigns[:site] |> Repo.preload(:custom_domain)
site = conn.assigns[:site]
conn
|> assign(:skip_plausible_tracking, true)

@ -24,7 +24,7 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do
site =
user_id
|> Plausible.Sites.get_for_user!(domain, [:owner, :admin, :super_admin])
|> Repo.preload([:custom_domain, :owner])
|> Repo.preload([:owner])
owner = Plausible.Users.with_subscription(site.owner)
site = Map.put(site, :owner, owner)

@ -278,8 +278,6 @@ defmodule PlausibleWeb.Router do
put "/sites/:website/shared-links/:slug", SiteController, :update_shared_link
delete "/sites/:website/shared-links/:slug", SiteController, :delete_shared_link
delete "/sites/:website/custom-domains/:id", SiteController, :delete_custom_domain
get "/sites/:website/memberships/invite", Site.MembershipController, :invite_member_form
post "/sites/:website/memberships/invite", Site.MembershipController, :invite_member
@ -311,7 +309,6 @@ defmodule PlausibleWeb.Router do
end
get "/:website/settings/email-reports", SiteController, :settings_email_reports
get "/:website/settings/custom-domain", SiteController, :settings_custom_domain
get "/:website/settings/danger-zone", SiteController, :settings_danger_zone
get "/:website/settings/integrations", SiteController, :settings_integrations

@ -1,39 +0,0 @@
<div class="rounded-md bg-yellow-50 dark:bg-transparent dark:border border-yellow-200 p-4">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-yellow-400 dark:text-yellow-300" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-yellow-800 dark:text-yellow-400">
Deprecated feature
</h3>
<div class="mt-2 text-sm text-yellow-700 dark:text-yellow-300">
<p>
We are moving away from CNAME-based custom domains. If you're concerned about adblockers, we recommend
<%= link("setting up a proxy", class: "underline text-yellow-800 dark:text-yellow-400", to: "https://plausible.io/docs/proxy/introduction", target: "_blank", rel: "noferrer") %> for your analytics script instead.
</p>
</div>
</div>
</div>
</div>
<div class="shadow bg-white dark:bg-gray-800 sm:rounded-md sm:overflow-hidden py-6 px-4 sm:p-6">
<header class="relative">
<h2 class="text-lg leading-6 font-medium text-gray-900 dark:text-gray-100">Custom domain</h2>
<p class="mt-1 text-sm leading-5 text-gray-500 dark:text-gray-200">Serve the tracking script from your domain name as a first-party resource instead of loading the script from our domain.</p>
<%= link(to: "https://plausible.io/docs/proxy/introduction", target: "_blank") do %>
<svg class="w-6 h-6 absolute top-0 right-0 text-gray-400" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"></path></svg>
<% end %>
</header>
<div class="mt-6 dark:text-gray-100 flex justify-between items-center">
<%= if @site.custom_domain do %>
<span>
Configured domain: <b><%= @site.custom_domain.domain %></b>
</span>
<%= link("Remove custom domain", to: "/sites/#{URI.encode_www_form(@site.domain)}/custom-domains/#{@site.custom_domain.id}", 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") %>
<% end %>
</div>
</div>

@ -83,9 +83,7 @@ defmodule PlausibleWeb.LayoutView do
[key: "Custom Properties", value: "properties"],
[key: "Integrations", value: "integrations"],
[key: "Email Reports", value: "email-reports"],
if !is_selfhost() && conn.assigns[:site].custom_domain do
[key: "Custom domain", value: "custom-domain"]
end,
# XXX
if conn.assigns[:current_user_role] == :owner do
[key: "Danger zone", value: "danger-zone"]
end
@ -125,6 +123,7 @@ defmodule PlausibleWeb.LayoutView do
end
defp is_selfhost() do
# XXX
Application.get_env(:plausible, :is_selfhost)
end
end

@ -23,12 +23,7 @@ defmodule PlausibleWeb.SiteView do
end
def render_snippet(site) do
tracker =
if site.custom_domain do
"https://" <> site.custom_domain.domain <> "/js/index.js"
else
"#{plausible_url()}/js/script.js"
end
tracker = "#{plausible_url()}/js/script.js"
"""
<script defer data-domain="#{site.domain}" src="#{tracker}"></script>

@ -0,0 +1,7 @@
defmodule Plausible.Repo.Migrations.RemoveCustomDomains do
use Ecto.Migration
def change do
drop table(:custom_domains)
end
end

@ -552,7 +552,6 @@ defmodule PlausibleWeb.SiteControllerTest do
test "deletes the site", %{conn: conn, user: user} do
site = insert(:site, members: [user])
insert(:google_auth, user: user, site: site)
insert(:custom_domain, site: site)
insert(:spike_notification, site: site)
delete(conn, "/#{site.domain}")
@ -563,7 +562,6 @@ defmodule PlausibleWeb.SiteControllerTest do
test "fails to delete a site with insufficient permissions", %{conn: conn, user: user} do
site = insert(:site, memberships: [build(:site_membership, user: user, role: :viewer)])
insert(:google_auth, user: user, site: site)
insert(:custom_domain, site: site)
insert(:spike_notification, site: site)
conn = delete(conn, "/#{site.domain}")
@ -581,7 +579,6 @@ defmodule PlausibleWeb.SiteControllerTest do
insert(:site, memberships: [build(:site_membership, user: other_user, role: "owner")])
insert(:google_auth, user: other_user, site: other_site)
insert(:custom_domain, site: other_site)
insert(:spike_notification, site: other_site)
my_conn = delete(my_conn, "/#{other_site.domain}")
@ -1229,35 +1226,6 @@ defmodule PlausibleWeb.SiteControllerTest do
end
end
describe "DELETE sites/:website/custom-domains/:id" do
setup [:create_user, :log_in, :create_site]
test "deletes custom domain", %{conn: conn, site: site} do
domain = insert(:custom_domain, site: site)
conn = delete(conn, "/sites/#{site.domain}/custom-domains/#{domain.id}")
assert Phoenix.Flash.get(conn.assigns.flash, :success) ==
"Custom domain deleted successfully"
assert Repo.aggregate(Plausible.Site.CustomDomain, :count, :id) == 0
end
test "fails to delete custom domain not owning it", %{conn: conn, site: site} do
_og_domain = insert(:custom_domain, site: site)
foreign_site = insert(:site)
foreign_domain = insert(:custom_domain, site: foreign_site)
assert Repo.aggregate(Plausible.Site.CustomDomain, :count, :id) == 2
conn = delete(conn, "/sites/#{site.domain}/custom-domains/#{foreign_domain.id}")
assert Phoenix.Flash.get(conn.assigns.flash, :error) == "Failed to delete custom domain"
assert Repo.aggregate(Plausible.Site.CustomDomain, :count, :id) == 2
end
end
describe "GET /:website/import/google-analytics/view-id" do
setup [:create_user, :log_in, :create_new_site]

@ -135,12 +135,6 @@ defmodule Plausible.Factory do
}
end
def custom_domain_factory do
%Plausible.Site.CustomDomain{
domain: sequence(:custom_domain, &"domain-#{&1}.com")
}
end
def weekly_report_factory do
%Plausible.Site.WeeklyReport{}
end

Loading…
Cancel
Save