Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c8d3f8a
Reset Django migrations baseline
NicholasBottone May 28, 2026
3c2e84f
Add premium subscriptions and casual server orchestration
NicholasBottone May 28, 2026
7dcda0d
Add migration checks to CI
NicholasBottone May 28, 2026
215f887
Use API key for subscription service calls
NicholasBottone May 28, 2026
05e5db2
Remove legacy subscription heartbeat endpoint
NicholasBottone May 31, 2026
d9f7eac
feat: use Polar credits for casual server usage
NicholasBottone Jul 7, 2026
7318903
chore: hide premium nav link before launch
NicholasBottone Jul 7, 2026
8eb6e5e
fix: preserve pending premium billing and launch review work
NicholasBottone Oct 29, 2026
8a5163d
fix: harden premium billing and server lifecycle for launch
NicholasBottone Oct 29, 2026
76eeb24
docs: clarify coordinated release deployment trigger
NicholasBottone Oct 29, 2026
9d82dba
fix: preserve customized subscription tiers during benefit cleanup
NicholasBottone Oct 29, 2026
7b46bfc
fix: allow isolated Discord OAuth application for staging
NicholasBottone Oct 29, 2026
9ddf6e8
docs: record live premium acceptance progress
NicholasBottone Oct 29, 2026
ab431ab
fix: avoid SQLite lock upgrade when recording server stop
NicholasBottone Oct 29, 2026
9235683
fix: preserve Polar webhook wire aliases
NicholasBottone Oct 29, 2026
7baf2d1
fix: remove Polar return credentials from URLs and logs
NicholasBottone Oct 29, 2026
182c917
fix: serialize launch responses with SQLite callbacks
NicholasBottone Oct 29, 2026
020a90c
fix: acquire callback write lock before reading session state
NicholasBottone Oct 29, 2026
ce9f470
docs: record end-to-end premium acceptance evidence and remaining gates
NicholasBottone Oct 29, 2026
65cd911
docs: specify isolated Polar Discord authorization setup
NicholasBottone Oct 30, 2026
6a23d44
docs: record connected Polar test guild and pending customer link
NicholasBottone Oct 30, 2026
ceaad19
docs: record verified Polar VIP role grant lifecycle
NicholasBottone Oct 30, 2026
933ea21
docs: record completed Discord role acceptance and cleanup
NicholasBottone Oct 30, 2026
7ad20fe
docs: refresh remaining launch gates after role acceptance
NicholasBottone Oct 30, 2026
48058bd
docs: record recurring billing acceptance and remaining live tests
NicholasBottone Oct 30, 2026
f63a0b7
docs: record fresh production migration rehearsal and runtime prerequ…
NicholasBottone Oct 30, 2026
eb4b78d
fix: charge minimum usage for subsecond ready sessions
NicholasBottone Oct 30, 2026
773b10e
docs: record failed renewal recovery and live billing regression
NicholasBottone Oct 30, 2026
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
40 changes: 40 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Django environment
# Use "development" locally. Omit or set a production value in production.
PYTHON_ENV=development

# Django/API secrets
SECRET_KEY=replace-me
API_KEY=replace-me

# Used in highscores clean-code decoding
NEW_AES_KEY=0123456789abcdef

# Discord OAuth (set a dedicated application ID for isolated testing)
DISCORD_CLIENT_ID=825618483957071873
DISCORD_REDIRECT_URI=
DISCORD_API_REDIRECT_URI=
DISCORD_CLIENT_SECRET=replace-me

# Email
SMTP_SERVER=smtp.example.com
SMTP_PASSWORD=replace-me

# Optional Discord webhook for highscores notifications
HIGHSCORES_WEBHOOK_URL=

# Polar subscriptions
POLAR_SERVER=production
# Optional override for self-hosted/proxy SDK API base URLs. Leave blank for Polar production/sandbox.
POLAR_API_BASE_URL=
POLAR_ACCESS_TOKEN=
POLAR_WEBHOOK_SECRET=
POLAR_CHECKOUT_SUCCESS_URL=
POLAR_CUSTOMER_PORTAL_URL=
POLAR_CASUAL_SERVER_METER_ID=
POLAR_CASUAL_SERVER_EVENT_NAME=casual_server_credits
POLAR_REQUEST_TIMEOUT_SECONDS=10

# xRC server orchestrator
ORCHESTRATOR_API_BASE_URL=
ORCHESTRATOR_API_TOKEN=
ORCHESTRATOR_REQUEST_TIMEOUT_SECONDS=10
94 changes: 68 additions & 26 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,97 @@
name: 🚀 Deploy Django
name: Deploy Django

on:
push:
branches: [main]

jobs:
build-deploy:
name: 🎉 Build and Deploy
validate:
name: Validate

runs-on: ubuntu-latest

steps:
- name: 🚚 Get latest code
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v4

- name: 🔨 Set up Python 3.12
uses: actions/setup-python@v2
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
python-version: "3.12"
cache: pip

- name: 🛠 Install Dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: ▶ Run Tests
run: |
python manage.py test
- name: Check for missing migrations
run: python manage.py makemigrations --check --dry-run
env:
SECRET_KEY: ci-secret-key
API_KEY: ci-api-key
NEW_AES_KEY: 0123456789abcdef
DISCORD_CLIENT_SECRET: ci-discord-secret

- name: Apply migrations on a fresh database
run: python manage.py migrate --noinput
env:
SECRET_KEY: ci-secret-key
API_KEY: ci-api-key
NEW_AES_KEY: 0123456789abcdef
DISCORD_CLIENT_SECRET: ci-discord-secret

- name: Run Django checks
run: python manage.py check
env:
SECRET_KEY: ci-secret-key
API_KEY: ci-api-key
NEW_AES_KEY: 0123456789abcdef
DISCORD_CLIENT_SECRET: ci-discord-secret

- name: Run tests
run: pytest
env:
SECRET_KEY: ${{ secrets.BASE_KEY }}
SMTP_SERVER: ${{ secrets.SMTP_SERVER }}
SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
NEW_AES_KEY: ${{ secrets.NEW_AES_KEY }}
DISCORD_CLIENT_SECRET: ${{ secrets.DISCORD_CLIENT_SECRET }}
SECRET_KEY: ci-secret-key
API_KEY: ci-api-key
NEW_AES_KEY: 0123456789abcdef
DISCORD_CLIENT_SECRET: ci-discord-secret

build-deploy:
name: Build and Deploy
needs: validate

- name: 📦 Collect Static Files
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip

- name: Install dependencies
run: |
python manage.py collectstatic --noinput
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Collect static files
run: python manage.py collectstatic --noinput
env:
SECRET_KEY: ${{ secrets.BASE_KEY }}
SMTP_SERVER: ${{ secrets.SMTP_SERVER }}
SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
NEW_AES_KEY: ${{ secrets.NEW_AES_KEY }}
DISCORD_CLIENT_SECRET: ${{ secrets.DISCORD_CLIENT_SECRET }}
SECRET_KEY: ci-secret-key
API_KEY: ci-api-key
NEW_AES_KEY: 0123456789abcdef
DISCORD_CLIENT_SECRET: ci-discord-secret

- name: 🔃 Restart Server
- name: Restart server
run: |
mkdir tmp
touch tmp/restart.txt

- name: ☁ SFTP Deploy
- name: SFTP deploy
uses: easingthemes/ssh-deploy@v2
env:
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
Expand Down
48 changes: 36 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,47 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: 🔨 Set up Python 3.12
uses: actions/setup-python@v2
- uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
python-version: "3.12"
cache: pip

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Check for missing migrations
run: python manage.py makemigrations --check --dry-run
env:
SECRET_KEY: ci-secret-key
API_KEY: ci-api-key
NEW_AES_KEY: 0123456789abcdef
DISCORD_CLIENT_SECRET: ci-discord-secret

- name: Apply migrations on a fresh database
run: python manage.py migrate --noinput
env:
SECRET_KEY: ci-secret-key
API_KEY: ci-api-key
NEW_AES_KEY: 0123456789abcdef
DISCORD_CLIENT_SECRET: ci-discord-secret

- name: Run Django checks
run: python manage.py check
env:
SECRET_KEY: ci-secret-key
API_KEY: ci-api-key
NEW_AES_KEY: 0123456789abcdef
DISCORD_CLIENT_SECRET: ci-discord-secret

- name: ▶ Run Tests
run: |
pytest
- name: Run tests
run: pytest
env:
SECRET_KEY: ${{ secrets.BASE_KEY }}
SMTP_SERVER: ${{ secrets.SMTP_SERVER }}
SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
NEW_AES_KEY: ${{ secrets.NEW_AES_KEY }}
DISCORD_CLIENT_SECRET: ${{ secrets.DISCORD_CLIENT_SECRET }}
SECRET_KEY: ci-secret-key
API_KEY: ci-api-key
NEW_AES_KEY: 0123456789abcdef
DISCORD_CLIENT_SECRET: ci-discord-secret
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ dmypy.json

# Database
*.sqlite3
migrations/

.vscode/
.DS_Store
Expand Down
16 changes: 16 additions & 0 deletions SRCweb/log_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Keep Polar's short-lived portal credential out of application access logs."""
import logging
import re


class RedactCustomerSessionToken(logging.Filter):
def filter(self, record):
message = record.getMessage()
redacted = re.sub(
r'(customer_session_token=)[^&\s\"\x27]+',
r'\1[REDACTED]', message, flags=re.IGNORECASE,
)
if redacted != message:
record.msg = redacted
record.args = ()
return True
62 changes: 54 additions & 8 deletions SRCweb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"""

from dotenv import load_dotenv
from django.core.exceptions import ImproperlyConfigured
from pathlib import Path
import os
from urllib.parse import urlencode

load_dotenv()

Expand All @@ -28,14 +30,40 @@
NEW_AES_KEY = os.getenv("NEW_AES_KEY") or "NEW_AES_KEY"

# Discord Client ID (client safe)
DISCORD_CLIENT_ID = "825618483957071873"
DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID") or "825618483957071873"

# SECURITY WARNING: keep the Discord Client Secret used in production secret!
DISCORD_CLIENT_SECRET = os.getenv(
"DISCORD_CLIENT_SECRET") or "DISCORD_CLIENT_SECRET"


def required_non_placeholder_env(name, *, development_default=None):
value = os.getenv(name) or development_default
if os.getenv("PYTHON_ENV") == "development":
return value
if not value or value in {name, "replace-me", "changeme", "CHANGE_ME"}:
raise ImproperlyConfigured(f"{name} must be configured in non-development environments.")
return value


# SECURITY WARNING: keep the API Key used in production secret!
API_KEY = os.getenv("API_KEY") or "API_KEY"
API_KEY = required_non_placeholder_env("API_KEY", development_default="API_KEY")

# Polar subscriptions
POLAR_SERVER = os.getenv("POLAR_SERVER") or "production"
POLAR_API_BASE_URL = os.getenv("POLAR_API_BASE_URL") or ""
POLAR_ACCESS_TOKEN = os.getenv("POLAR_ACCESS_TOKEN") or ""
POLAR_WEBHOOK_SECRET = os.getenv("POLAR_WEBHOOK_SECRET") or ""
POLAR_CHECKOUT_SUCCESS_URL = os.getenv("POLAR_CHECKOUT_SUCCESS_URL") or ""
POLAR_CUSTOMER_PORTAL_URL = os.getenv("POLAR_CUSTOMER_PORTAL_URL") or ""
POLAR_CASUAL_SERVER_METER_ID = os.getenv("POLAR_CASUAL_SERVER_METER_ID") or ""
POLAR_CASUAL_SERVER_EVENT_NAME = os.getenv("POLAR_CASUAL_SERVER_EVENT_NAME") or "casual_server_credits"
POLAR_REQUEST_TIMEOUT_SECONDS = float(os.getenv("POLAR_REQUEST_TIMEOUT_SECONDS") or 10)

# xRC server orchestrator
ORCHESTRATOR_API_BASE_URL = os.getenv("ORCHESTRATOR_API_BASE_URL") or ""
ORCHESTRATOR_API_TOKEN = os.getenv("ORCHESTRATOR_API_TOKEN") or ""
ORCHESTRATOR_REQUEST_TIMEOUT_SECONDS = float(os.getenv("ORCHESTRATOR_REQUEST_TIMEOUT_SECONDS") or 10)

# Sends an email to admins when debug = false and a 500 server error occurs
ADMINS = [('Webmaster', 'webmaster@secondrobotics.org')]
Expand Down Expand Up @@ -73,7 +101,8 @@
# 'teamleague',
# 'ladder',
'discordoauth2',
'ranked'
'ranked',
'subscriptions',
]

REST_FRAMEWORK = {
Expand Down Expand Up @@ -142,19 +171,21 @@
'console': {
'class': 'logging.StreamHandler',
'formatter': 'verbose',
'filters': ['redact_customer_session_token'],
},
'file': {
'class': 'logging.handlers.RotatingFileHandler',
'filename': BASE_DIR / 'django.log',
'maxBytes': 1024 * 1024 * 5, # 5 MB
'backupCount': 5,
'formatter': 'verbose',
'filters': ['redact_customer_session_token'],
},
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True,
'filters': ['require_debug_false'],
'filters': ['require_debug_false', 'redact_customer_session_token'],
}
},
'loggers': {
Expand All @@ -180,6 +211,9 @@
},
},
'filters': {
'redact_customer_session_token': {
'()': 'SRCweb.log_filters.RedactCustomerSessionToken',
},
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse',
},
Expand Down Expand Up @@ -243,19 +277,31 @@
STATICFILES_DIRS = [BASE_DIR / "static"]
DISCORD_REDIRECT_URI = "http://localhost:8000/oauth2/login/redirect"
DISCORD_API_REDIRECT_URI = "http://localhost:8000/oauth2/loginapi/redirect"
DISCORD_AUTH_URL = "https://discord.com/api/oauth2/authorize?client_id=825618483957071873&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Foauth2%2Flogin%2Fredirect&response_type=code&scope=identify%20email"
DISCORD_AUTH_API_URL = "https://discord.com/api/oauth2/authorize?client_id=825618483957071873&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Foauth2%2Floginapi%2Fredirect&response_type=code&scope=identify%20email"
else: # production
DEBUG = False
ALLOWED_HOSTS = ["secondrobotics.org",
"www.secondrobotics.org", "mail.secondrobotics.org"]
DISCORD_REDIRECT_URI = "https://secondrobotics.org/oauth2/login/redirect"
DISCORD_API_REDIRECT_URI = "https://secondrobotics.org/oauth2/loginapi/redirect"
DISCORD_AUTH_URL = "https://discord.com/api/oauth2/authorize?client_id=825618483957071873&redirect_uri=https%3A%2F%2Fsecondrobotics.org%2Foauth2%2Flogin%2Fredirect&response_type=code&scope=identify%20email"
DISCORD_AUTH_API_URL = "https://discord.com/api/oauth2/authorize?client_id=825618483957071873&redirect_uri=https%3A%2F%2Fsecondrobotics.org%2Foauth2%2Floginapi%2Fredirect&response_type=code&scope=identify%20email"
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True

# A dedicated test application can share its ID with the test bot. Preserve
# production defaults while allowing isolated OAuth login and redirect URLs.
DISCORD_REDIRECT_URI = os.getenv("DISCORD_REDIRECT_URI") or DISCORD_REDIRECT_URI
DISCORD_API_REDIRECT_URI = os.getenv("DISCORD_API_REDIRECT_URI") or DISCORD_API_REDIRECT_URI


def discord_authorization_url(redirect_uri):
return "https://discord.com/api/oauth2/authorize?" + urlencode({
"client_id": DISCORD_CLIENT_ID, "redirect_uri": redirect_uri,
"response_type": "code", "scope": "identify email",
})


DISCORD_AUTH_URL = discord_authorization_url(DISCORD_REDIRECT_URI)
DISCORD_AUTH_API_URL = discord_authorization_url(DISCORD_API_REDIRECT_URI)

SESSION_COOKIE_AGE = 60 * 60 * 24 * 30 # 30 days
MAX_UPLOAD_SIZE = "5242880"

Expand Down
2 changes: 2 additions & 0 deletions SRCweb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
path('oauth2/', include('discordoauth2.urls')),
path('ranked/', include('ranked.urls')),
path('api/ranked/', include('ranked.api.urls', namespace="api-ranked")),
path('subscriptions/', include('subscriptions.urls')),
path('api/subscriptions/', include('subscriptions.api.urls', namespace="api-subscriptions")),
]

if settings.DEBUG:
Expand Down
Loading
Loading