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
import FunCore.BasicSignupWhitelist
defmodule BasicSignupAllowlist do
import FunCore.BasicSignupAllowlist
@moduledoc """
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:
* Environment variable doesn't exist
* Environment variable is empty string
* Email not found in whitelist
* Email not found in allowlist
## Examples
iex> System.delete_env("SIGNUP_ALLOWLIST_EMAILS")
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
iex> BasicSignupAllowlist.mail_allowlisted("joe@example.com")
false
iex> System.put_env("SIGNUP_ALLOWLIST_EMAILS","*")
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
iex> BasicSignupAllowlist.mail_allowlisted("joe@example.com")
true
"""
def mail_whitelisted(email) do
def mail_allowlisted(email) do
env_value = System.get_env("SIGNUP_ALLOWLIST_EMAILS")
mail_whitelisted_fun(env_value, email)
mail_allowlisted_fun(env_value, email)
end
end

View File

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

View File

@ -1,9 +1,9 @@
defmodule BasicSignupWhitelist.MixProject do
defmodule BasicSignupAllowlist.MixProject do
use Mix.Project
def project do
[
app: :basic_signup_whitelist,
app: :basic_signup_allowlist,
version: "0.1.0",
elixir: "~> 1.18",
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
doctest BasicSignupWhitelist
doctest BasicSignupAllowlist
defp allow_signups_for(whitelist) do
System.put_env("SIGNUP_ALLOWLIST_EMAILS", whitelist)
defp allow_signups_for(allowlist) do
System.put_env("SIGNUP_ALLOWLIST_EMAILS", allowlist)
end
describe "setup in describe block" do
@ -16,14 +16,14 @@ defmodule BasicSignupWhitelistTest do
:ok
end
test "When not set, not whitelisted" do
test "When not set, not allowlisted" do
System.delete_env("SIGNUP_ALLOWLIST_EMAILS")
refute BasicSignupWhitelist.mail_whitelisted("joe@example.com")
refute BasicSignupAllowlist.mail_allowlisted("joe@example.com")
end
test "When set to star, whitelisted" do
test "When set to star, allowlisted" do
allow_signups_for("*")
assert BasicSignupWhitelist.mail_whitelisted("joe@example.com")
assert BasicSignupAllowlist.mail_allowlisted("joe@example.com")
end
end
end

View File

@ -1,6 +1,6 @@
defmodule FunCore.BasicSignupWhitelistTest do
defmodule FunCore.BasicSignupAllowlistTest do
use ExUnit.Case
import FunCore.BasicSignupWhitelist
import FunCore.BasicSignupAllowlist
test "addresses_as_list" do
assert addresses_as_list("joe@example.com, jane@example.com") == [
@ -14,27 +14,27 @@ defmodule FunCore.BasicSignupWhitelistTest do
assert "jane@example.com" in lst
end
describe "Not whitelisted when allowed list is" do
describe "Not allowlisted when allowed list is" do
test "not set" do
refute(mail_whitelisted_fun(nil, "joe@example.com"))
refute(mail_allowlisted_fun(nil, "joe@example.com"))
end
test "empty" do
refute(mail_whitelisted_fun("j", "joe@example.com"))
refute(mail_allowlisted_fun("j", "joe@example.com"))
end
end
describe "Whitelisted when" do
test "*" do
assert(mail_whitelisted_fun("*", "jane@example.com"))
assert(mail_allowlisted_fun("*", "jane@example.com"))
end
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
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