feat(manager): staff permission editor, signed-in sessions, approvals log (platform-v2 2.6e)
- Staff: the 13 perm_* tick columns become one Permissions column (count, "changed from role") opening an editor grouped by module, from /api/waiters/permission-catalog: switches labelled per key, keys you don't hold are disabled with the reason, reset to role defaults (names what it can't give), save the whole set; access.cannot_grant explained by label. - "Signed in now" (/management/sessions): who, where (app or device), since, last active, your own session marked; end session; show ended + reason. - "Manager approvals" (/management/approvals): the override audit with action label, asked by, approved by, device, used/not used, order link. - Backend: sessions list adds device_name/device_app/current/expires_at; overrides list adds device_name/expires_at. - Permission labels for every key in modules.json (en/el), guarded by test_module_texts; manager unit tests for the editor logic; e2e 66 checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -339,6 +339,97 @@ try {
|
||||
r.check('the approval is audited', audit[0]?.key === 'ordering.orders.cancel' && audit[0]?.target === `order:${order.id}` && !!audit[0]?.used_at, JSON.stringify(audit[0]))
|
||||
await w.screenshot({ path: path.join(OUT, 'manager-after-approval.png') })
|
||||
|
||||
// ── 2.6e: approvals log, who is signed in, staff permissions ───────────────
|
||||
await uiLogin(page, 'password')
|
||||
await page.waitForURL(u => u.pathname === '/dashboard', { timeout: 15_000 }).catch(() => {})
|
||||
const staffList = await api('GET', '/api/waiters/', { token: boss })
|
||||
const maria = staffList.find(u => u.username === 'demo_maria')
|
||||
|
||||
await page.goto(`${APP}/management/approvals`)
|
||||
const approval = page.locator(`[data-testid="approval-${audit[0].id}"]`)
|
||||
await approval.waitFor({ timeout: 10_000 }).catch(() => {})
|
||||
const approvalText = await approval.textContent().catch(() => '')
|
||||
r.check('approvals: the cancel is listed: action, who asked, who approved, used on the order',
|
||||
await approval.getAttribute('data-state').catch(() => '') === 'used' && approvalText.includes('Cancel items already sent') &&
|
||||
approvalText.includes(maria.full_name) && approvalText.includes(`Order #${order.id}`), approvalText)
|
||||
|
||||
await page.goto(`${APP}/management/sessions`)
|
||||
await page.getByTestId('sessions-table').waitFor({ timeout: 10_000 }).catch(() => {})
|
||||
const mariaRow = page.locator(`[data-user="${maria.id}"][data-client="waiter"][data-ended="false"]`)
|
||||
r.check('sessions: the waiter is listed (Waiter app) and my own row is "You, here" with no end button',
|
||||
await mariaRow.count() >= 1 && (await mariaRow.first().textContent()).includes('Waiter app') &&
|
||||
await page.locator('tr', { hasText: 'You, here' }).getByRole('button', { name: 'End session' }).count() === 0)
|
||||
await mariaRow.first().getByRole('button', { name: 'End session' }).click()
|
||||
await page.getByRole('dialog').getByRole('button', { name: 'End session' }).click()
|
||||
await page.waitForFunction(id => !document.querySelector(`[data-user="${id}"][data-client="waiter"][data-ended="false"]`), maria.id, { timeout: 8000 }).catch(() => {})
|
||||
const mariaMe = await fetch(`${backend.url}/api/auth/me`, { headers: { authorization: `Bearer ${waiter}` } })
|
||||
r.check('sessions: "End session" → gone from the list, the waiter\'s next call is refused',
|
||||
await mariaRow.count() === 0 && mariaMe.status === 401 && (await mariaMe.json()).error.code === 'auth.session_ended')
|
||||
await page.getByLabel('Show ended sessions').check()
|
||||
await page.waitForFunction(id => document.querySelector(`[data-user="${id}"][data-ended="true"]`), maria.id, { timeout: 8000 }).catch(() => {})
|
||||
r.check('sessions: "show ended" lists it as ended by a manager',
|
||||
(await page.locator(`[data-user="${maria.id}"][data-ended="true"]`).first().textContent().catch(() => '')).includes('ended by a manager'))
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-sessions.png'), fullPage: true })
|
||||
|
||||
// the permission editor: give one key, see it differ from the role, reset
|
||||
const mariaPerms = () => api('GET', `/api/waiters/${maria.id}/permissions`, { token: boss })
|
||||
const before = await mariaPerms()
|
||||
await page.goto(`${APP}/management/staff`)
|
||||
const permCell = page.getByTestId(`staff-perms-${maria.id}`)
|
||||
await permCell.waitFor({ timeout: 10_000 })
|
||||
r.check('staff: a Permissions column with the count instead of 13 tick columns',
|
||||
(await permCell.textContent()).includes(`${before.keys.length} permissions`) && await page.getByText('Ακύρωση', { exact: true }).count() === 0)
|
||||
await permCell.getByRole('button').click()
|
||||
const editor = page.getByTestId('perm-editor')
|
||||
await editor.waitFor({ timeout: 10_000 })
|
||||
const cancelRow = page.getByTestId('perm-ordering.orders.cancel')
|
||||
r.check('editor: grouped by module (Ordering, Kitchen display, Core…), cancel is off for a waiter',
|
||||
await page.getByTestId('perm-group-ordering').count() === 1 && await page.getByTestId('perm-group-core').count() === 1 &&
|
||||
await cancelRow.getAttribute('data-on') === 'false' && (await cancelRow.textContent()).includes('Cancel items already sent'))
|
||||
await cancelRow.getByRole('switch').click()
|
||||
await page.getByRole('button', { name: 'Save 1 change' }).click()
|
||||
await editor.waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||||
const afterGive = await mariaPerms()
|
||||
await page.waitForFunction(id => document.querySelector(`[data-testid="staff-perms-${id}"]`)?.textContent.includes('Changed from role'), maria.id, { timeout: 8000 }).catch(() => {})
|
||||
r.check('editor: saved → the waiter has the key, the row says "Changed from role"',
|
||||
afterGive.keys.includes('ordering.orders.cancel') && (await permCell.textContent()).includes('Changed from role'), JSON.stringify(afterGive.keys))
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-staff.png'), fullPage: true })
|
||||
await permCell.getByRole('button').click()
|
||||
await editor.waitFor({ timeout: 10_000 })
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-permissions.png') })
|
||||
await page.getByTestId('perm-reset').click()
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-permissions-reset.png') })
|
||||
r.check('editor: reset → the draft is the role\'s defaults (cancel off again), saying so',
|
||||
await cancelRow.getAttribute('data-on') === 'false' && await page.getByTestId('perm-note').count() === 1)
|
||||
await page.getByRole('button', { name: /^Save \d+ change/ }).click()
|
||||
await editor.waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||||
const afterReset = await mariaPerms()
|
||||
r.check('editor: reset saved → keys = the role template',
|
||||
JSON.stringify(afterReset.keys) === JSON.stringify(afterReset.role_template), JSON.stringify(afterReset.keys))
|
||||
|
||||
// a staff manager can't give what they don't have (disabled), and the backend's refusal is explained
|
||||
const sm = await api('POST', '/api/waiters/', { token: boss, body: { username: 'e2e_staffmgr', full_name: 'Stella Staff', pin: '5151', role: 'staff_manager', is_active: true } })
|
||||
const smToken = await loginApi('e2e_staffmgr', { pin: '5151' })
|
||||
const s2 = await (await browser.newContext({ viewport: { width: 1400, height: 900 } })).newPage()
|
||||
s2.on('pageerror', e => errors.push(e.message))
|
||||
await s2.goto(`${APP}/login`)
|
||||
await s2.evaluate(t => { localStorage.setItem('manager_token', t); localStorage.setItem('manager_username', 'e2e_staffmgr') }, smToken)
|
||||
await s2.goto(`${APP}/management/staff`)
|
||||
await s2.getByTestId(`staff-perms-${maria.id}`).getByRole('button').click()
|
||||
await s2.getByTestId('perm-editor').waitFor({ timeout: 10_000 })
|
||||
const smCancel = s2.getByTestId('perm-ordering.orders.cancel')
|
||||
r.check('staff manager: "cancel" is disabled with the reason (they don\'t have it)',
|
||||
await smCancel.getByRole('switch').isDisabled() && (await smCancel.textContent()).includes("You don't have this permission yourself"))
|
||||
// they had "See reports" when the editor opened; the owner takes it away before they save
|
||||
const smKeys = (await api('GET', `/api/waiters/${sm.id}/permissions`, { token: boss })).keys
|
||||
await api('PUT', `/api/waiters/${sm.id}/permissions`, { token: boss, body: { keys: smKeys.filter(k => k !== 'reports.view') } })
|
||||
await s2.getByTestId('perm-reports.view').getByRole('switch').click()
|
||||
await s2.getByRole('button', { name: 'Save 1 change' }).click()
|
||||
await s2.getByTestId('perm-error').waitFor({ timeout: 8000 }).catch(() => {})
|
||||
r.check('staff manager: the backend refuses (access.cannot_grant), named by its label',
|
||||
(await s2.getByTestId('perm-error').textContent().catch(() => '')).includes('You can only give permissions you have yourself: "See reports"'))
|
||||
r.check('…and nothing was saved', !(await mariaPerms()).keys.includes('reports.view'))
|
||||
|
||||
r.check('no page errors', errors.length === 0, errors.slice(0, 3).join(' | '))
|
||||
} finally {
|
||||
await browser.close()
|
||||
|
||||
Reference in New Issue
Block a user