# Design This file fixes the parts that are easy to get wrong. Choose the language and framework that fit the person's project; nothing here depends on them. ## Data model Use the database in the `database` input. | Table | Columns | | --- | --- | | `staff` | `user_id` (primary key), `role`, `added_by`, `added_at` | | `staff_records` | `id`, `staff_id`, `kind`, `account_id`, `detail` (JSON), `reason`, `ip`, `at` | | `impersonations` | `id`, `staff_id`, `account_id`, `token_hash` (unique), `reason`, `started_at`, `expires_at`, `ended_at` (only if `impersonation` is on) | `users` gains `suspended_at`. `kind` is one of `action`, `reveal`, `impersonation_started` and `impersonation_ended`. ## The guard One function in front of every `/admin` route, in this order: 1. No session, or the session is one as a customer: 404. 2. The user is not in `staff`: 404. 3. The session is older than 12 hours: send to sign-in, then back. 4. The route names a role the staff member lacks: 403. Answer 404 with the same page the app gives for any unknown address. ## A session as a customer - It is a session of its own kind, with its own cookie name and a random token stored as a hash. It does not reuse or copy the customer's session. - The app's guard, when it finds this cookie, loads the customer as the current user and also sets "acting staff member" on the request. - Routes are marked sensitive in one list. The app's guard answers 403 for them whenever "acting staff member" is set. - The cookie lasts as long as the `impersonation_minutes` input says, and the server checks `expires_at` on every request as well. - Stopping sets `ended_at`, clears the cookie and returns staff to the customer's page in the console. ## Masking | Value | Shown as | | --- | --- | | `sam@example.com` | `s•••@example.com` | | `a@example.com` | `•@example.com` | | A phone number | Its last 2 digits, the rest as `•` | | A name | As it is | The whole value is sent to the browser only in answer to "Show", never hidden in the page. ## Suspension Check `suspended_at` where sessions are loaded, so a suspension takes effect on the next request without having to find and end each session. ## Configuration | Secret | Purpose | | --- | --- | | `DATABASE_URL` | Connection string for the chosen database. | ## Named here - `support` may suspend, end sessions and resend a confirmation. Lifting a suspension, revealing a hidden value and changing staff are for `admin`. ## What this spec leaves to you Where this spec names something, use that name, so that two builds of it agree. Where it does not, the choice is yours. List what you chose in the README.