Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Admin: a profile with a null or shapeless workout entry opens instead of blanking the whole app (QA C16)

Duarte Santos8094a5131b35
diff --git a/frontend/src/views/Admin.jsx b/frontend/src/views/Admin.jsx
index e52d1e946..8ca0409c8 100644
--- a/frontend/src/views/Admin.jsx
+++ b/frontend/src/views/Admin.jsx
@@ -36,6 +36,12 @@ function UserDetail({ id, onChanged, close }) {
useEffect(() => { api('/api/admin/user?id=' + encodeURIComponent(id)).then(setD).catch(e => toast(e.message)) }, [id])
if (!d) return <div className="muted small">Loading…</div>
const u = d.user
+ // The document comes straight off the user's state file. PUT /api/data drops null and
+ // shapeless entries now, but a file written before it did still answers with them, and this
+ // sheet renders outside the route's ErrorBoundary: one throw here blanked the whole app and
+ // left exactly this account un-disableable. setsDone/workoutVolume walk entries and sets, so
+ // an entry that lacks either has nothing to show and is skipped rather than drawn.
+ const workouts = (d.workouts || []).filter(w => w && Array.isArray(w.entries) && w.entries.every(e => e && Array.isArray(e.sets)))
const setDisabled = disabled => {
api('/api/admin/user/disable', { method: 'POST', body: JSON.stringify({ id: u.id, disabled }) })
.then(() => { toast(disabled ? 'User disabled' : 'User enabled'); onChanged(); close() })
@@ -50,7 +56,7 @@ function UserDetail({ id, onChanged, close }) {
<span className="adm-pill">joined {u.created ? fmtDate(u.created.slice(0, 10)) : '—'}</span>
</div>
<div className="tiles" style={{ textAlign: 'left' }}>
- <div className="tile"><div className="l">Workouts</div><div className="v" style={{ fontSize: '1.1rem' }}>{d.workouts.length}</div></div>
+ <div className="tile"><div className="l">Workouts</div><div className="v" style={{ fontSize: '1.1rem' }}>{workouts.length}</div></div>
<div className="tile"><div className="l">Weigh-ins</div><div className="v" style={{ fontSize: '1.1rem' }}>{d.bodyweight.length}</div></div>
<div className="tile"><div className="l">Routines</div><div className="v" style={{ fontSize: '1.1rem' }}>{d.routines.length}</div></div>
<div className="tile"><div className="l">Last sync</div><div className="v" style={{ fontSize: '.95rem' }}>{rel(d.lastSync)}</div></div>
@@ -63,8 +69,8 @@ function UserDetail({ id, onChanged, close }) {
<div className="adm-hint">{u.disabled ? 'Enabling lets them sign in and sync again.' : 'Disabling signs them out everywhere and blocks sign-in. Nothing is deleted.'}</div>
</>}
<h4 className="sec">Workout history</h4>
- {d.workouts.length ? <div className="list" style={{ gap: 0 }}>
- {d.workouts.slice(0, 60).map(w => <div key={w.id} className="row between" style={{ padding: '9px 2px', borderBottom: '1px solid var(--sep)' }}>
+ {workouts.length ? <div className="list" style={{ gap: 0 }}>
+ {workouts.slice(0, 60).map(w => <div key={w.id} className="row between" style={{ padding: '9px 2px', borderBottom: '1px solid var(--sep)' }}>
<div><div className="small" style={{ fontWeight: 600 }}>{w.name}</div>
<div className="dim" style={{ fontSize: '.72rem' }}>{fmtDate(w.d, true)} · {fmtDur((w.end || w.start) - w.start)} · {setsDone(w)} sets{w.prs?.length ? ' · ' + w.prs.length + ' PR' : ''}</div></div>
<span className="small muted">{fmtVol(w.vol ?? workoutVolume(w), d.unit)}</span>
diff --git a/frontend/src/views/Admin.test.jsx b/frontend/src/views/Admin.test.jsx
new file mode 100644
index 000000000..d3cdba6d4
--- /dev/null
+++ b/frontend/src/views/Admin.test.jsx
@@ -0,0 +1,84 @@
+// @vitest-environment happy-dom
+// The admin drill-down (QA C16): a profile whose stored workouts hold a null or otherwise
+// shapeless entry must still open, because the sheet host sits outside the route's
+// ErrorBoundary — a throw here blanked the whole app and left the account un-disableable.
+import React, { act } from 'react'
+import { createRoot } from 'react-dom/client'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import Admin from './Admin.jsx'
+
+globalThis.IS_REACT_ACT_ENVIRONMENT = true
+
+const mocks = vi.hoisted(() => ({ answers: {}, sheets: [] }))
+vi.mock('../lib/api.js', () => ({
+ api: path => {
+ const key = path.split('?')[0]
+ return key in mocks.answers ? Promise.resolve(mocks.answers[key]) : Promise.reject(new Error('not found'))
+ }
+}))
+vi.mock('../store/useStore.js', () => {
+ const snap = () => ({ user: { id: 'adm', name: 'Admin', admin: true }, S: {} })
+ const useStore = selector => selector ? selector(snap()) : snap()
+ useStore.getState = snap
+ return { useStore }
+})
+vi.mock('../store/useUI.js', () => {
+ const snap = () => ({ toast: () => {}, openSheet: render => mocks.sheets.push(render) })
+ const useUI = selector => selector ? selector(snap()) : snap()
+ useUI.getState = snap
+ return { useUI }
+})
+vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} }))
+vi.mock('../sheets.jsx', () => ({ confirmSheet: vi.fn() }))
+vi.mock('./AdminCoach.jsx', () => ({ default: () => null }))
+
+const mounted = []
+function render(el) {
+ const host = document.createElement('div')
+ document.body.appendChild(host)
+ const root = createRoot(host)
+ mounted.push(root)
+ act(() => root.render(el))
+ return host
+}
+const settle = () => act(() => new Promise(r => setTimeout(r, 0)))
+
+const good = { id: 'w1', name: 'Push day', d: '2026-09-10', start: 1000, end: 61000, entries: [{ sets: [{ done: true }, { done: false }] }] }
+
+beforeEach(() => {
+ document.body.innerHTML = ''
+ mocks.sheets.length = 0
+ mocks.answers = {
+ '/api/admin/users': { users: [{ id: 'u1', name: 'Mallory', workouts: 2, lastSync: null, disabled: false }], invite_only: false },
+ '/api/admin/invites': { invites: [] },
+ '/api/admin/audit': { rows: [] },
+ '/api/admin/user': {
+ user: { id: 'u1', name: 'Mallory', created: '2026-09-01T00:00:00Z', disabled: false, admin: false },
+ unit: 'kg', lastSync: null, routines: [], bodyweight: [],
+ // What GET /api/admin/user hands over for a document written before PUT /api/data dropped
+ // such entries: a null, and a bare object without entries, next to a real session.
+ workouts: [null, good, {}]
+ }
+ }
+})
+afterEach(() => { act(() => { mounted.splice(0).forEach(root => root.unmount()) }) })
+
+describe('Admin user drill-down', () => {
+ it('opens a profile with malformed workout entries and still offers "Disable account"', async () => {
+ const page = render(<Admin />)
+ await settle()
+ const row = [...page.querySelectorAll('.item')].find(el => el.textContent.includes('Mallory'))
+ expect(row).toBeTruthy()
+ act(() => row.click())
+ expect(mocks.sheets.length).toBe(1)
+ const sheet = render(mocks.sheets[0](() => {}))
+ await settle()
+ const buttons = [...sheet.querySelectorAll('button')].map(b => b.textContent)
+ expect(buttons).toContain('Disable account')
+ // The one real session is listed; the two shapeless entries are skipped, not drawn as blanks.
+ const rows = [...sheet.querySelectorAll('.list > div')]
+ expect(rows.length).toBe(1)
+ expect(rows[0].textContent).toContain('Push day')
+ expect(rows[0].textContent).toContain('1 sets')
+ })
+})