Template
## Summary - Port Monica campaign UTM + piha.li minting into always-on `core` (`shortener.py`, `campaign_utm.py`) so `email_sms` and `directmail` stay optional and never import each other. - `utm_source` is a slug of `SITE_NAME` (override with `UTM_SOURCE`). Email gets an HTML `data-campaign-utm` link; SMS gets a plain URL; postcard QR only — no body inject. - Live composer mints through login+CSRF `POST /portal/campaigns/short-link/` (registered only when an outreach app is installed). Empty `SHORTENER_*` falls back to the long UTM URL. Reference: [monica_site PR #10](ai_ml_operations/monica_site#10) Closes #3 ## Test plan - [x] `cd site && uv run python manage.py test` (125 tests) - [ ] Email composer: type a name, confirm HTML link + `utm_campaign` updates, save draft - [ ] SMS composer: plain `piha.li` (or long UTM if shortener unset) in the body - [ ] Postcard composer: QR copies the tracked URL; campaign body has no `utm_source` - [ ] Campaign report pages show the same panel - [ ] With `FEATURE_EMAIL_SMS` and `FEATURE_DIRECT_MAIL` off, no extra nav and no `/portal/campaigns/short-link/` route Reviewed-on: #4
106 lines
2.3 KiB
Bash
Executable File
106 lines
2.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}"
|
|
_true() { [[ "${1:-}" =~ ^(1|true|yes|on)$ ]]; }
|
|
|
|
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
|
|
)
|
|
fi
|
|
|
|
if [[ "$DJANGO_ENV" == "prod" ]]; then
|
|
required_vars+=(
|
|
SITE_UNDER_CONSTRUCTION
|
|
TIANJI_WEBSITE_ID
|
|
)
|
|
fi
|
|
|
|
if _true "${FEATURE_EMAIL_SMS:-}"; then
|
|
required_vars+=(
|
|
EMAIL_HOST_USER
|
|
EMAIL_HOST_PASSWORD
|
|
SMTP2GO_SMS_API_KEY
|
|
SMTP2GO_WEBHOOK_SECRET
|
|
)
|
|
fi
|
|
if _true "${FEATURE_DIRECT_MAIL:-}"; then
|
|
required_vars+=(
|
|
PCM_API_KEY
|
|
PCM_API_SECRET
|
|
PCM_WEBHOOK_SECRETS
|
|
PCM_RETURN_ADDRESS
|
|
)
|
|
fi
|
|
if _true "${FEATURE_EMAIL_SMS:-}" || _true "${FEATURE_DIRECT_MAIL:-}"; then
|
|
if [[ "$DJANGO_ENV" == "prod" || "$DJANGO_ENV" == "beta" ]]; then
|
|
required_vars+=(
|
|
SHORTENER_BASE_URL
|
|
SHORTENER_API_TOKEN
|
|
)
|
|
fi
|
|
fi
|
|
if _true "${FEATURE_PAYMENTS:-}"; then
|
|
required_vars+=(
|
|
STRIPE_SECRET_KEY
|
|
STRIPE_PUBLISHABLE_KEY
|
|
STRIPE_WEBHOOK_SECRET
|
|
)
|
|
if ! _true "${FEATURE_EMAIL_SMS:-}"; then
|
|
echo "FEATURE_PAYMENTS requires FEATURE_EMAIL_SMS" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
if _true "${FEATURE_SOCIAL:-}"; then
|
|
required_vars+=(SOCIAL_TOKEN_ENCRYPTION_KEY)
|
|
fi
|
|
if _true "${FEATURE_SOCIAL_AI:-}"; then
|
|
required_vars+=(OLLAMA_BASE_URL OLLAMA_MODEL)
|
|
if ! _true "${FEATURE_SOCIAL:-}"; then
|
|
echo "FEATURE_SOCIAL_AI requires FEATURE_SOCIAL" >&2
|
|
exit 1
|
|
fi
|
|
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/<slug>_site/<slug>_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)."
|