# Admin console ## What this builds The pages a company's own staff use to help its customers: find an account, see what is in it, fix what can be fixed, and look at the app as the customer does. The console is kept apart from the app, shows no more than the job needs, and records everything staff do in it. Read `spekkr.inputs.json` first. `impersonation` decides whether R6 exists, and a session as a customer lasts `impersonation_minutes` minutes. `require_reason` changes R5 and R6. This spec needs an app with a `users` table and sign-in. It does not build them. ## Out of scope - A general tool for editing any row of any table. - Charts and reports. - Help-desk tickets. ## Requirements Each requirement has an id. Tests name the id they cover. ### R1. Who is staff - Staff are listed in a table of their own, with a role: `support` or `admin`. - A person becomes staff by a command run on the server, or by an `admin` in the console. No public route and no field on a form can make someone staff. - An `admin` cannot remove their own role, and the last `admin` cannot be removed. Accept when: a request that sets a role field on the user's own profile changes nothing, and removing the last `admin` is refused. ### R2. Kept apart - Every console address starts with `/admin` and passes through one guard. - A person who is not staff gets 404 for every console address, the same answer as for an address that does not exist. - The console asks staff to sign in again if they last did so more than 12 hours ago. - A test lists every route under `/admin` and fails if one is not behind the guard. Accept when: a signed-in customer gets 404 for each console address, and the route test fails when a route is added outside the guard. ### R3. Find a customer - Staff search by email address, name or id. An exact email or id leads straight to the account. - Results show a name, a masked email address and when the account was made, 20 at a time. Accept when: a search by part of a name lists matching accounts with their email addresses masked. ### R4. A customer's page - The page is made of sections, each a function that takes the account and returns facts to show. The first sections: the account, its sessions, its workspaces if the app has them. - Personal details are masked: `s•••@example.com`. "Show" reveals one, and the reveal is recorded. - The page shows the last 20 things staff did to this account. Accept when: the page as first loaded holds no whole email address, and pressing "Show" leaves a record. ### R5. Actions - Actions are a list in code. Each has a name, the role it needs, whether it asks to be confirmed, and a function that does it. - The first actions: suspend an account, lift a suspension, end all of an account's sessions, and resend the confirmation email. - If `require_reason` is on, every action needs a reason of at least 10 characters before it runs. - A suspended account cannot sign in or use a session it has. Its sign-in page says the account is suspended and how to reach support. - `support` can do only the actions marked for it. `admin` can do all. Accept when: a `support` person gets 403 for an `admin` action, a suspended account's existing session is refused on its next request, and with `require_reason` on, an action without a reason does not run. ### R6. Sign in as a customer Only if `impersonation` is on. - Staff start a session as a customer from the customer's page. If `require_reason` is on, it needs a reason. - The session lasts `impersonation_minutes` minutes and then ends by itself. A banner on every page of the app says "You are signed in as NAME" and has a button to stop. - In such a session the routes marked sensitive answer 403: changing the email address or the password, deleting the account, anything that pays or changes how the customer pays, and creating API keys. - Staff cannot sign in as other staff. A session as a customer cannot open the console or start another such session. - The customer's own sessions are untouched, and nothing the customer sees says that staff looked. - Whatever is recorded during the session, by this spec or by the app, names the staff member as well as the customer. Accept when: a sensitive route answers 403 in such a session, the session stops working one second after its time, and staff trying to sign in as staff get 403. ### R7. Everything is recorded - Each action, each reveal and the start and end of each session as a customer is recorded: who, what, on which account, the reason, when, and from which IP address. - Records cannot be changed or deleted from the console. - An `admin` can read all records, with filters for staff member and account. Accept when: each of the four kinds of event leaves a record with every field, and no console route changes one. ### R8. Pages - Search, the customer's page, the staff list, the records. - Every page says in its header that it is the console, in a colour the app does not use, so staff never mistake one for the other. Accept when: each page works with a keyboard alone and at a 360 pixel wide screen. ## Definition of done - Every acceptance check above has an automated test, and all tests pass. - A README explains how to make the first `admin`, how to add a section and an action, how to mark a route sensitive, and how to run the tests.