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 activity log: pairing events read as sentences, not as auth.pair.create / code-invalid (QA C18)

Duarte Santos5bbbffe138cc
diff --git a/frontend/src/lib/audit.js b/frontend/src/lib/audit.js
index 6acdbfbd1..d3d65ac3f 100644
--- a/frontend/src/lib/audit.js
+++ b/frontend/src/lib/audit.js
@@ -21,6 +21,11 @@ const LABELS = {
'auth.register.denied': 'Signup refused',
'auth.logout': 'Signed out',
'auth.logout.all': 'Signed out everywhere',
+ // Device pairing (Settings → "Pair the mobile app"): the code is minted in a signed-in browser
+ // tab and redeemed by the app, so "ok" is the phone coming online, not a sign-in.
+ 'auth.pair.create': 'Created a pairing code',
+ 'auth.pair.ok': 'Paired a phone',
+ 'auth.pair.fail': 'Pairing failed',
'admin.user.disable': 'Disabled an account',
'admin.user.enable': 'Re-enabled an account',
'admin.invite.create': 'Created an invite code',
@@ -41,7 +46,9 @@ const REASONS = {
'account-disabled': 'the account is disabled',
'credential-exists': 'that passkey already belongs to a profile',
'invite-invalid': 'the invite code was used or revoked in the meantime',
- 'invite-rejected': 'wrong or already-used invite code'
+ 'invite-rejected': 'wrong or already-used invite code',
+ 'code-invalid': 'wrong or expired pairing code',
+ 'user-unavailable': 'the profile behind the pairing code is disabled or gone'
}
export const auditReason = msg => REASONS[msg] || (msg ? String(msg) : '')
diff --git a/frontend/src/lib/audit.test.js b/frontend/src/lib/audit.test.js
index c39c1e9b1..f8b95cc2a 100644
--- a/frontend/src/lib/audit.test.js
+++ b/frontend/src/lib/audit.test.js
@@ -1,19 +1,15 @@
import { describe, it, expect } from 'vitest'
+import { readFileSync } from 'node:fs'
import { auditCat, auditLabel, auditReason, auditLine, fmtWhen } from './audit.js'
-// Every event name and reason code the server can emit (api/server.js, the audit block).
+// Every event name and reason code the server can emit, read off api/server.js itself rather
+// than kept as a second list here: the hand-kept copy silently missed the three pairing events
+// for several releases, and the dashboard printed 'auth.pair.create' at the operator (QA C18).
// If a new one is added there without a label here, the first test fails rather than the
// dashboard quietly printing a dotted identifier at a person.
-const EVENTS = [
- 'auth.login.ok', 'auth.login.fail', 'auth.register.ok', 'auth.register.fail',
- 'auth.register.denied', 'auth.logout', 'auth.logout.all',
- 'admin.user.disable', 'admin.user.enable', 'admin.invite.create',
- 'admin.invite.revoke', 'admin.audit.clear', 'admin.denied'
-]
-const REASONS = [
- 'challenge-expired', 'unknown-credential', 'verify-error', 'not-verified',
- 'user-missing', 'account-disabled', 'credential-exists', 'invite-invalid', 'invite-rejected'
-]
+const SERVER = readFileSync(new URL('../../../api/server.js', import.meta.url), 'utf8')
+const EVENTS = [...new Set([...SERVER.matchAll(/audit\(req, '([a-z.]+)'/g)].map(m => m[1]))]
+const REASONS = [...new Set([...SERVER.matchAll(/msg: '([a-z-]+)'/g)].map(m => m[1]))]
describe('auditLabel', () => {
it('has a sentence for every event the server emits', () => {
@@ -58,6 +54,14 @@ describe('auditReason', () => {
})
describe('auditLine', () => {
+ it('reads the server lists off api/server.js, pairing events included', () => {
+ // Guards the extraction itself: an empty match would make the two loops above vacuous.
+ expect(EVENTS).toEqual(expect.arrayContaining(['auth.login.ok', 'auth.pair.create', 'auth.pair.ok', 'auth.pair.fail', 'admin.audit.clear']))
+ expect(REASONS).toEqual(expect.arrayContaining(['challenge-expired', 'code-invalid', 'user-unavailable']))
+ expect(auditLine({ ev: 'auth.pair.fail', ok: false, msg: 'code-invalid' })).toEqual({ title: 'Pairing failed', sub: 'unknown caller · wrong or expired pairing code' })
+ expect(auditLine({ ev: 'auth.pair.ok', ok: true, name: 'Verifier' })).toEqual({ title: 'Paired a phone', sub: 'Verifier' })
+ })
+
it('names the person who did it', () => {
expect(auditLine({ ev: 'auth.login.ok', ok: true, uid: 'u1', name: 'Duarte' }))
.toEqual({ title: 'Signed in', sub: 'Duarte' })