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:
@@ -86,6 +86,7 @@ export function AccessProvider({
|
||||
language: d.language,
|
||||
modules: new Set((d.modules || []).map(m => m.key)),
|
||||
permissions: new Set(d.permissions || []),
|
||||
approvable: new Set(d.approvable || []), // keys a manager may approve on the spot (4.3)
|
||||
offline: state.offline, // running on the cached bootstrap (cache prop)
|
||||
refresh: load,
|
||||
}
|
||||
|
||||
@@ -25,6 +25,21 @@ 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
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// … mounts the manager-approval dialog
|
||||
// useAccess() → { venue, user, permissions, modules, license, refresh }
|
||||
// useModule('kds') · useCan('catalog.menu.manage') · useCan([a, b]) (any) · useCan([a, b], { all: true })
|
||||
// useAllowed('ordering.orders.cancel') → 'yes' | 'approve' (a manager's PIN) | 'no' (4.3)
|
||||
// <Can perm="…" fallback={…}> · <RequireModule module="…">
|
||||
//
|
||||
// SALES_POINTS, IN_PERSON, DIGITAL where an order is sold (phase 3S)
|
||||
@@ -12,7 +13,7 @@
|
||||
// UI hiding only: the backend checks every request (CS-14).
|
||||
|
||||
export { AccessProvider } from './AccessProvider.jsx'
|
||||
export { useAccess, useModule, useCan, can } from './hooks.js'
|
||||
export { useAccess, useModule, useCan, can, useAllowed, allowed } from './hooks.js'
|
||||
export { Can, RequireModule, ModuleOff, NoAccess } from './guards.jsx'
|
||||
export { OverrideHost } from './OverrideHost.jsx'
|
||||
export { SALES_POINTS, IN_PERSON, DIGITAL, normalizeSalesPoints } from './salesPoints.js'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { test } from 'node:test'
|
||||
import { can } from '../src/hooks.js'
|
||||
import { allowed, can } from '../src/hooks.js'
|
||||
|
||||
const held = new Set(['reports.view', 'catalog.menu.manage'])
|
||||
|
||||
@@ -18,3 +18,11 @@ test('a list means any of them (like require_any), or all with all=true', () =>
|
||||
test('an empty list asks for nothing', () => {
|
||||
assert.equal(can(new Set(), []), true)
|
||||
})
|
||||
|
||||
test('allowed: held, a manager may approve, or no (plan step 4.3)', () => {
|
||||
const approvable = new Set(['ordering.orders.cancel'])
|
||||
assert.equal(allowed(held, approvable, 'reports.view'), 'yes')
|
||||
assert.equal(allowed(held, approvable, 'ordering.orders.cancel'), 'approve')
|
||||
assert.equal(allowed(held, approvable, 'pricing.discounts.apply'), 'no')
|
||||
assert.equal(allowed(held, undefined, 'ordering.orders.cancel'), 'no')
|
||||
})
|
||||
|
||||
@@ -228,7 +228,18 @@
|
||||
"saveCount_one": "Αποθήκευση {{count}} αλλαγής",
|
||||
"saveCount_other": "Αποθήκευση {{count}} αλλαγών",
|
||||
"saved": "Τα δικαιώματα του/της {{name}} αποθηκεύτηκαν",
|
||||
"cannotGrant": "Μπορείτε να δώσετε μόνο δικαιώματα που έχετε κι εσείς: «{{label}}»."
|
||||
"cannotGrant": "Μπορείτε να δώσετε μόνο δικαιώματα που έχετε κι εσείς: «{{label}}».",
|
||||
"roleTitle": "Τι επιτρέπεται στον ρόλο: {{role}}",
|
||||
"roleSubtitle_one": "Οι αλλαγές ισχύουν αμέσως για {{count}} άτομο με αυτόν τον ρόλο και για όσους προστεθούν αργότερα.",
|
||||
"roleSubtitle_other": "Οι αλλαγές ισχύουν αμέσως για {{count}} άτομα με αυτόν τον ρόλο και για όσους προστεθούν αργότερα.",
|
||||
"defaultHas": "Ανήκει στον ρόλο από προεπιλογή",
|
||||
"defaultHasNot": "Δεν ανήκει στον ρόλο από προεπιλογή",
|
||||
"roleReset": "Επαναφορά στις προεπιλογές",
|
||||
"roleResetDone": "Ορίστηκαν οι προεπιλογές. Πατήστε Αποθήκευση για να μείνουν.",
|
||||
"roleSaved": "Τα δικαιώματα του ρόλου {{role}} αποθηκεύτηκαν",
|
||||
"rolesTitle": "Τι επιτρέπεται σε κάθε ρόλο",
|
||||
"rolesDescription": "Τα δικαιώματα κάθε ρόλου: είσπραξη, ακυρώσεις, αλλαγή τιμής, εκπτώσεις, συνομιλία… Η αλλαγή ισχύει για όλους με αυτόν τον ρόλο και για όσους προστεθούν αργότερα. Μεμονωμένα άτομα αλλάζουν από τη σελίδα Προσωπικό.",
|
||||
"rolesEdit": "Επεξεργασία"
|
||||
},
|
||||
"sessions": {
|
||||
"intro": "Όσοι είναι συνδεδεμένοι αυτή τη στιγμή, και πού. Ο τερματισμός μιας σύνδεσης αποσυνδέει αμέσως το άτομο· μπορεί να συνδεθεί ξανά.",
|
||||
|
||||
@@ -295,7 +295,10 @@
|
||||
"business_day": {
|
||||
"manage": "Άνοιγμα και κλείσιμο της εργάσιμης ημέρας"
|
||||
},
|
||||
"refunds": "Επιστροφή χρημάτων για πληρωμές άλλων βαρδιών"
|
||||
"refunds": "Επιστροφή χρημάτων για πληρωμές άλλων βαρδιών",
|
||||
"payments": {
|
||||
"revert": "Αναίρεση πληρωμής (πληρωμένα → απλήρωτα)"
|
||||
}
|
||||
}
|
||||
},
|
||||
"pos_counter": {
|
||||
|
||||
@@ -228,7 +228,18 @@
|
||||
"saveCount_one": "Save {{count}} change",
|
||||
"saveCount_other": "Save {{count}} changes",
|
||||
"saved": "Permissions of {{name}} saved",
|
||||
"cannotGrant": "You can only give permissions you have yourself: \"{{label}}\"."
|
||||
"cannotGrant": "You can only give permissions you have yourself: \"{{label}}\".",
|
||||
"roleTitle": "What a {{role}} may do",
|
||||
"roleSubtitle_one": "Changes apply at once to the {{count}} person with this role, and to staff added later.",
|
||||
"roleSubtitle_other": "Changes apply at once to the {{count}} people with this role, and to staff added later.",
|
||||
"defaultHas": "Part of the role by default",
|
||||
"defaultHasNot": "Not part of the role by default",
|
||||
"roleReset": "Back to the defaults",
|
||||
"roleResetDone": "Set to the defaults. Save to keep it.",
|
||||
"roleSaved": "Permissions of the role {{role}} saved",
|
||||
"rolesTitle": "What each role may do",
|
||||
"rolesDescription": "The permissions each role gets: taking payments, cancelling, changing prices, discounts, chat… A change applies to everyone with the role and to staff added later. Single people can still be changed on the Staff page.",
|
||||
"rolesEdit": "Edit"
|
||||
},
|
||||
"sessions": {
|
||||
"intro": "Everyone signed in right now, and where. Ending a session signs that person out at once; they can sign in again.",
|
||||
|
||||
@@ -295,7 +295,10 @@
|
||||
"business_day": {
|
||||
"manage": "Open and close the business day"
|
||||
},
|
||||
"refunds": "Refund payments from other shifts"
|
||||
"refunds": "Refund payments from other shifts",
|
||||
"payments": {
|
||||
"revert": "Turn paid items back to unpaid"
|
||||
}
|
||||
}
|
||||
},
|
||||
"pos_counter": {
|
||||
|
||||
Reference in New Issue
Block a user