From d77afa397253423c6564845e608f8bad64d69710 Mon Sep 17 00:00:00 2001 From: Alexey Grigorev Date: Sat, 3 Oct 2026 06:19:06 +0200 Subject: [PATCH] Add a separate public list for the agent git lab. Production keeps the PocketShell list and adds agent-git-lab for alexeygrigorev.com, with its own audience, client, and confirmation template. --- .../commands/provision_public_signup.py | 24 +++++++--- mailing/tests/test_public_subscribe.py | 45 +++++++++++++++++++ scripts/deploy_relay_sandbox.sh | 6 ++- templates/agent-git-lab/confirm-signup.md | 16 +++++++ 4 files changed, 83 insertions(+), 8 deletions(-) create mode 100644 templates/agent-git-lab/confirm-signup.md diff --git a/mailing/management/commands/provision_public_signup.py b/mailing/management/commands/provision_public_signup.py index 5a16d8f..9d6146e 100644 --- a/mailing/management/commands/provision_public_signup.py +++ b/mailing/management/commands/provision_public_signup.py @@ -13,6 +13,12 @@ SENDERS = { "pocketshell": ("hello", "PocketShell "), + "agent-git-lab": ("hello", "Agent Git Lab "), +} + +NAMES = { + "pocketshell": "PocketShell", + "agent-git-lab": "Agent Git Lab", } @@ -36,25 +42,31 @@ def _provision(self, spec): sender_id, sender_value = SENDERS[spec.key] sender_email = normalize_sender_email(sender_value) - organization, _ = Organization.objects.update_or_create( + label = NAMES.get(spec.key, spec.organization_slug) + organization, _ = Organization.objects.get_or_create( slug=spec.organization_slug, - defaults={"name": spec.organization_slug}, + defaults={"name": label}, ) - audience, _ = Audience.objects.update_or_create( + audience, _ = Audience.objects.get_or_create( organization=organization, slug=spec.audience_slug, - defaults={"name": spec.audience_slug}, + defaults={"name": label}, ) - client, _ = Client.objects.update_or_create( + client, created = Client.objects.get_or_create( organization=organization, slug=spec.client_slug, defaults={ - "name": spec.client_slug, + "name": label, "is_active": True, "default_sender_id": sender_id, "sender_emails": [{"id": sender_id, "email": sender_email}], }, ) + if not created: + client.is_active = True + client.default_sender_id = sender_id + client.sender_emails = [{"id": sender_id, "email": sender_email}] + client.save() template_path = Path(settings.BASE_DIR) / "templates" / spec.key / f"{spec.template_key}.md" if not template_path.is_file(): raise CommandError(f"Missing template file {template_path}.") diff --git a/mailing/tests/test_public_subscribe.py b/mailing/tests/test_public_subscribe.py index 76f3103..9882718 100644 --- a/mailing/tests/test_public_subscribe.py +++ b/mailing/tests/test_public_subscribe.py @@ -1,4 +1,5 @@ import pytest +from django.core.management import call_command from django.test import override_settings from django.urls import reverse from django.utils import timezone @@ -165,3 +166,47 @@ def test_public_preflight_is_an_empty_204(client): def test_parse_public_lists_rejects_a_broken_entry(): with pytest.raises(Exception): parse_public_lists("pocketshell client=only") + + +def test_parse_public_lists_keeps_agent_git_lab_beside_pocketshell(): + lists = parse_public_lists( + "pocketshell org=pocketshell client=pocketshell audience=pocketshell " + "category=newsletter template=confirm-signup confirm_base=https://pocketshell.io/; " + "agent-git-lab org=agent-git-lab client=agent-git-lab audience=agent-git-lab " + "category=newsletter template=confirm-signup " + "confirm_base=https://alexeygrigorev.com/cloudflare-agent-git/subscribe/" + ) + + assert lists["pocketshell"].confirm_base_url == "https://pocketshell.io" + lab = lists["agent-git-lab"] + assert lab.client_slug == "agent-git-lab" + assert lab.audience_slug == "agent-git-lab" + assert lab.organization_slug == "agent-git-lab" + assert lab.confirm_base_url == "https://alexeygrigorev.com/cloudflare-agent-git/subscribe" + + +BOTH_LISTS = ( + "pocketshell org=pocketshell client=pocketshell audience=pocketshell " + "category=newsletter template=confirm-signup confirm_base=https://pocketshell.io/; " + "agent-git-lab org=agent-git-lab client=agent-git-lab audience=agent-git-lab " + "category=newsletter template=confirm-signup " + "confirm_base=https://alexeygrigorev.com/cloudflare-agent-git/subscribe/" +) + + +@override_settings(RELAY_PUBLIC_LISTS=BOTH_LISTS) +def test_provision_public_signup_adds_a_separate_list_without_renaming_pocketshell(pocketshell): + call_command("provision_public_signup") + + pocketshell["organization"].refresh_from_db() + pocketshell["client"].refresh_from_db() + assert pocketshell["organization"].name == "PocketShell" + assert pocketshell["client"].sender_emails == [{"id": "hello", "email": "PocketShell "}] + lab = Client.objects.get(slug="agent-git-lab") + assert lab.organization.slug == "agent-git-lab" + assert lab.organization_id != pocketshell["organization"].id + assert Audience.objects.get(slug="agent-git-lab").organization_id == lab.organization_id + assert lab.sender_emails == [{"id": "hello", "email": "Agent Git Lab "}] + template = EmailTemplate.objects.get(client=lab, key="confirm-signup") + assert template.subject == "Confirm your email" + assert template.is_active is True diff --git a/scripts/deploy_relay_sandbox.sh b/scripts/deploy_relay_sandbox.sh index 93ff856..0f23dd7 100755 --- a/scripts/deploy_relay_sandbox.sh +++ b/scripts/deploy_relay_sandbox.sh @@ -197,8 +197,8 @@ else if [[ -n "$sandbox_role" ]]; then set_runtime_value RELAY_SES_DOMAIN_ROUTES "dtcdev.click role=${sandbox_role} region=us-east-1 configuration_set=datamailer-sandbox;pocketshell.io role=${sandbox_role} region=us-east-1 configuration_set=datamailer-sandbox" fi - set_runtime_value RELAY_PUBLIC_LISTS 'pocketshell org=pocketshell client=pocketshell audience=pocketshell category=newsletter template=confirm-signup confirm_base=https://pocketshell.io/' - set_runtime_value RELAY_PUBLIC_SUBSCRIBE_ORIGINS 'https://pocketshell.io,https://www.pocketshell.io,http://localhost:4000,http://127.0.0.1:4000' + set_runtime_value RELAY_PUBLIC_LISTS 'pocketshell org=pocketshell client=pocketshell audience=pocketshell category=newsletter template=confirm-signup confirm_base=https://pocketshell.io/;agent-git-lab org=agent-git-lab client=agent-git-lab audience=agent-git-lab category=newsletter template=confirm-signup confirm_base=https://alexeygrigorev.com/cloudflare-agent-git/subscribe/' + set_runtime_value RELAY_PUBLIC_SUBSCRIBE_ORIGINS 'https://pocketshell.io,https://www.pocketshell.io,http://localhost:4000,http://127.0.0.1:4000,https://alexeygrigorev.com' if ! grep -q '^RELAY_TRANSFER_TOKEN=.' "$runtime_env"; then set_runtime_value RELAY_TRANSFER_TOKEN "$(openssl rand -hex 32)" fi @@ -319,6 +319,8 @@ else bash "$app_dir/scripts/provision_production_tenant.sh" fi +run_app python manage.py provision_public_signup + app_container_args=( --network host --env-file "$infra_env" diff --git a/templates/agent-git-lab/confirm-signup.md b/templates/agent-git-lab/confirm-signup.md new file mode 100644 index 0000000..b3eae3e --- /dev/null +++ b/templates/agent-git-lab/confirm-signup.md @@ -0,0 +1,16 @@ +--- +subject: Confirm your email +name: Agent Git Lab signup confirmation +category: transactional +required_context: + - name: confirm_url + description: Link that verifies this address +example_context: + confirm_url: https://alexeygrigorev.com/cloudflare-agent-git/subscribe/?token=example +--- + +Confirm your email to hear about the agent git lab. + +[Verify your email]({{ confirm_url }}) + +If you did not ask for this, you can ignore this message. The link expires in 48 hours.