feat(backend,waiter,terminal,manager): sign-in: ask before signing a waiter's other phone out, usernames on paired screens
- auth.single_session_waiter gains 'ask', the new default (Alembic 0051 moves venues on 'off'
to it): a second phone gets auth.session_elsewhere {device, since}; Continue retries with
replace=true and the first phone is signed out at once (live session.ended, reason
"replaced") and says why on its sign-in page. Only phones count (terminal sessions are
their own client). refuse_new / end_old unchanged.
- auth.session_ended now carries the reason; the waiter app keeps it until the next sign-in.
- The waiter app sends queued offline ops on every (re)connection, so an order queued on a
phone that was signed out by another goes out after the next sign-in there (e2e checked).
- auth.terminal_require_username (venue) + Device.require_username (per device, wins):
GET /api/devices/me/users lists nobody, the screen asks for a username then PIN/password,
a picked user_id is refused (auth.username_required), "tap" falls back to PIN.
- Manager: Sign-in settings (ask, the new switch), the device dialog's usernames choice.
Plan platform-v2 6F.7.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+15
-5
@@ -189,7 +189,7 @@ try {
|
||||
await page.getByRole('button', { name: 'Pair a device' }).first().click()
|
||||
await dlg.getByLabel('Code shown on the device').fill('zz-zz-zz')
|
||||
await dlg.getByLabel('App to run').selectOption('kds')
|
||||
await dlg.getByLabel('Name').fill('Kitchen')
|
||||
await dlg.getByLabel('Name', { exact: true }).fill('Kitchen')
|
||||
await dlg.getByRole('button', { name: 'Pair a device' }).click()
|
||||
await page.getByTestId('pair-error').waitFor({ timeout: 5000 }).catch(() => {})
|
||||
r.check('devices: a wrong code is refused with a message', (await page.getByTestId('pair-error').textContent().catch(() => '')).includes('pairing code is wrong'))
|
||||
@@ -221,12 +221,15 @@ try {
|
||||
r.check('devices: the screen opens a live connection with its device token alone (3.1a)', await sock.ready)
|
||||
await row.getByRole('button', { name: 'Edit' }).click()
|
||||
r.check('devices: the edit dialog shows the device setting', await dlg.getByLabel('Sign out after').inputValue() === '10')
|
||||
await dlg.getByLabel('Name').fill('Kitchen 1')
|
||||
await dlg.getByLabel('Name', { exact: true }).fill('Kitchen 1')
|
||||
await dlg.getByLabel('Sign out after').selectOption('5')
|
||||
await dlg.getByTestId('device-usernames').selectOption('true') // 6F.7: this screen asks for usernames
|
||||
await dlg.getByRole('button', { name: 'Save' }).click()
|
||||
await page.waitForFunction(() => document.querySelector('[data-testid^="device-"][data-status]')?.textContent.includes('Kitchen 1'), null, { timeout: 8000 }).catch(() => {})
|
||||
const me2 = await asDevice(deviceToken, '/api/devices/me').then(x => x.json())
|
||||
r.check('devices: renamed, setting changed', (await row.textContent()).includes('Kitchen 1') && me2.name === 'Kitchen 1' && me2.config?.auto_sign_out_minutes === 5, JSON.stringify(me2))
|
||||
r.check('6F.7: a device set to "staff type their username" lists nobody', me2.require_username === true
|
||||
&& (await asDevice(deviceToken, '/api/devices/me/users').then(x => x.json())).length === 0)
|
||||
await sleep(300)
|
||||
r.check('devices: the screen is told at once (device.updated)', sock.messages.some(m => m.type === 'device.updated'), JSON.stringify(sock.messages))
|
||||
|
||||
@@ -667,11 +670,18 @@ try {
|
||||
(await api('GET', '/api/platform/bootstrap')).login.manager_mode === 'pin')
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-settings-sign-in.png'), fullPage: true })
|
||||
await page.getByTestId('setting-auth.manager_login_mode').selectOption('password')
|
||||
const sessionDefault = await page.getByTestId('setting-auth.single_session_waiter').inputValue()
|
||||
r.check('6F.7: one session per waiter is "ask" by default', sessionDefault === 'ask', sessionDefault)
|
||||
await page.getByTestId('setting-auth.terminal_require_username').click()
|
||||
await sleep(800)
|
||||
r.check('6F.7: "staff type their username" on paired devices is saved', await settingValue('auth.terminal_require_username') === 'true')
|
||||
await page.getByTestId('setting-auth.terminal_require_username').click()
|
||||
await sleep(800)
|
||||
await page.getByTestId('setting-auth.single_session_waiter').selectOption('end_old')
|
||||
await sleep(800)
|
||||
r.check('settings: one session per waiter → "sign out the older one"', await settingValue('auth.single_session_waiter') === 'end_old' &&
|
||||
await settingValue('auth.manager_login_mode') === 'password' && await settingValue('auth.waiter_login_mode') === 'pin')
|
||||
await page.getByTestId('setting-auth.single_session_waiter').selectOption('off')
|
||||
await page.getByTestId('setting-auth.single_session_waiter').selectOption('ask')
|
||||
const idleSel = page.getByTestId('setting-auth.idle_days')
|
||||
const idleDefault = await idleSel.inputValue()
|
||||
await idleSel.selectOption('30')
|
||||
@@ -912,7 +922,7 @@ try {
|
||||
const odlg = o.getByRole('dialog')
|
||||
await odlg.getByLabel('Code shown on the device').fill(kitchenCode)
|
||||
await odlg.getByLabel('App to run').selectOption('kds')
|
||||
await odlg.getByLabel('Name').fill('Kitchen pass')
|
||||
await odlg.getByLabel('Name', { exact: true }).fill('Kitchen pass')
|
||||
await odlg.getByLabel('How staff sign in').selectOption('pin')
|
||||
await odlg.getByRole('button', { name: 'Pair a device' }).click()
|
||||
await odlg.waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||||
@@ -971,7 +981,7 @@ try {
|
||||
r.check(`${ov} a shift started for a waiter with €20.50 (typed with a comma)`, await ovRow.waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||||
&& (await api('GET', '/api/shifts/?active_only=true', { token: boss })).shifts.some(s => s.waiter_id === ovWaiter.id && s.starting_cash === 20.5))
|
||||
const freeTable = (await api('GET', '/api/tables/', { token: boss })).find(t => !t.open_order_id && !t.current_order_id)
|
||||
const ovOrder = await api('POST', '/api/orders/', { token: await loginApi('demo_maria', { pin: '3302', client: 'waiter' }), body: { table_id: freeTable.id } })
|
||||
const ovOrder = await api('POST', '/api/orders/', { token: await loginApi('demo_maria', { pin: '3302', client: 'waiter', replace: true }), body: { table_id: freeTable.id } })
|
||||
const chip = page.locator(`[data-testid="table-chip"][data-state="open"]`).filter({ hasText: freeTable.label || `T${freeTable.number}` }).first()
|
||||
r.check(`${ov} a table a waiter opens turns "open" by itself (live)`, await chip.waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||||
await chip.click()
|
||||
|
||||
@@ -308,6 +308,30 @@ try {
|
||||
await api('POST', `/api/auth/sessions/${sid}/end`, { token: boss })
|
||||
r.check('session ended by a manager → the screen is back at sign-in at once', await shown(page, 'sign-in-screen', 8000))
|
||||
|
||||
// ── 6F.7: usernames on paired screens (venue setting, the device's own choice wins) ──
|
||||
await api('PUT', '/api/settings/auth.terminal_require_username', { token: boss, body: { value: 'true' } })
|
||||
r.check('6F.7: usernames on → the screen lists nobody and asks for a username (live)',
|
||||
await shown(page, 'username-form', 8000) && await page.getByTestId('user-grid').count() === 0)
|
||||
await page.screenshot({ path: path.join(OUT, 'terminal-username.png') })
|
||||
const byName = async name => {
|
||||
await page.getByTestId('username-input').fill(name)
|
||||
await page.getByRole('button', { name: 'Next' }).click()
|
||||
await page.getByLabel('Password').fill('password')
|
||||
await page.getByRole('button', { name: 'Sign in' }).click()
|
||||
}
|
||||
await byName('nobody_here')
|
||||
await sleep(1200)
|
||||
r.check('6F.7: a wrong username is refused', await page.getByTestId('app-kds').count() === 0 && await page.getByTestId('sign-in-screen').count() === 1)
|
||||
await page.getByRole('button', { name: 'Back' }).click()
|
||||
await byName('manager')
|
||||
r.check('6F.7: username + password signs in', await shown(page, 'app-kds'))
|
||||
await page.getByRole('button', { name: 'Sign out' }).click()
|
||||
await api('PATCH', `/api/devices/${kitchen.id}`, { token: boss, body: { require_username: false } })
|
||||
r.check('6F.7: the device\'s own "no" wins: the names are back', await shown(page, 'user-grid', 8000))
|
||||
await api('PATCH', `/api/devices/${kitchen.id}`, { token: boss, body: { require_username: null } })
|
||||
await api('PUT', '/api/settings/auth.terminal_require_username', { token: boss, body: { value: 'false' } })
|
||||
await shown(page, 'user-grid', 8000)
|
||||
|
||||
// ── app off / on ──────────────────────────────────────────────────────────
|
||||
await api('PUT', '/api/platform/modules/kds', { token: boss, body: { enabled: false } })
|
||||
r.check('KDS turned off → "turned off" screen, live', await shown(page, 'blocked-screen', 8000)
|
||||
|
||||
@@ -596,6 +596,53 @@ try {
|
||||
await a.getByRole('button', { name: /Dark theme/ }).click()
|
||||
await a.reload()
|
||||
|
||||
// ── 6F.7: "ask" (the default): the second phone asks; Continue signs the first one out and it
|
||||
// says why; an order queued offline on the first phone goes out after it signs in again ──
|
||||
{
|
||||
await setting(boss, 'auth.single_session_waiter', 'ask')
|
||||
const busy7 = new Set((await api('GET', '/api/orders/', { token: boss })).map(o => o.table_id))
|
||||
const tq = (await api('GET', '/api/tables/', { token: boss })).find(x => x.is_active !== false && !busy7.has(x.id))
|
||||
const status7 = async () => (await api('GET', `/api/tables/${tq.id}/status`, { token: boss })).active_order_id
|
||||
await a.goto(`${APP}/tables/${tq.id}/add?new=1`)
|
||||
await addOn(tq.id, plain)
|
||||
await ctxA.setOffline(true)
|
||||
await a.getByTestId('cart-open').click()
|
||||
await waitFor(async () => (await total().innerText().catch(() => '')).includes('offline'), 30_000, 1000)
|
||||
await a.getByRole('button', { name: /^(SEND|SUMMARY)/ }).last().click()
|
||||
if (await shown(a, 'summary-total', 3000)) await a.getByRole('button', { name: /SEND/ }).last().click()
|
||||
await sleep(1500)
|
||||
// the second phone
|
||||
await b.reload()
|
||||
await b.getByTestId('waiter-card').filter({ hasText: 'Κωνσταντίνου' }).click({ timeout: 10_000 })
|
||||
await pin(b, '3302')
|
||||
const asked = await shown(b, 'login-elsewhere', 5000)
|
||||
const askText = await b.getByTestId('login-elsewhere').innerText().catch(() => '')
|
||||
r.check('6F.7: a second phone asks (where, since when) instead of refusing', asked && /\d\d:\d\d/.test(askText) && !(await tokenOf(b)), askText.replace(/\s+/g, ' '))
|
||||
await b.screenshot({ path: path.join(OUT, 'waiter-signed-in-elsewhere.png') })
|
||||
await b.getByTestId('login-elsewhere-continue').click()
|
||||
await b.waitForURL(u => u.pathname !== '/login', { timeout: 10_000 }).catch(() => {})
|
||||
r.check('6F.7: Continue signs this phone in', !!(await tokenOf(b)) && await pathOf(b) !== '/login', await pathOf(b))
|
||||
// the first phone comes back: signed out, says why, the order still queued
|
||||
await ctxA.setOffline(false)
|
||||
const outA = await a.waitForURL(u => u.pathname === '/login', { timeout: 45_000 }).then(() => true).catch(() => false)
|
||||
const noteA = await a.getByTestId('signed-out-note').innerText({ timeout: 10_000 }).catch(() => '')
|
||||
r.check('6F.7: the first phone, back online, is signed out and says why', outA && /another device|άλλη συσκευή/.test(noteA), noteA)
|
||||
await a.screenshot({ path: path.join(OUT, 'waiter-signed-out-replaced.png') })
|
||||
r.check('6F.7: its order queued offline was not sent with the ended session', !(await status7()))
|
||||
// it signs in again (asks: the second phone now); the second phone leaves at once (live)
|
||||
await a.getByTestId('waiter-card').filter({ hasText: 'Κωνσταντίνου' }).click({ timeout: 10_000 })
|
||||
await pin(a, '3302')
|
||||
await a.getByTestId('login-elsewhere-continue').click({ timeout: 5000 })
|
||||
await a.waitForURL(u => u.pathname !== '/login', { timeout: 10_000 }).catch(() => {})
|
||||
const outB = await b.waitForURL(u => u.pathname === '/login', { timeout: 10_000 }).then(() => true).catch(() => false)
|
||||
const noteB = await b.getByTestId('signed-out-note').innerText({ timeout: 5000 }).catch(() => '')
|
||||
r.check('6F.7: the other phone is signed out at once (live) and says why', outB && /another device|άλλη συσκευή/.test(noteB), noteB)
|
||||
const flushed = await waitFor(status7, 30_000, 1000)
|
||||
r.check('6F.7: …and the order queued offline goes out after signing in again', !!flushed)
|
||||
if (flushed) await api('DELETE', `/api/orders/${flushed}`, { token: boss }).catch(() => {})
|
||||
await a.goto(`${APP}/tables`)
|
||||
}
|
||||
|
||||
// ── Signing out ends the session on the server: the second phone can sign in ─
|
||||
await a.getByRole('button', { name: 'demo_maria' }).first().click({ timeout: 10_000 })
|
||||
await a.getByRole('button', { name: /Sign out/ }).last().click()
|
||||
|
||||
Reference in New Issue
Block a user