Render an error on site creation with domain=domain_changed_from (#2821)

This commit is contained in:
hq1 2023-04-05 11:57:20 +02:00 committed by GitHub
parent ffc96205f6
commit 406ea6f0cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -57,6 +57,10 @@ defmodule Plausible.Site do
|> unique_constraint(:domain,
message: @domain_unique_error
)
|> unique_constraint(:domain,
name: "domain_change_disallowed",
message: @domain_unique_error
)
end
def update_changeset(site, attrs \\ %{}, opts \\ []) do

View File

@ -284,6 +284,23 @@ defmodule PlausibleWeb.SiteControllerTest do
assert html_response(conn, 200) =~
"This domain cannot be registered. Perhaps one of your colleagues registered it?"
end
test "renders form again when domain was changed from elsewhere", %{conn: conn} do
:site
|> insert(domain: "example.com")
|> Plausible.Site.Domain.change("new.example.com")
conn =
post(conn, "/sites", %{
"site" => %{
"domain" => "example.com",
"timezone" => "Europe/London"
}
})
assert html_response(conn, 200) =~
"This domain cannot be registered. Perhaps one of your colleagues registered it?"
end
end
describe "GET /:website/snippet" do