feat(manager): shell navigation from modules + permission keys; profile menu language

Platform-v2 step 2.6a:
- shell/nav.js: one nav definition (module + key per page) read by the sidebar,
  the page titles and a RouteGuard around the layout outlet (and /kds): a module
  that's off hides its items and its routes say "turned off"; a missing key
  hides the item and the route says "no access". Same keys as before (v1
  permission names mapped), plus the module check
- labels/breadcrumbs are keys in a new i18n namespace `manager` (en + el)
- removed the browser-only feature toggles (usePhase2Features, Settings ->
  Λειτουργίες, F-033), PermissionGuard and usePermissions
- profile menu: language, saved to the profile (PATCH /api/auth/me) and
  bootstrap reloaded
- e2e manager.mjs: module off/on, no-key user, language switch live + saved

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 21:48:08 +02:00
co-authored by Claude Opus 5.5
parent 78c8824356
commit df57fd1552
15 changed files with 454 additions and 545 deletions
+45 -6
View File
@@ -1,4 +1,5 @@
// Manager suite (Playwright + Edge): the manager on the shared packages (plan step 2.5).
// Manager suite (Playwright + Edge): the manager on the shared packages (plan steps 2.5, 2.6).
// The demo venue has no venue.language set, so the shell starts in English.
// Starts a backend on a demo-seeded database (:8057, licensing off) and the manager's Vite
// dev server (:5186) proxied to it. Checks login and the platform bootstrap through
// @xenia/api + @xenia/access, the 401 rules (wrong password / wrong PIN stay on screen, an
@@ -70,11 +71,41 @@ try {
await sleep(1500)
r.check('login → /dashboard', new URL(page.url()).pathname === '/dashboard', page.url())
r.check('bootstrap reloaded with the session token', bootstraps.some(b => b.startsWith('Bearer ')), bootstraps.join(','))
r.check('sidebar built from bootstrap permissions (Διαχείριση, Αναφορές)',
await page.getByText('Διαχείριση').count() > 0 && await page.getByText('Αναφορές').count() > 0)
const sidebar = page.getByTestId('sidebar')
r.check('sidebar built from modules + keys (Management, Reports)',
await sidebar.getByText('Management').count() > 0 && await sidebar.getByText('Reports').count() > 0)
await page.goto(`${APP}/management/products`)
await sleep(1500)
r.check('a PermissionGuard page renders for the manager', await page.getByText('Δεν έχετε πρόσβαση').count() === 0 && (await page.evaluate(() => document.body.innerText.length)) > 200)
r.check('a guarded page renders for the manager', await page.getByTestId('route-guard').count() === 0 && (await page.evaluate(() => document.body.innerText.length)) > 200)
r.check('page title from the nav (Management › Products)', (await page.locator('header nav').first().innerText()).replace(/\s+/g, ' ').includes('Management Products'))
// ── 2.6a: a module turned off disappears from the sidebar and its route ────
const mgrNotes = await page.evaluate(() => localStorage.getItem('manager_token'))
await api('PUT', '/api/platform/modules/notes', { token: mgrNotes, body: { enabled: false } })
await page.goto(`${APP}/notes`)
await sleep(2000)
await sidebar.getByText('Management').click().catch(() => {})
r.check('notes off: no "Notes" in the sidebar', await sidebar.getByText('Notes', { exact: true }).count() === 0)
r.check('notes off: /notes shows "turned off"', await page.getByTestId('route-guard').getByText('This feature is turned off').count() === 1)
await api('PUT', '/api/platform/modules/notes', { token: mgrNotes, body: { enabled: true } })
await page.goto(`${APP}/notes`)
await sleep(2000)
r.check('notes on again: the page and the item are back', await page.getByTestId('route-guard').count() === 0 && await sidebar.getByText('Notes', { exact: true }).count() === 1)
// ── 2.6a: the profile menu language switch (live, then saved) ──────────────
await page.goto(`${APP}/dashboard`)
await sleep(1500)
await page.getByTestId('user-menu').click()
await page.getByRole('menuitemradio', { name: 'Ελληνικά' }).click()
await page.waitForFunction(() => document.querySelector('[data-testid="sidebar"]')?.innerText.includes('Διαχείριση'), null, { timeout: 5000 }).catch(() => {})
r.check('language → Ελληνικά: the shell changes live', await sidebar.getByText('Διαχείριση').count() > 0 && await page.evaluate(() => document.documentElement.lang) === 'el')
await page.reload()
await sleep(2500)
r.check('…and it was saved (still Greek after a reload)', await sidebar.getByText('Διαχείριση').count() > 0)
await page.getByTestId('user-menu').click()
await page.getByRole('menuitemradio', { name: 'English' }).click()
await page.waitForFunction(() => document.querySelector('[data-testid="sidebar"]')?.innerText.includes('Management'), null, { timeout: 5000 }).catch(() => {})
r.check('language → English again', await sidebar.getByText('Management').count() > 0)
// ── Lock screen: a wrong PIN stays locked (no logout), the right one unlocks ─
await page.goto(`${APP}/dashboard`)
@@ -104,8 +135,8 @@ try {
await page.goto(`${APP}/dashboard`)
await sleep(1500)
await api('POST', '/api/auth/logout', { token: mgr })
await page.getByText('Αναφορές').first().click()
await page.getByText('Σήμερα').first().click()
await sidebar.getByText('Reports').first().click()
await sidebar.getByText('Today').first().click()
await page.waitForURL(u => u.pathname === '/login', { timeout: 10_000 }).catch(() => {})
r.check('session ended → back to /login, token cleared',
new URL(page.url()).pathname === '/login' && !(await page.evaluate(() => localStorage.getItem('manager_token'))), page.url())
@@ -124,6 +155,14 @@ try {
await w.evaluate(t => { localStorage.setItem('manager_token', t); localStorage.setItem('manager_username', 'demo_maria') }, waiter)
await w.goto(`${APP}/dashboard`)
await sleep(2500)
// ── 2.6a: a user without the keys: no item, and "no access" on the URL ─────
const wSidebar = w.getByTestId('sidebar')
r.check('waiter in the manager: no Reports / Management items', await wSidebar.getByText('Reports').count() === 0 && await wSidebar.getByText('Management').count() === 0)
await w.goto(`${APP}/reports/today`)
await sleep(2000)
r.check('waiter opens /reports/today by URL → "no access"', await w.getByTestId('route-guard').getByText("You don't have access to this page").count() === 1)
await w.goto(`${APP}/dashboard`)
await sleep(2000)
await w.evaluate(id => {
window.__res = window.__xeniaClient.delete(`/api/orders/${id}`) // cancel the whole order
.then(res => ({ ok: true, status: res.status }), e => ({ ok: false, code: e.xenia?.code, cancelled: !!e.xenia?.overrideCancelled }))