feat(waiter): what a waiter may do comes from permission keys (platform-v2 step 4.3)
- Payments: ordering.orders.close checked on pay/close and the counter POS
(waiters have it by default, owner decision); pay-offline always recorded.
- The venue switches waiter_cancellations / price_adjust / revert are gone:
ordering.orders.cancel, ordering.prices.modify and the new
ordering.payments.revert (overridable) decide; moves/split/transfer/merge
need ordering.orders.open; discounts pricing.discounts.apply; chat chat.use.
- Venue role defaults: role_permissions (Alembic 0024), role_template(role, db),
GET/PUT /api/waiters/roles/{role}/permissions applying the change to everyone
with the role; manager Settings -> Operation -> "What each role may do".
0024 also grants the new key to existing owners and store managers.
- Bootstrap `approvable`; @xenia/access useAllowed(key) -> yes/approve/no.
The waiter shows each action by key, "with a manager's approval (PIN)" where
allowed; GET /api/orders/cancel-permissions removed.
- Tests: test_waiter_keys.py (11), access allowed(), waiter.mjs +5, manager.mjs +3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -621,6 +621,27 @@ try {
|
||||
&& idleCfg.qr_target === 'ordering' && idleCfg.qr_caption === 'Order online', JSON.stringify(idleCfg))
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-display-settings.png'), fullPage: true })
|
||||
|
||||
// 4.3: Settings → Operation → "What each role may do" replaces the three waiter switches
|
||||
await page.goto(`${APP}/settings`)
|
||||
await page.getByRole('button', { name: 'Operation', exact: true }).click()
|
||||
await page.getByTestId('settings-role-permissions').waitFor({ timeout: 10_000 })
|
||||
r.check('settings: Operation has "What each role may do", the old waiter switches are gone',
|
||||
await page.getByText('Ακυρώσεις Παραγγελιών από Σερβιτόρους').count() === 0 && await page.getByText('Αναίρεση Πληρωμής από Σερβιτόρους').count() === 0)
|
||||
await page.getByTestId('role-perm-waiter').click()
|
||||
await page.getByTestId('perm-editor').waitFor({ timeout: 10_000 })
|
||||
const payRow = page.getByTestId('perm-ordering.orders.close')
|
||||
const payOn = await payRow.getAttribute('data-on')
|
||||
await payRow.getByRole('switch').click()
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-role-permissions.png') })
|
||||
await page.getByRole('button', { name: 'Save 1 change' }).click()
|
||||
await page.getByTestId('perm-editor').waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||||
const waiterRole = await api('GET', '/api/waiters/roles/waiter/permissions', { token: boss })
|
||||
r.check('settings: the waiter role loses "take payments" → so does every waiter (Maria)',
|
||||
payOn === 'true' && !waiterRole.keys.includes('ordering.orders.close') && !(await mariaPerms()).keys.includes('ordering.orders.close'),
|
||||
JSON.stringify(waiterRole.keys))
|
||||
await api('PUT', '/api/waiters/roles/waiter/permissions', { token: boss, body: { keys: waiterRole.default_keys } })
|
||||
r.check('settings: back to the role defaults → Maria takes payments again', (await mariaPerms()).keys.includes('ordering.orders.close'))
|
||||
|
||||
await page.goto(`${APP}/settings`)
|
||||
await page.getByText('Sign-in & security', { exact: true }).click()
|
||||
const waiterMode = page.getByTestId('setting-auth.waiter_login_mode')
|
||||
|
||||
+39
-3
@@ -1,10 +1,11 @@
|
||||
// Waiter app suite (plan phase 4): sign-in v2 on the phone (4.2): each login mode, wrong PIN,
|
||||
// one session per waiter, lock / unlock / idle sign-out, a manager's approval on the phone.
|
||||
// one session per waiter, lock / unlock / idle sign-out, a manager's approval on the phone;
|
||||
// what a waiter may do from permission keys and the venue's role defaults (4.3).
|
||||
// Starts its own backend (:8061) and the venue-mode dev build (:5181), phone-sized Edge.
|
||||
// node waiter.mjs
|
||||
import path from 'node:path'
|
||||
import { chromium } from 'playwright'
|
||||
import { BROWSER_CHANNEL, OUT, reporter, sleep } from './lib/env.mjs'
|
||||
import { BROWSER_CHANNEL, OUT, reporter, sleep, waitFor } from './lib/env.mjs'
|
||||
import { login, startBackend, startViteNative } from './lib/proc.mjs'
|
||||
|
||||
const backend = await startBackend({ port: 8061, siteId: 'test-site-1', env: { LICENSE_MODE: 'off' } })
|
||||
@@ -12,7 +13,7 @@ const vite = await startViteNative({ port: 5181, backendUrl: backend.url })
|
||||
const APP = 'http://localhost:5181'
|
||||
const TOKEN_KEY = 'xenia:dev:token'
|
||||
const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {})
|
||||
const r = reporter('waiter: sign-in v2, lock, approvals (4.2)')
|
||||
const r = reporter('waiter: sign-in v2, lock, approvals (4.2), keys (4.3)')
|
||||
const errors = []
|
||||
let failures = 0
|
||||
|
||||
@@ -120,6 +121,41 @@ try {
|
||||
const result = await a.evaluate(() => window.__res)
|
||||
r.check("the manager's PIN completes the cancel on the phone", result.ok === true, JSON.stringify(result))
|
||||
|
||||
// ── 4.3: what a waiter may do comes from permission keys ───────────────────
|
||||
const t2 = tables.find(t => t.id !== table.id && !t.open_order_id && !t.current_order_id) || tables[1]
|
||||
const o2 = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: t2.id } })
|
||||
await a.goto(`${APP}/tables/${t2.id}`)
|
||||
r.check('4.3: a waiter takes payment by default (PAY shown)', await shown(a, 'pay-button'))
|
||||
await a.getByText('ACTIONS', { exact: true }).first().click()
|
||||
await sleep(800)
|
||||
const sheet = await a.locator('.modal-sheet--top').innerText().catch(() => '')
|
||||
r.check('4.3: the actions follow the keys (transfer yes, discount hidden, cancel "with a manager\'s PIN")',
|
||||
sheet.includes('Μεταφορά Τραπεζιού') && !sheet.includes('Εφαρμογή Έκπτωσης') && sheet.includes('Με έγκριση διαχειριστή'), sheet.replace(/\s+/g, ' ').slice(0, 300))
|
||||
await a.getByText('Ακύρωση Παραγγελίας', { exact: true }).click()
|
||||
await a.getByRole('button', { name: 'Ακύρωση ✕' }).click()
|
||||
const dlg = a.getByRole('dialog')
|
||||
await dlg.waitFor({ timeout: 10_000 }).catch(() => {})
|
||||
r.check('4.3: cancelling from the screen opens the approval dialog', await a.getByTestId('override-key').textContent().catch(() => '') === 'ordering.orders.cancel')
|
||||
await dlg.locator('input').nth(0).fill('manager')
|
||||
await dlg.locator('input').nth(1).fill('1234')
|
||||
await dlg.locator('input').nth(1).press('Enter')
|
||||
const cancelled = await waitFor(async () => (await api('GET', `/api/orders/${o2.id}`, { token: boss })).status === 'cancelled', 10_000, 500)
|
||||
r.check("4.3: …and the manager's PIN cancels the order", !!cancelled)
|
||||
|
||||
// the venue takes "take payments" away from the waiter role: the phone hides PAY, the server refuses
|
||||
const role = await api('GET', '/api/waiters/roles/waiter/permissions', { token: boss })
|
||||
await api('PUT', '/api/waiters/roles/waiter/permissions', { token: boss, body: { keys: role.keys.filter(k => k !== 'ordering.orders.close') } })
|
||||
const o3 = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: t2.id } })
|
||||
await a.goto(`${APP}/tables/${t2.id}`)
|
||||
await sleep(4000)
|
||||
const refused = await api('POST', `/api/orders/${o3.id}/close`, { token: tokenA, raw: true })
|
||||
const body3 = await refused.json().catch(() => ({}))
|
||||
r.check('4.3: without "take payments" on the role: no PAY on the phone, the server refuses (access.denied)',
|
||||
await a.getByTestId('pay-button').count() === 0 && body3?.error?.code === 'access.denied', `${await a.getByTestId('pay-button').count()} ${JSON.stringify(body3).slice(0, 120)}`)
|
||||
await api('PUT', '/api/waiters/roles/waiter/permissions', { token: boss, body: { keys: role.default_keys } })
|
||||
await api('DELETE', `/api/orders/${o3.id}`, { 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: /Αποσύνδεση/ }).last().click()
|
||||
|
||||
Reference in New Issue
Block a user