Skip to content

feat: admin panel and coach view - #319

Merged
mralexsaavedra merged 14 commits into
mainfrom
feat/admin-coach
Dec 1, 2026
Merged

mralexsaavedra merged 14 commits into
mainfrom
feat/admin-coach

Conversation

@mralexsaavedra

Copy link
Copy Markdown
Owner

What

An admin panel and a coach view for a multi-user install.

  • Admin role (sql/026): one flag per user; the install's first user is the admin after the migration. user.js admin <username> on|off.
  • User management from the page (/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.
  • One-time password links (sql/027): the admin issues a link, the person chooses their own password with it (/#set-password=<token>). The admin never knows a password.
  • Coach view (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 a GET or HEAD is refused while viewing, in one place before every other route. Consent taken back ends the view at the next request.

How it was checked

  • Service suite with a real Postgres: 813 tests pass (last full run), plus the tests of the small follow-up.
  • Page suite: 3032 pass, 0 fail, 8 skipped. Lint and type checks clean.
  • The browser tests (e2e/lan/multi-user.spec.mjs, extended) could not run on the development machine: CI runs them here.

Notes

  • user.js list prints two more columns (admin, shares).
  • New users do not share by default. Sharing for existing users is turned on per user with user.js share <username> on.
  • Docs: docs/lan-services.md (Admin routes, Password links, Coach view), docs/profile.md, docs/plan-page.md.

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.
@mralexsaavedra
mralexsaavedra merged commit 07eaec2 into main Dec 1, 2026
5 checks passed
@mralexsaavedra
mralexsaavedra deleted the feat/admin-coach branch December 1, 2026 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant