RosterChief charging the clubs, which is a different domain from `shop` (a club charging its members). Nothing here is club-scoped: these rows reference a Club, they are not owned by one, and no club user ever sees them. - Tier + TierPrice. Prices are dated, not keyed by year: a rate change is one row with a future active_from, and price_on(day) answers "what was in force then". A tier with no price yet returns None, which callers must treat as "cannot bill" -- never as free. - Due: one rolling-year period per club, with a 45-day grace tail. The tier and the amount are SNAPSHOTS taken when the period opens. Raise the price and last year's period must still say what was actually charged; reading it back through the tier would silently rewrite financial history. - DuePayment: partial payments accumulate. amount_paid is re-summed from the payments on every change, never incremented -- an increment drifts the moment a payment is deleted, and the drift still looks like money. - Invoice: PDF via WeasyPrint, rendered on demand from the frozen snapshot. Only the number is stored, in one platform-wide series (unlike the shop's per-club order numbers), and re-issuing returns the existing one rather than burning a number -- a gap in an invoice series is a question you don't want to answer. WeasyPrint is imported lazily: it binds to native pango/cairo, and the app, the tests and every other page must still run on a machine without them. - archive_overdue_clubs reports by default and archives only with --commit. That asymmetry is deliberate: this switches off paying customers, so a bad clock or a cron misconfiguration should cost an email, not a morning of angry clubs. A club with auto_archive off is spared entirely. Renewal continues from the last period end, not from the payment date: a club that pays two months late has still used those two months. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
227 lines
7.6 KiB
Python
227 lines
7.6 KiB
Python
"""
|
|
Django settings for rosterchief project.
|
|
|
|
Generated by 'django-admin startproject' using Django 6.0.6.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/6.0/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/6.0/ref/settings/
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
from decouple import Csv, config
|
|
from dj_database_url import parse as db_url
|
|
|
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = config("DJANGO_SECRET_KEY")
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = config("DJANGO_DEBUG", default=False, cast=bool)
|
|
|
|
ALLOWED_HOSTS = config("DJANGO_ALLOWED_HOSTS", cast=Csv(), default="")
|
|
INTERNAL_IPS = config("DJANGO_INTERNAL_IPS", cast=Csv(), default="127.0.0.1")
|
|
|
|
CSRF_TRUSTED_ORIGINS = config("DJANGO_CSRF_TRUSTED_ORIGINS", cast=Csv(), default="")
|
|
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
"django.contrib.admin",
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
# Required by allauth's security-key list template ({% load humanize %}); without it
|
|
# that page raises TemplateSyntaxError.
|
|
"django.contrib.humanize",
|
|
"phonenumber_field",
|
|
"lucide",
|
|
# Auth: allauth deliberately WITHOUT django.contrib.sites — it is optional in
|
|
# allauth 65+, and ARCHITECTURE.md §2.4 rejects the Sites framework (Club is
|
|
# the tenant root, not Site).
|
|
"allauth",
|
|
"allauth.account",
|
|
"allauth.mfa",
|
|
"club.apps.ClubConfig",
|
|
"authentication.apps.AuthenticationConfig",
|
|
"members.apps.MembersConfig",
|
|
"teams.apps.TeamsConfig",
|
|
"events.apps.EventsConfig",
|
|
"formbuilder.apps.FormbuilderConfig",
|
|
"shop.apps.ShopConfig",
|
|
# Platform billing: RosterChief charging the clubs. Not tenant data — see billing/models.py.
|
|
"billing.apps.BillingConfig",
|
|
"waffle",
|
|
"features.apps.FeaturesConfig",
|
|
"controlpanel.apps.ControlpanelConfig",
|
|
]
|
|
|
|
# Feature flags (django-waffle). The Flag model is swappable, like AUTH_USER_MODEL:
|
|
# ours adds a `clubs` M2M so a feature can be turned on per tenant. Because the
|
|
# tenant middleware sets request.club, `flag_is_active(request, "x")` just works.
|
|
WAFFLE_FLAG_MODEL = "features.Flag"
|
|
|
|
MIDDLEWARE = [
|
|
"django.middleware.security.SecurityMiddleware",
|
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
|
"django.middleware.common.CommonMiddleware",
|
|
"django.middleware.csrf.CsrfViewMiddleware",
|
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
|
"allauth.account.middleware.AccountMiddleware",
|
|
"authentication.middleware.RequireMFAMiddleware",
|
|
"club.tenancy.ClubTenantMiddleware",
|
|
"django.contrib.messages.middleware.MessageMiddleware",
|
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
|
]
|
|
|
|
# Reload the browser when templates, static files or Python change. Dev only: it
|
|
# injects a script tag into every HTML response and serves an open event stream,
|
|
# neither of which belongs in production.
|
|
if DEBUG:
|
|
INSTALLED_APPS += ["django_browser_reload"]
|
|
MIDDLEWARE += ["django_browser_reload.middleware.BrowserReloadMiddleware"]
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
|
"django.contrib.auth.backends.ModelBackend",
|
|
"allauth.account.auth_backends.AuthenticationBackend",
|
|
]
|
|
|
|
# Multi-tenancy: base domain whose subdomains resolve to a club, e.g.
|
|
# "ajax-united.rosterchief.app" -> the club with slug "ajax-united". Leave
|
|
# unset to fall back to generic "slug.example.com" (3+ label) resolution.
|
|
ROSTERCHIEF_BASE_DOMAIN = config("ROSTERCHIEF_BASE_DOMAIN", default="")
|
|
|
|
ROOT_URLCONF = "rosterchief.urls"
|
|
|
|
AUTH_USER_MODEL = "authentication.User"
|
|
|
|
|
|
# Authentication (django-allauth)
|
|
|
|
LOGIN_URL = "account_login"
|
|
LOGIN_REDIRECT_URL = "/"
|
|
|
|
# The User model logs in by email and has no username field.
|
|
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
|
|
ACCOUNT_LOGIN_METHODS = {"email"}
|
|
ACCOUNT_SIGNUP_FIELDS = ["email*", "password1*", "password2*"]
|
|
ACCOUNT_EMAIL_VERIFICATION = "none"
|
|
|
|
|
|
# Two-factor authentication (allauth.mfa)
|
|
|
|
MFA_SUPPORTED_TYPES = ["totp", "webauthn", "recovery_codes"]
|
|
|
|
# Passkeys are a first factor: sign in with Touch ID / a security key alone.
|
|
MFA_PASSKEY_LOGIN_ENABLED = True
|
|
MFA_PASSKEY_SIGNUP_ENABLED = False
|
|
|
|
# WebAuthn needs a secure context. Browsers treat *.localhost as secure, but the
|
|
# dev server is plain HTTP, so allow the insecure origin while DEBUG.
|
|
MFA_WEBAUTHN_ALLOW_INSECURE_ORIGIN = DEBUG
|
|
|
|
# A passkey is bound to a Relying Party ID (a domain). Our adapter pins it to
|
|
# ROSTERCHIEF_BASE_DOMAIN so that ONE passkey works across every club subdomain
|
|
# — allauth's default (the request host) would bind it to a single club.
|
|
MFA_ADAPTER = "authentication.adapters.RosterChiefMFAAdapter"
|
|
MFA_WEBAUTHN_RP_NAME = config("ROSTERCHIEF_RP_NAME", default="RosterChief")
|
|
|
|
# Where RequireMFAMiddleware sends privileged users who haven't enrolled yet.
|
|
MFA_ENROLMENT_URL_NAME = "mfa_index"
|
|
|
|
|
|
# Sessions are shared across club subdomains: log in once and you're authenticated
|
|
# on every club (matching the one-passkey-everywhere model). Tenancy still scopes
|
|
# what you can *see* — that is the access service's job, not the cookie's.
|
|
# Browsers reject a Domain attribute on localhost, so it stays host-only in dev.
|
|
SHARED_COOKIE_DOMAIN = f".{ROSTERCHIEF_BASE_DOMAIN}" if ROSTERCHIEF_BASE_DOMAIN and ROSTERCHIEF_BASE_DOMAIN != "localhost" else None
|
|
|
|
SESSION_COOKIE_DOMAIN = config("DJANGO_SESSION_COOKIE_DOMAIN", default=SHARED_COOKIE_DOMAIN)
|
|
CSRF_COOKIE_DOMAIN = config("DJANGO_CSRF_COOKIE_DOMAIN", default=SHARED_COOKIE_DOMAIN)
|
|
|
|
TEMPLATES = [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
"DIRS": [BASE_DIR / "templates"],
|
|
"APP_DIRS": True,
|
|
"OPTIONS": {
|
|
"context_processors": [
|
|
"django.template.context_processors.request",
|
|
"django.contrib.auth.context_processors.auth",
|
|
"django.contrib.messages.context_processors.messages",
|
|
"club.context_processors.branding",
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = "rosterchief.wsgi.application"
|
|
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
|
|
|
|
DATABASES = {
|
|
"default": config("DJANGO_DATABASE_URL", default="sqlite:///db.sqlite3", cast=db_url),
|
|
}
|
|
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators
|
|
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
{
|
|
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
|
},
|
|
{
|
|
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
|
},
|
|
{
|
|
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
|
},
|
|
{
|
|
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
|
},
|
|
]
|
|
|
|
|
|
# Internationalization
|
|
# https://docs.djangoproject.com/en/6.0/topics/i18n/
|
|
|
|
LANGUAGE_CODE = "en-us"
|
|
|
|
TIME_ZONE = config("DJANGO_TIME_ZONE", default="Europe/Brussels", cast=str)
|
|
|
|
USE_I18N = True
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/6.0/howto/static-files/
|
|
|
|
STATIC_URL = "static/"
|
|
STATIC_ROOT = BASE_DIR / "staticfiles"
|
|
STATICFILES_DIRS = [BASE_DIR / "static"]
|
|
|
|
MEDIA_URL = "media/"
|
|
MEDIA_ROOT = BASE_DIR / "media"
|
|
|
|
|
|
# Phone numbers (django-phonenumber-field)
|
|
|
|
PHONENUMBER_DEFAULT_REGION = "BE"
|
|
PHONENUMBER_DB_FORMAT = "E164"
|