add typesecs and docstrings
This commit is contained in:
parent
8112173ef4
commit
8b527f618a
@ -10,6 +10,7 @@ defmodule BasicSignupAllowlist do
|
|||||||
@doc """
|
@doc """
|
||||||
Returns the name of the environment variable used for the signup allowlist.
|
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
|
def signup_allowlist_emails, do: @signup_allowlist_emails
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
@ -33,6 +34,7 @@ defmodule BasicSignupAllowlist do
|
|||||||
true
|
true
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@spec signup_allowed?(String.t()) :: boolean()
|
||||||
def signup_allowed?(email) do
|
def signup_allowed?(email) do
|
||||||
env_value = System.get_env(@signup_allowlist_emails)
|
env_value = System.get_env(@signup_allowlist_emails)
|
||||||
signup_allowed_fun(env_value, email)
|
signup_allowed_fun(env_value, email)
|
||||||
|
|||||||
@ -1,14 +1,30 @@
|
|||||||
defmodule FunCore.BasicSignupAllowlist do
|
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
|
def normalize(email) do
|
||||||
email |> String.trim() |> String.downcase()
|
email |> String.trim() |> String.downcase()
|
||||||
end
|
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
|
def addresses_as_list(addresses_str) do
|
||||||
addresses_str
|
addresses_str
|
||||||
|> String.split(",")
|
|> String.split(",")
|
||||||
|> Enum.map(&normalize/1)
|
|> Enum.map(&normalize/1)
|
||||||
end
|
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
|
def signup_allowed_fun(signups_allowed, email_received) do
|
||||||
case signups_allowed do
|
case signups_allowed do
|
||||||
nil -> false
|
nil -> false
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user