Repository navigation
feat: admin panel and coach view - #319
Merged
Merged
Conversation
sql/026 adds app_user.is_admin (the install's first user after the migration) and share_with_coach (off for everyone). The session answers both on every request, GET /auth/session returns them, and the user script gets admin / share <username> on|off and shows both in list. The only admin is never turned off.
/admin/users (list, add, rename, delete) and machine tokens (issue, list, revoke), reached from the page through /api/admin/. Only a session whose user is an admin: never open mode, a machine token or a run credential. The rules shared with scripts/user.js (token label, token issue, the order of a delete) move to src/user-admin.js. The script's delete now refuses the only admin.
An admin issues a link for a user (POST /admin/users/<name>/password-link); whoever holds it sets that user's password once within 48 hours (POST /auth/password), which ends that user's sessions and deletes the link in one statement. Only the SHA-256 of a link is stored (sql/027), a user has one link at a time, and every bad link is the same 410.
GET /admin/users/<name>/providers, POST /admin/strava/authorize-url, PUT / DELETE /admin/users/<name>/strava and /garmin. The connection rules the user script had inline (what a pasted secret may be, the code exchange and the one-transaction store) move to src/user-admin.js, and Strava's authorization steps to src/strava-oauth.js; the script uses them. No route answers a stored secret, and Strava's own response text is never passed on.
An admin's session can view a user who shares (POST /auth/view, /auth/unview; sql/028 keeps it on the session). The person routes and GET /site then answer the viewed user's data, and every request that is not a GET or HEAD is 403 read_only: one check before every other route, with identify() as the backstop. The view counts only while the viewer is an admin and the viewed user shares, checked in the query that reads the session. A person switches their own consent with POST /auth/sharing.
… and the coach view The profile sheet gets a People sheet for an admin (add, rename, delete, password link, machine tokens, Strava and Garmin of any person) and a 'share with my coach' switch for everybody. The sign-in sheet shows a 'choose your password' form for a one-time link (#set-password=<token>). While a session views somebody a banner says whose page it is, with the way back; a refused write shows a read-only notice. The tab remembers whose page it shows, so the viewer's own stored goal stays apart and the page reloads once when the view changes elsewhere.
The coach banner's styles had been made to fit the CSS budget by merging unrelated existing rules, which changed the size of the gear kilometres and dropped the sign-in panel's min-height. The existing rules are back exactly as on main; only the banner block is new, and the inline CSS budget goes from 112_000 to 113_000 (owner-approved).
…sed while viewing Taking consent back, or removing the admin role, now clears the view from the sessions that had it in the same statement, so it no longer comes back by itself when consent or the role returns. While a session views somebody every /admin route answers 403 viewing, reads included.
Two cards like the profile's own sections. A person's panel opens right under their row as an inset card, and that row's button becomes its Close. The panel starts with the everyday actions; rename, machine tokens, Strava and Garmin and delete wait in closed folds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
An admin panel and a coach view for a multi-user install.
sql/026): one flag per user; the install's first user is the admin after the migration.user.js admin <username> on|off./admin/*, the People sheet in the profile): list, add, rename, delete, machine tokens, and the Strava / Garmin connection of any person. Only a signed-in admin's session reaches these routes.sql/027): the admin issues a link, the person chooses their own password with it (/#set-password=<token>). The admin never knows a password.sql/028): an admin can look, read-only, at the page of a person who turned on "share with my coach". Every request that is not aGETorHEADis refused while viewing, in one place before every other route. Consent taken back ends the view at the next request.How it was checked
e2e/lan/multi-user.spec.mjs, extended) could not run on the development machine: CI runs them here.Notes
user.js listprints two more columns (admin,shares).user.js share <username> on.docs/lan-services.md(Admin routes, Password links, Coach view),docs/profile.md,docs/plan-page.md.