feat(api): @xenia/api + @xenia/access; the manager logs in and loads bootstrap through them
Platform-v2 step 2.5 (APPS_PLATFORM D-7, D-10, §9): - @xenia/api: createApiClient (app passes its axios; session/device headers, err.xenia codes, 401/offline hooks, manager-override retry: ask PIN, grant, retry once with X-Xenia-Override); errorMessage; createLiveClient = the waiter's WebSocket logic (cursor replay, backoff, online) moved unchanged - @xenia/access: AccessProvider (bootstrap per session token, language + venue formats, translated ui labels, approval dialog), useAccess/useCan/ useModule, Can, RequireModule - i18n: errors namespace for every backend code (en/el, test vs core/errors.py), override/access texts - manager: client from createApiClient, AccessProvider in a layout route, /kds behind RequireModule, usePermissions from bootstrap keys; login and unlock no longer treat a wrong password/PIN as "session ended" (a wrong lock-screen PIN used to log the manager out) - waiter: useWebSocket is a thin wrapper over createLiveClient - tests: api/access unit tests; new e2e suite tests/e2e/manager.mjs; CS-18 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,30 @@
|
||||
import useAuthStore from '../store/authStore'
|
||||
import { useAccess } from '@xenia/access'
|
||||
|
||||
// The current screens' permission names -> the v2 keys they stand for (the same pairs as
|
||||
// local_backend/core/access/legacy.py). Removed when the pages use useCan(key) directly (phase 6).
|
||||
const KEYS = {
|
||||
accessDashboard: 'core.dashboard.access',
|
||||
accessWaiterApp: 'waiter_app.access',
|
||||
accessKds: 'kds.access',
|
||||
cancelOrders: 'ordering.orders.cancel',
|
||||
applyDiscounts: 'pricing.discounts.apply',
|
||||
modifyPrices: 'ordering.prices.modify',
|
||||
openOrders: 'ordering.orders.open',
|
||||
closeOrders: 'ordering.orders.close',
|
||||
viewReports: 'reports.view',
|
||||
manageStaff: 'core.staff.manage',
|
||||
manageTables: 'catalog.tables.manage',
|
||||
manageMenu: 'catalog.menu.manage',
|
||||
manageSettings: 'core.settings.manage',
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a permissions object derived from the logged-in user.
|
||||
* Superadmin always has every permission regardless of stored flags.
|
||||
* The signed-in user's permissions in the shape the current pages use, from the keys in
|
||||
* the platform bootstrap (@xenia/access). A key whose module is off counts as not held.
|
||||
* Superadmin holds every key (the backend sends them all).
|
||||
*/
|
||||
export default function usePermissions() {
|
||||
const user = useAuthStore(s => s.user)
|
||||
const { user, permissions } = useAccess()
|
||||
|
||||
if (!user) {
|
||||
return {
|
||||
@@ -26,24 +45,7 @@ export default function usePermissions() {
|
||||
}
|
||||
}
|
||||
|
||||
const superadmin = user.role === 'superadmin'
|
||||
|
||||
const p = (flag) => superadmin || !!user[flag]
|
||||
|
||||
return {
|
||||
isSuperadmin: superadmin,
|
||||
accessDashboard: p('perm_access_dashboard'),
|
||||
accessWaiterApp: p('perm_access_waiter_app'),
|
||||
accessKds: p('perm_access_kds'),
|
||||
cancelOrders: p('perm_cancel_orders'),
|
||||
applyDiscounts: p('perm_apply_discounts'),
|
||||
modifyPrices: p('perm_modify_prices'),
|
||||
openOrders: p('perm_open_orders'),
|
||||
closeOrders: p('perm_close_orders'),
|
||||
viewReports: p('perm_view_reports'),
|
||||
manageStaff: p('perm_manage_staff'),
|
||||
manageTables: p('perm_manage_tables'),
|
||||
manageMenu: p('perm_manage_menu'),
|
||||
manageSettings: p('perm_manage_settings'),
|
||||
}
|
||||
const out = { isSuperadmin: user.role === 'superadmin' }
|
||||
for (const [name, key] of Object.entries(KEYS)) out[name] = permissions.has(key)
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user