- 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>
48 lines
1.7 KiB
JavaScript
48 lines
1.7 KiB
JavaScript
import { useContext } from 'react'
|
|
import { AccessContext } from './context.js'
|
|
|
|
/**
|
|
* Everything bootstrap said (GET /api/platform/bootstrap):
|
|
* { venue, user, permissions (Set), modules (Set), license, languages, bootstrap (raw), refresh() }
|
|
* permissions: the keys the signed-in user holds, only for modules that are on (superadmin: all).
|
|
*/
|
|
export function useAccess() {
|
|
const ctx = useContext(AccessContext)
|
|
if (!ctx) throw new Error('useAccess() needs an <AccessProvider> above it')
|
|
return ctx
|
|
}
|
|
|
|
/** Is this module licensed and turned on? */
|
|
export function useModule(key) {
|
|
return useAccess().modules.has(key)
|
|
}
|
|
|
|
/**
|
|
* Does the signed-in user hold this key? With a list, ANY of them (like the backend's
|
|
* require_any); { all: true } for all of them. Hides UI only: the backend always checks too.
|
|
*/
|
|
export function useCan(keys, { all = false } = {}) {
|
|
return can(useAccess().permissions, keys, all)
|
|
}
|
|
|
|
/**
|
|
* May the user do it (plan step 4.3)? 'yes' (they hold the key), 'approve' (they don't, but a
|
|
* manager may approve it with their PIN: show the action, the approval dialog runs when the
|
|
* server asks) or 'no' (hide it, or show it disabled with the reason).
|
|
*/
|
|
export function useAllowed(key) {
|
|
const { permissions, approvable } = useAccess()
|
|
return allowed(permissions, approvable, key)
|
|
}
|
|
|
|
export function allowed(permissions, approvable, key) {
|
|
if (permissions.has(key)) return 'yes'
|
|
return approvable?.has(key) ? 'approve' : 'no'
|
|
}
|
|
|
|
export function can(permissions, keys, all = false) {
|
|
const list = Array.isArray(keys) ? keys : [keys]
|
|
if (!list.length) return true
|
|
return all ? list.every(k => permissions.has(k)) : list.some(k => permissions.has(k))
|
|
}
|