## Summary Closes #9. - Campaign composer auto-inserts a tracked homepage link (`utm_source=monica`, `utm_medium` = channel, `utm_campaign` = slug of the name) for email, SMS, and postcard QR — no manual UTM paste. - When `SHORTENER_BASE_URL` + `SHORTENER_API_TOKEN` are set, the app mints that long HTTPS URL via `POST /api/links/` on the shortener **API host** and puts the returned `piha.li` / `beta.piha.li` short URL in SMS, email hrefs, and QR codes. Empty env (local) falls back to the long UTM URL. - Live composer resolves shorts through a portal JSON endpoint (login + CSRF). Browser never calls the shortener. ## Secrets (control node, not git) **monica_site** (`~/Documents/secrets/monica_site/`): ``` # prod SHORTENER_BASE_URL=https://shortener.aimloperations.com SHORTENER_API_TOKEN=monica:<secret> # beta SHORTENER_BASE_URL=https://shortener-beta.aimloperations.com SHORTENER_API_TOKEN=monica:<beta-secret> ``` **url_shortening_service** (same secret, named token): ``` SHORTENER_API_TOKENS=monica:<secret> SHORT_ALLOWED_HOSTS=mkdrealtor.com,aimloperations.com ``` Prod public short host: `piha.li`. Beta: `beta.piha.li`. Generate with `python -c "import secrets; print(secrets.token_urlsafe(32))"`. Template port: westfarn/web_django_template#3 ## Test plan - [ ] `cd site && uv run python manage.py test messaging.tests.CampaignUtmLinkTests` - [ ] Composer: type a campaign name — email gets an HTML link, SMS gets a URL, postcard shows a QR - [ ] With shortener env set: SMS/QR show `piha.li` (or `beta.piha.li`); without it, long UTM URL still works - [ ] Copy/download QR into postcard designer - [ ] Secret files have `SHORTENER_*` on both caller and operator sides before beta/prod deploy Reviewed-on: #10
63 lines
1.3 KiB
Bash
Executable File
63 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ENV_FILE="${1:?Usage: $0 <env-file>}"
|
|
|
|
if [[ ! -f "$ENV_FILE" ]]; then
|
|
echo "Environment file not found: $ENV_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
set -a
|
|
# shellcheck disable=SC1090
|
|
source "$ENV_FILE"
|
|
set +a
|
|
|
|
DJANGO_ENV="${DJANGO_ENV:-prod}"
|
|
|
|
required_vars=(
|
|
DJANGO_SECRET_KEY
|
|
DJANGO_ALLOWED_HOSTS
|
|
DATABASE_URL
|
|
WEB_PORT
|
|
)
|
|
|
|
if [[ "$DJANGO_ENV" == "prod" || "$DJANGO_ENV" == "beta" ]]; then
|
|
required_vars+=(
|
|
RECAPTCHA_PUBLIC_KEY
|
|
RECAPTCHA_PRIVATE_KEY
|
|
EMAIL_HOST_USER
|
|
EMAIL_HOST_PASSWORD
|
|
SHORTENER_BASE_URL
|
|
SHORTENER_API_TOKEN
|
|
)
|
|
fi
|
|
|
|
if [[ "$DJANGO_ENV" == "prod" ]]; then
|
|
required_vars+=(
|
|
SITE_UNDER_CONSTRUCTION
|
|
TIANJI_WEBSITE_ID
|
|
)
|
|
fi
|
|
|
|
missing=()
|
|
for var in "${required_vars[@]}"; do
|
|
if [[ -z "${!var:-}" ]]; then
|
|
missing+=("$var")
|
|
fi
|
|
done
|
|
|
|
if ((${#missing[@]} > 0)); then
|
|
echo "Missing required environment variables in $ENV_FILE:" >&2
|
|
printf ' - %s\n' "${missing[@]}" >&2
|
|
echo "Copy .env.prod.example to ~/Documents/secrets/monica_site/monica_site_${DJANGO_ENV}.env and set values." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ "$DJANGO_ENV" == "prod" && "$DJANGO_SECRET_KEY" == change-me* ]]; then
|
|
echo "DJANGO_SECRET_KEY must be changed from the example value for production." >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Environment validation passed (DJANGO_ENV=$DJANGO_ENV)."
|