From 31182fd0dcd25f7f677028e16a0afcb24e39f069 Mon Sep 17 00:00:00 2001 From: Alexander Saavedra Date: Tue, 1 Dec 2026 13:52:36 +0100 Subject: [PATCH] fix(page): the first-run assistant stays closed in the coach view, and a refused save says read-only chore(release): 1.12.2 --- CHANGELOG.md | 6 +++ README.es.md | 4 +- README.md | 4 +- docker/docker-compose.yml | 8 ++-- docker/example.env | 2 +- docs/profile.md | 4 ++ package-lock.json | 4 +- package.json | 2 +- services/loop-ingest/package-lock.json | 4 +- services/loop-ingest/package.json | 2 +- web/src/client/onboarding.test.mjs | 52 ++++++++++++++++++++++++-- web/src/client/onboarding.ts | 12 +++++- web/src/i18n/onboarding-templates.mjs | 2 + 13 files changed, 86 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39418ca3..e7d674fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ Dated history of structural work on this repo: the append-only narrative of what operating facts live in `CLAUDE.md` and the docs ([`docs/README.md`](docs/README.md)). +## [1.12.2] - 2026-12-01 + +- **Coach view:** the first-run assistant no longer opens over the page of a person you are viewing (it is theirs to + fill in, and the view is read-only). If a save is refused because you are viewing somebody, the page now says so + instead of "server error". + ## [1.12.1] - 2026-12-01 - **Profile:** the "Share with my coach" switch now sits on the line of its label; on a phone it was drawn above it. diff --git a/README.es.md b/README.es.md index bdc8e283..cc79dd31 100644 --- a/README.es.md +++ b/README.es.md @@ -128,8 +128,8 @@ página) y la imagen `loop-web` (sirve la página). ```sh mkdir loop && cd loop - curl -fsSLO https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.1/docker/docker-compose.yml - curl -fsSL -o .env https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.1/docker/example.env + curl -fsSLO https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.2/docker/docker-compose.yml + curl -fsSL -o .env https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.2/docker/example.env mkdir -p files/import files/manuals files/documents ``` diff --git a/README.md b/README.md index c4a7b8c8..10f206bd 100644 --- a/README.md +++ b/README.md @@ -125,8 +125,8 @@ and the endpoint the iOS Shortcut sends your Apple Health data to. Three contain ```sh mkdir loop && cd loop - curl -fsSLO https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.1/docker/docker-compose.yml - curl -fsSL -o .env https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.1/docker/example.env + curl -fsSLO https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.2/docker/docker-compose.yml + curl -fsSL -o .env https://raw.githubusercontent.com/mralexsaavedra/loop/v1.12.2/docker/example.env mkdir -p files/import files/manuals files/documents ``` diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 7950425d..f1240db1 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -50,12 +50,12 @@ services: loop-server: # the published image (Docker Hub); `docker compose up -d --build` builds it from a clone instead - image: mralexandersaavedra/loop-server:${HC_VERSION:-1.12.1} + image: mralexandersaavedra/loop-server:${HC_VERSION:-1.12.2} build: context: .. dockerfile: docker/loop-server.Dockerfile args: - VERSION: ${HC_VERSION:-1.12.1} + VERSION: ${HC_VERSION:-1.12.2} container_name: loop-server${HC_INSTANCE:+-${HC_INSTANCE}} restart: unless-stopped # SIGTERM lets in-flight requests finish for up to 10 s and stops a running build; docker waits this long @@ -132,12 +132,12 @@ services: loop-web: # the published image (Docker Hub); `docker compose up -d --build` builds it from a clone instead. The nginx # template and hosts.sh are baked in from services/loop-web (docker/loop-web.Dockerfile), never bind-mounted. - image: mralexandersaavedra/loop-web:${HC_VERSION:-1.12.1} + image: mralexandersaavedra/loop-web:${HC_VERSION:-1.12.2} build: context: .. dockerfile: docker/loop-web.Dockerfile args: - VERSION: ${HC_VERSION:-1.12.1} + VERSION: ${HC_VERSION:-1.12.2} container_name: loop-web${HC_INSTANCE:+-${HC_INSTANCE}} restart: unless-stopped # The same hardening as services/loop-web/docker-compose.yml: a read-only root filesystem; tmpfs for what the diff --git a/docker/example.env b/docker/example.env index c0e01669..504b9676 100644 --- a/docker/example.env +++ b/docker/example.env @@ -2,7 +2,7 @@ # and is never committed (docker/.gitignore). # The image tag: mralexandersaavedra/loop-server: and mralexandersaavedra/loop-web: -HC_VERSION=1.12.1 +HC_VERSION=1.12.2 # Empty for the first install; a short name (e.g. second) for another install on the same host HC_INSTANCE= diff --git a/docs/profile.md b/docs/profile.md index b69ea9fc..10e87951 100644 --- a/docs/profile.md +++ b/docs/profile.md @@ -484,5 +484,9 @@ The document may carry `sports` — `[{sport, minutes, perWeek}]`, one entry per - It opens on its own once, when the server has neither an onboarding document nor a goal and the page was not opened on a sheet deep link. - "Later" is remembered in `localStorage` (`hc.onboarding.later`, a convenience only). +- In the admin's coach view (the tab shows another person's page, `sessionStorage` `hc.viewing`) the assistant never + opens by itself and asks the server nothing: the page is read-only and the profile is that person's to fill in. Opened + by hand there, **Save** answers "Read-only: you are viewing another person's page. Nothing was saved." without a + request; a save the server refuses with `403 read_only` gets the same line, never "server error". - The profile sheet opens it from the **Edit** chip at the end of its header row (name, age, place) on the LAN page. diff --git a/package-lock.json b/package-lock.json index 656a1154..dc15a503 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "loop", - "version": "1.12.1", + "version": "1.12.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "loop", - "version": "1.12.1", + "version": "1.12.2", "license": "MIT", "dependencies": { "astro": "7.3.8", diff --git a/package.json b/package.json index 9c29d1f7..39333a34 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loop", - "version": "1.12.1", + "version": "1.12.2", "private": true, "description": "Tooling for the plan single source of truth (data/nutrition + data/training) and its Astro build (web/).", "license": "MIT", diff --git a/services/loop-ingest/package-lock.json b/services/loop-ingest/package-lock.json index 5a20b5da..4ca3e8c7 100644 --- a/services/loop-ingest/package-lock.json +++ b/services/loop-ingest/package-lock.json @@ -1,12 +1,12 @@ { "name": "loop-ingest", - "version": "1.12.1", + "version": "1.12.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "loop-ingest", - "version": "1.12.1", + "version": "1.12.2", "license": "MIT", "dependencies": { "pg": "^8.13.1" diff --git a/services/loop-ingest/package.json b/services/loop-ingest/package.json index e66f4939..b4e0fb79 100644 --- a/services/loop-ingest/package.json +++ b/services/loop-ingest/package.json @@ -1,6 +1,6 @@ { "name": "loop-ingest", - "version": "1.12.1", + "version": "1.12.2", "private": true, "license": "MIT", "type": "module", diff --git a/web/src/client/onboarding.test.mjs b/web/src/client/onboarding.test.mjs index 92a51b86..b7400b48 100644 --- a/web/src/client/onboarding.test.mjs +++ b/web/src/client/onboarding.test.mjs @@ -15,9 +15,10 @@ const source = clientScriptSource('onboarding.ts'); /** @typedef {import('node:vm').Context} VmGlobals the script's globals (a vm context: untyped by nature) */ /** * @param {{locale?: string, profile?: unknown, settings?: {goal: string | null}, protocol?: string, later?: boolean, putFails?: boolean, - * hash?: string, statusNode?: {textContent: string} | null}} [opts] + * hash?: string, statusNode?: {textContent: string} | null, viewing?: string, putError?: {status: number, code?: string} | null}} [opts] + * `viewing`: the tab shows that person's page (the coach view); `putError`: what the save is rejected with */ -function setup({ locale = 'en', profile = null, settings = { goal: null }, protocol = 'http:', later = false, putFails = false, hash = '', statusNode = null } = {}) { +function setup({ locale = 'en', profile = null, settings = { goal: null }, protocol = 'http:', later = false, putFails = false, hash = '', statusNode = null, viewing = '', putError = null } = {}) { /** @type {Record void)[]>} */ const listeners = {}; /** @type {[string, string, any][]} the API calls; [2] = the JSON round-trip of the body the script sent */ @@ -35,7 +36,7 @@ function setup({ locale = 'en', profile = null, settings = { goal: null }, proto calls.push([method, p, body && JSON.parse(JSON.stringify(body))]); if (method === 'GET' && p === '/profile') return Promise.resolve({ profile }); if (method === 'GET' && p === '/settings') return Promise.resolve({ settings }); - if (method === 'PUT' && p === '/profile') return putFails ? Promise.reject({ status: 0 }) : Promise.resolve({ profile: body }); + if (method === 'PUT' && p === '/profile') return putError ? Promise.reject(putError) : putFails ? Promise.reject({ status: 0 }) : Promise.resolve({ profile: body }); return Promise.reject({ status: 404 }); }; /** @type {VmGlobals} */ @@ -61,6 +62,8 @@ function setup({ locale = 'en', profile = null, settings = { goal: null }, proto }, location: { protocol, origin: 'http://192.168.1.50:8091', hash }, localStorage: { getItem: (/** @type {string} */ k) => (k in store ? store[k] : null), setItem: (/** @type {string} */ k, /** @type {unknown} */ v) => { store[k] = String(v); }, removeItem: (/** @type {string} */ k) => { delete store[k]; } }, + // whose page the tab shows (client/signin.ts): the viewed person's name in the admin's coach view, else nothing + sessionStorage: { getItem: (/** @type {string} */ k) => (k === 'hc.viewing' && viewing ? viewing : null) }, PROFILE: { weight: { kg: 60, date: '2026-10-13' } }, I18N_ONB: locale === 'es' ? esO : enO, LOCALE: locale, @@ -527,3 +530,46 @@ test('each adjust cell names its day type (sr-only), so "kcal" is never ambiguou es.act('next'); es.act('next'); es.act('adjust'); assert.match(es.html(), new RegExp(`${esO.summary.days.rest} `)); }); + +test('the coach view (the tab shows another person\'s page): the assistant never opens by itself and asks the server nothing', async () => { + const s = setup({ viewing: 'ana' }); + await flush(); await flush(); + assert.deepEqual(s.opened, [], 'not opened over a page that is read-only'); + assert.deepEqual(s.calls, [], 'no first-run lookup either'); + // the same person-less page on their OWN tab still gets it + const own = setup(); + await flush(); await flush(); + assert.deepEqual(own.opened.map((o) => o[0]), ['onboarding']); +}); + +test('the coach view: a save says "read-only" at once, sends nothing and keeps the sheet open (en / es)', async () => { + for (const [locale, text] of /** @type {[string, RegExp][]} */ ([['en', /Read-only: you are viewing another person's page\. Nothing was saved\.|Read-only: you are viewing another person's page\. Nothing was saved\./], ['es', /Solo lectura: estás viendo la página de otra persona\. No se ha guardado nada\./]])) { + const s = setup({ viewing: 'ana', locale }); + toSafety(s, [['team', '90', '2']]); + s.act('next'); s.act('next'); s.act('next'); s.act('next'); + s.act('save'); + await flush(); await flush(); + assert.match(s.html(), text, locale); + assert.deepEqual(s.calls.filter((c) => c[0] === 'PUT'), [], 'nothing was sent'); + assert.deepEqual(s.saved, []); + assert.equal(s.synced, 0); + } +}); + +test('a save the server refuses as read_only (the view began elsewhere) gets that reason, not "server error"', async () => { + const s = setup({ putError: { status: 403, code: 'read_only' } }); + toSafety(s, [['team', '90', '2']]); + s.act('next'); s.act('next'); s.act('next'); s.act('next'); + s.act('save'); + await flush(); await flush(); + assert.match(s.html(), /Read-only: you are viewing another person/); + assert.doesNotMatch(s.html(), /server error/); + assert.deepEqual(s.saved, []); + // any other refusal keeps the generic reason + const other = setup({ putError: { status: 500, code: 'internal' } }); + toSafety(other, [['team', '90', '2']]); + other.act('next'); other.act('next'); other.act('next'); other.act('next'); + other.act('save'); + await flush(); await flush(); + assert.match(other.html(), /Could not save \(server error\)/); +}); diff --git a/web/src/client/onboarding.ts b/web/src/client/onboarding.ts index 6410e3f1..8304ce33 100644 --- a/web/src/client/onboarding.ts +++ b/web/src/client/onboarding.ts @@ -395,6 +395,7 @@ type OnbDoc = { function save() { var call = api(); if (!call) return; + if (viewing()) { setStatus(T.errors.readOnly); return; } setStatus(T.saving); var st = window.HCSettings; call('PUT', '/profile', doc()).then(function () { @@ -408,7 +409,9 @@ type OnbDoc = { close(); var b = document.getElementById ? document.getElementById('sync-btn') : null; if (b && !b.hidden && typeof b.click === 'function') b.click(); - }).catch(function (err: { status?: number } | null | undefined) { + }).catch(function (err: { status?: number; code?: string } | null | undefined) { + // the server refuses every write of a session that is viewing somebody (403 read_only): not a server error + if (err && err.code === 'read_only') { setStatus(T.errors.readOnly); return; } setStatus(format(T.errors.save, { reason: err && err.status === 0 ? T.reasons.offline : T.reasons.generic })); }); } @@ -477,13 +480,18 @@ type OnbDoc = { HC.registerView('onboarding', { title: function () { return T.title; }, render: render }); + // While this tab shows ANOTHER person's page (the admin's coach view, read-only; client/signin.ts keeps sessionStorage + // `hc.viewing`) the assistant is nobody's to fill in: it never opens by itself, and a save says so without asking the server. + function viewing() { + try { return typeof sessionStorage !== 'undefined' && !!sessionStorage.getItem('hc.viewing'); } catch (e) { return false; } + } // first run (LAN only): neither an onboarding document nor a goal on the server, and not postponed here function laterSet() { try { return localStorage.getItem(LATER_KEY) === '1'; } catch (e) { return false; } } function firstRun() { var call = api(); - if (!call || laterSet()) return; + if (!call || laterSet() || viewing()) return; Promise.all([call('GET', '/profile'), call('GET', '/settings')]).then(function (r) { var prof = r[0] && r[0].profile, set = r[1] && r[1].settings; if (prof || (set && set.goal)) return; diff --git a/web/src/i18n/onboarding-templates.mjs b/web/src/i18n/onboarding-templates.mjs index 8aaa7f56..bac73d42 100644 --- a/web/src/i18n/onboarding-templates.mjs +++ b/web/src/i18n/onboarding-templates.mjs @@ -103,6 +103,7 @@ export const en = { proteinMax: 'Protein above 2.4 g per kg.', fatMin: 'Fat below 0.5 g per kg.', save: 'Could not save ({reason}). Try again.', + readOnly: 'Read-only: you are viewing another person\'s page. Nothing was saved.', }, warnings: { proteinRange: 'Protein outside the usual 1.6-2.2 g per kg.', @@ -222,6 +223,7 @@ export const es = { proteinMax: 'Proteína por encima de 2,4 g por kg.', fatMin: 'Grasa por debajo de 0,5 g por kg.', save: 'No se pudo guardar ({reason}). Inténtalo de nuevo.', + readOnly: 'Solo lectura: estás viendo la página de otra persona. No se ha guardado nada.', }, warnings: { proteinRange: 'Proteína fuera del rango habitual de 1,6-2,2 g por kg.',