Add Sign up ENV flag (#2526)

Why:

* During the beta launch, sign-ups will need to be disabled to make sure
no unexpected accounts are created.
This commit is contained in:
bmanifold
2023-10-30 22:04:32 -04:00
committed by GitHub
parent 6c28f90219
commit 2e55d37b38
4 changed files with 59 additions and 4 deletions

View File

@@ -113,6 +113,10 @@ defmodule Domain.Config do
end
end
def sign_up_enabled? do
compile_config!(Definitions, :feature_sign_up_enabled)
end
## Test helpers
if Mix.env() != :test do

View File

@@ -604,4 +604,13 @@ defmodule Domain.Config.Definitions do
default: nil,
changeset: {Logo, :changeset, []}
)
##############################################
## Feature Flags
##############################################
@doc """
Boolean flag to turn Sign-ups on/off.
"""
defconfig(:feature_sign_up_enabled, :boolean, default: true)
end

View File

@@ -1,6 +1,6 @@
defmodule Web.SignUp do
use Web, {:live_view, layout: {Web.Layouts, :public}}
alias Domain.{Auth, Accounts, Actors}
alias Domain.{Auth, Accounts, Actors, Config}
alias Web.Registration
defmodule Registration do
@@ -37,6 +37,15 @@ defmodule Web.SignUp do
actor: %{type: :account_admin_user}
})
socket =
assign(socket,
form: to_form(changeset),
account: nil,
sign_up_enabled?: Config.sign_up_enabled?()
)
{:ok, socket}
{:ok, assign(socket, form: to_form(changeset), account: nil)}
end
@@ -61,8 +70,9 @@ defmodule Web.SignUp do
</:separator>
<:item>
<.sign_up_form :if={@account == nil} flash={@flash} form={@form} />
<.welcome :if={@account} account={@account} />
<.sign_up_form :if={@account == nil && @sign_up_enabled?} flash={@flash} form={@form} />
<.welcome :if={@account && @sign_up_enabled?} account={@account} />
<.sign_up_disabled :if={!@sign_up_enabled?} />
</:item>
</.intersperse_blocks>
</div>
@@ -187,6 +197,29 @@ defmodule Web.SignUp do
"""
end
def sign_up_disabled(assigns) do
~H"""
<div class="space-y-6">
<div class="text-xl text-center text-gray-900 dark:text-white">
Sign-ups are currently disabled.
</div>
<div class="text-center">
Please contact
<a class={link_style()} href="mailto:sales@firezone.dev?subject=Firezone Sign Up Request">
sales@firezone.dev
</a>
for more information.
</div>
<p class="text-xs text-center">
By signing up you agree to our <.link
href="https://www.firezone.dev/terms"
class="text-blue-600 dark:text-blue-500 hover:underline"
>Terms of Use</.link>.
</p>
</div>
"""
end
def handle_event("validate", %{"registration" => attrs}, socket) do
changeset =
%Registration{}
@@ -206,7 +239,7 @@ defmodule Web.SignUp do
|> Registration.changeset(attrs)
|> Map.put(:action, :insert)
if changeset.valid? do
if changeset.valid? && socket.assigns.sign_up_enabled? do
registration = Ecto.Changeset.apply_changes(changeset)
multi =

View File

@@ -78,4 +78,13 @@ defmodule Web.Live.SignUpTest do
"registration[email]" => ["has invalid format"]
}
end
test "renders signup disabled message", %{conn: conn} do
Domain.Config.put_system_env_override(:feature_sign_up_enabled, false)
{:ok, _lv, html} = live(conn, ~p"/sign_up")
assert html =~ "Sign-ups are currently disabled"
assert html =~ "sales@firezone.dev"
end
end