#105 · Limit comparisons per kind of account; let the env file set storage quotas
- timeline-app
- pull request
Closes #86, closes #87. ## #86: comparison limits per kind of account Comparisons were capped at eight timelines for everyone. Three env settings (each 2 to 8) now cap them per kind of account: | Setting | Default | |---|---| | `COMPARE_TIMELINES_GUEST` | **4** (was 8) | | `COMPARE_TIMELINES_USER` | 8 | | `COMPARE_TIMELINES_ADMIN` | 8 | Eight stays the hard ceiling, because live updates, layouts and saved views assume it. - `/api/session` reports the visitor's `compareLimit`. - These follow the limit: - the editor's comparison dialog (selection and messages); - `#compare/…` links; - the dashboard's selection tray and checkboxes on `/` and on profiles; - the `/compare` page. Where the guest limit is lower, guests are told that signing in allows more. - **Server enforcement:** a saved comparison holds at most as many sources as its **owner** may compare. A comparison saved within its owner's limit stays viewable by anyone allowed to see it. - An invalid setting stops startup with a message. ## #87: storage limits from the env file - **When `DEFAULT_USER_STORAGE_BYTES` is set:** it is the default quota from **every start**. `/admin` shows it as set by the env file and refuses to change it (409). - **When it is unset or empty:** it behaves as before. The default starts at 100 MiB and is managed in `/admin`. - **Units:** quotas take sizes with units, both in the env file and in `/admin`'s default and per-user fields: `500MiB`, `2GB`, `1.5GiB`, or a byte count. Decimal units are powers of 1000 and binary ones powers of 1024; the limit is 10 TB. - An invalid value stops startup with a message. - **Upgrades:** `compose.yml`, `.env.example` and the Debian env file used to set `DEFAULT_USER_STORAGE_BYTES=104857600`. They now leave it **unset**, so existing installations keep managing the default in `/admin`. An operator who wants the env file to decide sets it there. ## Tests - `test/limits.test.mjs` covers the limit defaults and validation, per-account limits, size parsing, and env-managed defaults. - `test/limits-postgres.mjs`, a new CI step, checks: - a saved comparison is refused past its owner's limit; - administrators get their own limit; - the session reports the guest limit. - `test/administration-postgres.mjs` now checks that an env default applies on every start. - Locally: - `npm test` (236 tests) passes; - the administration, HTTP, Next.js and comparison-live Postgres tests pass; - the Chromium suite passes. Docs: `docs/administration.md` (quotas) and `docs/comparison.md` (limits).