Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions mailing/management/commands/provision_public_signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

SENDERS = {
"pocketshell": ("hello", "PocketShell <hello@pocketshell.io>"),
"agent-git-lab": ("hello", "Agent Git Lab <hello@datatalks.club>"),
}

NAMES = {
"pocketshell": "PocketShell",
"agent-git-lab": "Agent Git Lab",
}


Expand All @@ -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}.")
Expand Down
45 changes: 45 additions & 0 deletions mailing/tests/test_public_subscribe.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 <hello@pocketshell.io>"}]
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 <hello@datatalks.club>"}]
template = EmailTemplate.objects.get(client=lab, key="confirm-signup")
assert template.subject == "Confirm your email"
assert template.is_active is True
6 changes: 4 additions & 2 deletions scripts/deploy_relay_sandbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions templates/agent-git-lab/confirm-signup.md
Original file line number Diff line number Diff line change
@@ -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.
Loading