Rename to allowlist

This commit is contained in:
Your Name 2025-09-16 09:09:51 +00:00
parent 30548eae80
commit 490102c0a8
6 changed files with 73 additions and 27 deletions

View File

@ -1,5 +1,5 @@
defmodule BasicSignupWhitelist do defmodule BasicSignupAllowlist do
import FunCore.BasicSignupWhitelist import FunCore.BasicSignupAllowlist
@moduledoc """ @moduledoc """
Checks if an email address is allowed based on the SIGNUP_ALLOWLIST_EMAILS env variable. Checks if an email address is allowed based on the SIGNUP_ALLOWLIST_EMAILS env variable.
@ -14,20 +14,20 @@ defmodule BasicSignupWhitelist do
- Returns false if: - Returns false if:
* Environment variable doesn't exist * Environment variable doesn't exist
* Environment variable is empty string * Environment variable is empty string
* Email not found in whitelist * Email not found in allowlist
## Examples ## Examples
iex> System.delete_env("SIGNUP_ALLOWLIST_EMAILS") iex> System.delete_env("SIGNUP_ALLOWLIST_EMAILS")
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com") iex> BasicSignupAllowlist.mail_allowlisted("joe@example.com")
false false
iex> System.put_env("SIGNUP_ALLOWLIST_EMAILS","*") iex> System.put_env("SIGNUP_ALLOWLIST_EMAILS","*")
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com") iex> BasicSignupAllowlist.mail_allowlisted("joe@example.com")
true true
""" """
def mail_whitelisted(email) do def mail_allowlisted(email) do
env_value = System.get_env("SIGNUP_ALLOWLIST_EMAILS") env_value = System.get_env("SIGNUP_ALLOWLIST_EMAILS")
mail_whitelisted_fun(env_value, email) mail_allowlisted_fun(env_value, email)
end end
end end

View File

@ -1,4 +1,4 @@
defmodule FunCore.BasicSignupWhitelist do defmodule FunCore.BasicSignupAllowlist do
def normalize(email) do def normalize(email) do
email |> String.trim() |> String.downcase() email |> String.trim() |> String.downcase()
end end
@ -9,7 +9,7 @@ defmodule FunCore.BasicSignupWhitelist do
|> Enum.map(&normalize/1) |> Enum.map(&normalize/1)
end end
def mail_whitelisted_fun(signups_allowed, email_received) do def mail_allowlisted_fun(signups_allowed, email_received) do
case signups_allowed do case signups_allowed do
nil -> false nil -> false
"*" -> true "*" -> true

View File

@ -1,9 +1,9 @@
defmodule BasicSignupWhitelist.MixProject do defmodule BasicSignupAllowlist.MixProject do
use Mix.Project use Mix.Project
def project do def project do
[ [
app: :basic_signup_whitelist, app: :basic_signup_allowlist,
version: "0.1.0", version: "0.1.0",
elixir: "~> 1.18", elixir: "~> 1.18",
start_permanent: Mix.env() == :prod, start_permanent: Mix.env() == :prod,

46
rename_module.sh Executable file
View File

@ -0,0 +1,46 @@
#!/bin/bash
# Script to rename BasicSignupWhitelist module to BasicSignupAllowlist
# This includes renaming files, module names, function names, and all references
echo "Starting module rename from Whitelist to Allowlist..."
# 1. Rename the files
echo "Renaming files..."
if [ -f "lib/basic_signup_whitelist.ex" ]; then
mv lib/basic_signup_whitelist.ex lib/basic_signup_allowlist.ex
echo " ✓ Renamed lib/basic_signup_whitelist.ex to lib/basic_signup_allowlist.ex"
fi
if [ -f "test/basic_signup_whitelist_test.exs" ]; then
mv test/basic_signup_whitelist_test.exs test/basic_signup_allowlist_test.exs
echo " ✓ Renamed test/basic_signup_whitelist_test.exs to test/basic_signup_allowlist_test.exs"
fi
# 2. Replace all occurrences of BasicSignupWhitelist with BasicSignupAllowlist
echo "Updating module names..."
find . -type f \( -name "*.ex" -o -name "*.exs" \) -exec sed -i 's/BasicSignupWhitelist/BasicSignupAllowlist/g' {} +
echo " ✓ Updated module names from BasicSignupWhitelist to BasicSignupAllowlist"
# 3. Replace function names (mail_whitelisted -> mail_allowlisted)
echo "Updating function names..."
find . -type f \( -name "*.ex" -o -name "*.exs" \) -exec sed -i 's/mail_whitelisted/mail_allowlisted/g' {} +
echo " ✓ Updated function names from mail_whitelisted to mail_allowlisted"
# 4. Replace any remaining "whitelist" references in comments/docs with "allowlist"
echo "Updating remaining whitelist references..."
find . -type f \( -name "*.ex" -o -name "*.exs" \) -exec sed -i 's/whitelist/allowlist/g' {} +
echo " ✓ Updated all remaining references from whitelist to allowlist"
# 5. Update any references to the old filenames in mix.exs or other config files
echo "Checking for filename references in config files..."
if [ -f "mix.exs" ]; then
sed -i 's/basic_signup_whitelist/basic_signup_allowlist/g' mix.exs
echo " ✓ Updated references in mix.exs"
fi
echo ""
echo "Module rename complete! You may want to:"
echo " 1. Run 'mix test' to ensure all tests still pass"
echo " 2. Run 'mix compile --force' to recompile with the new module names"
echo " 3. Check any documentation or README files for references to update"

View File

@ -1,9 +1,9 @@
defmodule BasicSignupWhitelistTest do defmodule BasicSignupAllowlistTest do
use ExUnit.Case, async: false use ExUnit.Case, async: false
doctest BasicSignupWhitelist doctest BasicSignupAllowlist
defp allow_signups_for(whitelist) do defp allow_signups_for(allowlist) do
System.put_env("SIGNUP_ALLOWLIST_EMAILS", whitelist) System.put_env("SIGNUP_ALLOWLIST_EMAILS", allowlist)
end end
describe "setup in describe block" do describe "setup in describe block" do
@ -16,14 +16,14 @@ defmodule BasicSignupWhitelistTest do
:ok :ok
end end
test "When not set, not whitelisted" do test "When not set, not allowlisted" do
System.delete_env("SIGNUP_ALLOWLIST_EMAILS") System.delete_env("SIGNUP_ALLOWLIST_EMAILS")
refute BasicSignupWhitelist.mail_whitelisted("joe@example.com") refute BasicSignupAllowlist.mail_allowlisted("joe@example.com")
end end
test "When set to star, whitelisted" do test "When set to star, allowlisted" do
allow_signups_for("*") allow_signups_for("*")
assert BasicSignupWhitelist.mail_whitelisted("joe@example.com") assert BasicSignupAllowlist.mail_allowlisted("joe@example.com")
end end
end end
end end

View File

@ -1,6 +1,6 @@
defmodule FunCore.BasicSignupWhitelistTest do defmodule FunCore.BasicSignupAllowlistTest do
use ExUnit.Case use ExUnit.Case
import FunCore.BasicSignupWhitelist import FunCore.BasicSignupAllowlist
test "addresses_as_list" do test "addresses_as_list" do
assert addresses_as_list("joe@example.com, jane@example.com") == [ assert addresses_as_list("joe@example.com, jane@example.com") == [
@ -14,27 +14,27 @@ defmodule FunCore.BasicSignupWhitelistTest do
assert "jane@example.com" in lst assert "jane@example.com" in lst
end end
describe "Not whitelisted when allowed list is" do describe "Not allowlisted when allowed list is" do
test "not set" do test "not set" do
refute(mail_whitelisted_fun(nil, "joe@example.com")) refute(mail_allowlisted_fun(nil, "joe@example.com"))
end end
test "empty" do test "empty" do
refute(mail_whitelisted_fun("j", "joe@example.com")) refute(mail_allowlisted_fun("j", "joe@example.com"))
end end
end end
describe "Whitelisted when" do describe "Whitelisted when" do
test "*" do test "*" do
assert(mail_whitelisted_fun("*", "jane@example.com")) assert(mail_allowlisted_fun("*", "jane@example.com"))
end end
test "Multiple set and one match" do test "Multiple set and one match" do
assert(mail_whitelisted_fun("joe@example.com, jane@example.com", "jane@example.com")) assert(mail_allowlisted_fun("joe@example.com, jane@example.com", "jane@example.com"))
end end
test "Matches with different casings" do test "Matches with different casings" do
assert(mail_whitelisted_fun("joe@Example.com, jane@example.com", "Joe@example.com")) assert(mail_allowlisted_fun("joe@Example.com, jane@example.com", "Joe@example.com"))
end end
end end
end end