diff --git a/lib/plausible/site.ex b/lib/plausible/site.ex index f18fc5b03..35b9dc2e5 100644 --- a/lib/plausible/site.ex +++ b/lib/plausible/site.ex @@ -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 diff --git a/lib/plausible/site/custom_domain.ex b/lib/plausible/site/custom_domain.ex deleted file mode 100644 index 325b72bb0..000000000 --- a/lib/plausible/site/custom_domain.ex +++ /dev/null @@ -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 diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex index c4a493c01..0b9949939 100644 --- a/lib/plausible_web/controllers/site_controller.ex +++ b/lib/plausible_web/controllers/site_controller.ex @@ -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) diff --git a/lib/plausible_web/live/goal_settings/form.ex b/lib/plausible_web/live/goal_settings/form.ex index 1a5b28233..4da4681cf 100644 --- a/lib/plausible_web/live/goal_settings/form.ex +++ b/lib/plausible_web/live/goal_settings/form.ex @@ -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) diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.ex index d8bfc57e1..099361d92 100644 --- a/lib/plausible_web/router.ex +++ b/lib/plausible_web/router.ex @@ -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 diff --git a/lib/plausible_web/templates/site/settings_custom_domain.html.eex b/lib/plausible_web/templates/site/settings_custom_domain.html.eex deleted file mode 100644 index 304eff671..000000000 --- a/lib/plausible_web/templates/site/settings_custom_domain.html.eex +++ /dev/null @@ -1,39 +0,0 @@ -
-
-
- -
-
-

- Deprecated feature -

-
-

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

-
-
-
-
- -
-
-

Custom domain

-

Serve the tracking script from your domain name as a first-party resource instead of loading the script from our domain.

- - <%= link(to: "https://plausible.io/docs/proxy/introduction", target: "_blank") do %> - - <% end %> -
-
- <%= if @site.custom_domain do %> - - Configured domain: <%= @site.custom_domain.domain %> - - <%= 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 %> -
-
diff --git a/lib/plausible_web/views/layout_view.ex b/lib/plausible_web/views/layout_view.ex index 092b6871d..4a83eaeca 100644 --- a/lib/plausible_web/views/layout_view.ex +++ b/lib/plausible_web/views/layout_view.ex @@ -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 diff --git a/lib/plausible_web/views/site_view.ex b/lib/plausible_web/views/site_view.ex index 6c95abeb3..b7f97920f 100644 --- a/lib/plausible_web/views/site_view.ex +++ b/lib/plausible_web/views/site_view.ex @@ -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" """ diff --git a/priv/repo/migrations/20231127132321_remove_custom_domains.exs b/priv/repo/migrations/20231127132321_remove_custom_domains.exs new file mode 100644 index 000000000..d53307a9b --- /dev/null +++ b/priv/repo/migrations/20231127132321_remove_custom_domains.exs @@ -0,0 +1,7 @@ +defmodule Plausible.Repo.Migrations.RemoveCustomDomains do + use Ecto.Migration + + def change do + drop table(:custom_domains) + end +end diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exs index a7601a429..258c2ca9d 100644 --- a/test/plausible_web/controllers/site_controller_test.exs +++ b/test/plausible_web/controllers/site_controller_test.exs @@ -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] diff --git a/test/support/factory.ex b/test/support/factory.ex index 6ee76a287..4b3606ee8 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -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