feat: staff and the schedule on v2; managers give staff passwords (platform-v2 step 6.11, KI-014)

- staff: PUT /api/waiters/{id}/password (set, change, or take away; 6+ chars)
  so the password sign-in mode works for everyone; PUT /{id}/pin with the PIN in
  the body (was in the address: reset-pin?pin= removed); PINs 4-6 digits when
  adding; a password can be given when adding; has_password on staff; editing
  clears emptied fields and keeps usernames unique; delete only without history
  (orders, items, shifts) and never yourself
- schedule: times checked (schedule.bad_time), one person's overlapping shifts
  refused (schedule.overlap, past midnight understood), everyone active can be
  scheduled (the kitchen too), changes need core.staff.manage
- manager: src/pages/staff (list with search and filters, person dialog with
  photo, PIN / password dialog, zones) and src/pages/schedule (by person, by
  hour with opening hours, shift dialog with clash check, view settings kept in
  the browser); the never-used "automatic start/close" switches dropped; v1
  StaffTab and SchedulePage removed; ApprovalsPage loads with useLiveQuery
- tests: test_staff_v2.py (done-when on a paired screen), staff.test.mjs, e2e
  manager.mjs (add, password, sign-in on a paired till, a shift and a clash)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 08:05:01 +02:00
co-authored by Claude Opus 5.5
parent f31bdf42aa
commit 6643614ff6
27 changed files with 1554 additions and 1794 deletions
+61
View File
@@ -1100,6 +1100,67 @@ try {
if (savedZone) await api('DELETE', `/api/prep-zones/${savedZone.id}`, { token: boss })
if (grill) await api('DELETE', `/api/system/printers/${grill.id}`, { token: boss })
// ── 6.11: staff on v2; a password given by the manager works on a paired screen (KI-014) ──
const st = 'staff:'
await page.goto(`${APP}/management/staff`)
await page.getByTestId('staff-new').click()
await page.getByTestId('staff-save').click()
r.check(`${st} a new person needs their names, a username and a PIN`, await page.getByTestId('staff-dialog').count() === 1
&& (await page.getByTestId('staff-dialog').textContent()).includes('4 to 6 digits'))
await page.getByTestId('staff-full-name').fill('Eleni E2E')
await page.getByTestId('staff-nickname').fill('Eleni')
await page.getByTestId('staff-username').fill('e2e_eleni')
await page.getByTestId('staff-new-pin').fill('2580')
await page.getByTestId('staff-rate').fill('8,5')
await page.getByTestId('staff-save').click()
const eleniRow = page.locator('[data-testid="staff-row"][data-username="e2e_eleni"]')
const eleniListed = await eleniRow.waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
let eleni = (await api('GET', '/api/waiters/', { token: boss })).find(m => m.username === 'e2e_eleni')
r.check(`${st} added from the page: a waiter with a PIN, no password, pay 8.50`, eleniListed && eleni?.role === 'waiter' && eleni.has_password === false && eleni.hourly_rate === 8.5, JSON.stringify(eleni))
await eleniRow.getByTestId('staff-password').click()
await page.getByTestId('secret-value').fill('kalimera6')
await page.getByTestId('secret-again').fill('kalimera7')
await page.getByTestId('secret-save').click()
r.check(`${st} the two passwords must match`, (await page.getByTestId('secret-dialog').textContent()).includes("don't match"))
await page.getByTestId('secret-again').fill('kalimera6')
await page.getByTestId('secret-save').click()
await page.getByTestId('secret-dialog').waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
await eleniRow.getByText('PIN + password').waitFor({ timeout: 8000 }).catch(() => {})
eleni = (await api('GET', '/api/waiters/', { token: boss })).find(m => m.username === 'e2e_eleni')
r.check(`${st} the manager gives her a password: the row says "PIN + password"`, eleni.has_password === true && (await eleniRow.textContent()).includes('PIN + password'))
await page.screenshot({ path: path.join(OUT, 'manager-staff-v2.png'), fullPage: true })
// a counter screen that signs in by password
await api('PUT', '/api/platform/modules/pos_counter', { token: boss, body: { enabled: true } }).catch(() => {})
const tillReq = await deviceRequestsPairing()
await api('POST', '/api/devices', { token: boss, body: { code: tillReq.code, app_key: 'pos_counter', name: 'E2E till', login_mode: 'password' } })
const tillToken = await devicePicksUpToken(tillReq)
const tillLogin = async password => fetch(`${backend.url}/api/auth/login`, {
method: 'POST', headers: { 'content-type': 'application/json', 'X-Xenia-Device': tillToken },
body: JSON.stringify({ client: 'terminal', username: 'e2e_eleni', password }),
}).then(async x => ({ status: x.status, body: await x.json() }))
const wrongPw = await tillLogin('wrong-one')
const rightPw = await tillLogin('kalimera6')
r.check(`${st} the done-when: she signs in with that password on a paired screen (a wrong one is refused)`,
wrongPw.body?.error?.code === 'auth.invalid_credentials' && rightPw.status === 200 && rightPw.body.user?.username === 'e2e_eleni', JSON.stringify(rightPw.body).slice(0, 200))
// the schedule: a shift for her, and a clash shown before saving
await page.goto(`${APP}/management/schedule`)
const eleniPlan = page.locator('[data-testid="schedule-person"][data-name="Eleni E2E"]')
await eleniPlan.waitFor({ timeout: 10_000 }).catch(() => {})
await eleniPlan.getByTestId('schedule-add').first().click()
await page.getByTestId('shift-start').fill('18:00')
await page.getByTestId('shift-end').fill('02:00')
await page.getByTestId('shift-save').click()
const planned = await eleniPlan.getByTestId('schedule-shift').first().waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
r.check(`${st} schedule: a shift 18:00–02:00 for her, 8 hours, costed at her pay`, planned
&& (await eleniPlan.getByTestId('schedule-shift').first().textContent()).includes('18:00–02:00')
&& (await eleniPlan.textContent()).includes('8 hours') && (await page.getByTestId('schedule-totals').textContent()).includes('€'))
await eleniPlan.getByTestId('schedule-add').first().click()
await page.getByTestId('shift-start').fill('20:00')
await page.getByTestId('shift-end').fill('22:00')
r.check(`${st} schedule: an overlapping shift is flagged and can't be saved`, await page.getByTestId('shift-clash').count() === 1 && await page.getByTestId('shift-save').isDisabled())
await page.screenshot({ path: path.join(OUT, 'manager-schedule.png'), fullPage: true })
await page.keyboard.press('Escape')
await api('PUT', '/api/platform/modules/connect_orders', { token: boss, body: { enabled: true } })
await page.goto(`${APP}/online-orders`)
await page.getByTestId('online-orders').waitFor({ timeout: 10_000 }).catch(() => {})