-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
797 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
defmodule Plausible.Site.Domain do | ||
@expire_threshold_hours 72 | ||
|
||
@moduledoc """ | ||
Basic interface for domain changes. | ||
Once V2 schema migration is ready, domain change operation | ||
will be enabled, accessible to the users. | ||
We will set a grace period of #{@expire_threshold_hours} hours | ||
during which both old and new domains will redirect events traffic | ||
to the same site. A periodic worker will call the `expire/0` | ||
function to end it where applicable. | ||
""" | ||
|
||
alias Plausible.Site | ||
alias Plausible.Repo | ||
|
||
import Ecto.Query | ||
|
||
@spec expire_change_transitions(integer()) :: {:ok, non_neg_integer()} | ||
def expire_change_transitions(expire_threshold_hours \\ @expire_threshold_hours) do | ||
{updated, _} = | ||
Repo.update_all( | ||
from(s in Site, | ||
where: s.domain_changed_at < ago(^expire_threshold_hours, "hour") | ||
), | ||
set: [ | ||
domain_changed_from: nil, | ||
domain_changed_at: nil | ||
] | ||
) | ||
|
||
{:ok, updated} | ||
end | ||
|
||
@spec change(Site.t(), String.t(), Keyword.t()) :: | ||
{:ok, Site.t()} | {:error, Ecto.Changeset.t()} | ||
def change(site = %Site{}, new_domain, opts \\ []) when is_binary(new_domain) do | ||
changeset = Site.update_changeset(site, %{domain: new_domain}, opts) | ||
|
||
changeset = | ||
if Enum.empty?(changeset.changes) do | ||
Ecto.Changeset.add_error( | ||
changeset, | ||
:domain, | ||
"New domain must be different than your current one." | ||
) | ||
else | ||
changeset | ||
end | ||
|
||
Repo.update(changeset) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<div class="w-full max-w-3xl mt-4 mx-auto flex"> | ||
<%= form_for @changeset, Routes.site_path(@conn, :change_domain_submit, @site.domain), [class: "max-w-lg w-full mx-auto bg-white dark:bg-gray-800 shadow-lg rounded px-8 pt-6 pb-8 mb-4 mt-8"], fn f -> %> | ||
<h2 class="text-xl font-black dark:text-gray-100">Change your website domain</h2> | ||
|
||
<div class="my-6"> | ||
<%= label f, :domain, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %> | ||
<p class="text-gray-500 dark:text-gray-400 text-xs mt-1">Just the naked domain or subdomain without 'www'</p> | ||
<div class="mt-2 flex rounded-md shadow-sm"> | ||
<span class="inline-flex items-center px-3 rounded-l-md border border-r-0 border-gray-300 dark:border-gray-500 bg-gray-50 dark:bg-gray-850 text-gray-500 dark:text-gray-400 sm:text-sm"> | ||
https:// | ||
</span> | ||
<%= text_input f, :domain, class: "focus:ring-indigo-500 focus:border-indigo-500 dark:bg-gray-800 flex-1 block w-full px-3 py-2 rounded-none rounded-r-md sm:text-sm border-gray-300 dark:border-gray-500 dark:bg-gray-900 dark:text-gray-300", placeholder: "example.com" %> | ||
</div> | ||
<%= error_tag f, :domain %> | ||
</div> | ||
|
||
<p class="text-sm sm:text-sm text-gray-700 dark:text-gray-300"> | ||
<span class="font-bold dark:text-gray-100">Once you change your domain, you must update the JavaScript snippet on your site within 72 hours to guarantee continuous tracking</span>. If you're using the API, please also make sure to update your API credentials.</p> | ||
<p class="text-sm sm:text-sm text-gray-700 dark:text-gray-300 mt-4"> | ||
Visit our <a target="_blank" href="https://plausible.io/docs/change-domain-name/" class="text-indigo-500">documentation</a> for details. | ||
</p> | ||
|
||
<%= submit "Change domain and add new snippet →", class: "button mt-4 w-full" %> | ||
|
||
<div class="text-center mt-8"> | ||
<%= link "Back to site settings", to: Routes.site_path(@conn, :settings_general, @site.domain), class: "text-indigo-500 w-full text-center" %> | ||
</div> | ||
<% end %> | ||
</div> |
Oops, something went wrong.