Allow custom domain to be deleted

pull/197/head
Uku Taht 6 years ago
parent 9edbf394f7
commit 9a91c6d901

@ -393,6 +393,17 @@ defmodule PlausibleWeb.SiteController do
end
end
def delete_custom_domain(conn, %{"website" => website}) do
site = Sites.get_for_user!(conn.assigns[:current_user].id, website)
|> Repo.preload(:custom_domain)
Repo.delete!(site.custom_domain)
conn
|> put_flash(:success, "Custom domain deleted succesfully")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings")
end
defp insert_site(user_id, params) do
site_changeset = Plausible.Site.changeset(%Plausible.Site{}, params)

@ -138,6 +138,7 @@ defmodule PlausibleWeb.Router do
get "/sites/:website/custom-domains/dns-setup", SiteController, :custom_domain_dns_setup
get "/sites/:website/custom-domains/snippet", SiteController, :custom_domain_snippet
post "/sites/:website/custom-domains", SiteController, :add_custom_domain
delete "/sites/:website/custom-domains/:id", SiteController, :delete_custom_domain
get "/sites/:website/weekly-report/unsubscribe", UnsubscribeController, :weekly_report
get "/sites/:website/monthly-report/unsubscribe", UnsubscribeController, :monthly_report

@ -211,6 +211,7 @@
<div class="mt-6">
<%= if @site.custom_domain do %>
Configured domain: <b><%= @site.custom_domain.domain %></b>
<%= 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 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") %>
<% else %>
<%= link("Add custom domain", to: "/sites/#{URI.encode_www_form(@site.domain)}/custom-domains/new", class: "button") %>
<% end %>

@ -408,4 +408,16 @@ defmodule PlausibleWeb.SiteControllerTest do
assert html_response(conn, 200) =~ "DNS for #{domain.domain}"
end
end
describe "DELETE sites/:website/custom-domains/:id" do
setup [:create_user, :log_in, :create_site]
test "lists goals for the site", %{conn: conn, site: site} do
domain = insert(:custom_domain, site: site)
delete(conn, "/sites/#{site.domain}/custom-domains/#{domain.id}")
assert Repo.aggregate(Plausible.Site.CustomDomain, :count, :id) == 0
end
end
end

Loading…
Cancel
Save