add typesecs and docstrings
This commit is contained in:
parent
8112173ef4
commit
8b527f618a
@ -10,6 +10,7 @@ defmodule BasicSignupAllowlist do
|
||||
@doc """
|
||||
Returns the name of the environment variable used for the signup allowlist.
|
||||
"""
|
||||
@spec signup_allowlist_emails() :: String.t()
|
||||
def signup_allowlist_emails, do: @signup_allowlist_emails
|
||||
|
||||
@doc """
|
||||
@ -28,11 +29,12 @@ defmodule BasicSignupAllowlist do
|
||||
iex> System.delete_env("SIGNUP_ALLOWLIST_EMAILS")
|
||||
iex> BasicSignupAllowlist.signup_allowed?("joe@example.com")
|
||||
false
|
||||
iex> System.put_env("SIGNUP_ALLOWLIST_EMAILS","*")
|
||||
iex> System.put_env("SIGNUP_ALLOWLIST_EMAILS", "*")
|
||||
iex> BasicSignupAllowlist.signup_allowed?("joe@example.com")
|
||||
true
|
||||
|
||||
"""
|
||||
@spec signup_allowed?(String.t()) :: boolean()
|
||||
def signup_allowed?(email) do
|
||||
env_value = System.get_env(@signup_allowlist_emails)
|
||||
signup_allowed_fun(env_value, email)
|
||||
|
||||
@ -1,14 +1,30 @@
|
||||
defmodule FunCore.BasicSignupAllowlist do
|
||||
@moduledoc """
|
||||
Functional core for email allowlist checking logic.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Normalizes an email address by trimming whitespace and converting to lowercase.
|
||||
"""
|
||||
@spec normalize(String.t()) :: String.t()
|
||||
def normalize(email) do
|
||||
email |> String.trim() |> String.downcase()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Converts a comma-separated string of email addresses into a normalized list.
|
||||
"""
|
||||
@spec addresses_as_list(String.t()) :: [String.t()]
|
||||
def addresses_as_list(addresses_str) do
|
||||
addresses_str
|
||||
|> String.split(",")
|
||||
|> Enum.map(&normalize/1)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Checks if an email is allowed based on the allowlist configuration.
|
||||
"""
|
||||
@spec signup_allowed_fun(String.t() | nil, String.t()) :: boolean()
|
||||
def signup_allowed_fun(signups_allowed, email_received) do
|
||||
case signups_allowed do
|
||||
nil -> false
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user