feat(backend): manager override with one-time PIN approval for cancel, price change, over-limit discount
Platform v2 step 1.9 (APPS_PLATFORM D-10).
- Perm(..., overridable=True). check() answers access.override_possible (not
access.denied) for such keys, and consumes an X-Xenia-Override token for them.
- POST /api/access/override {key, username, pin}: the approver must hold the key
(module effective); returns a token valid 60 s, once, for that key and the
requesting session only (sha256 stored). Wrong PINs throttled per session.
GET /api/access/overrides: audit list (core.staff.manage).
- access_overrides table (revision 0008): who asked, session, who approved, device,
key, created/expires/used, target. The revision also grants core.devices.manage and
the new pricing.discounts.over_limit to existing owners/store managers.
- Overridable: ordering.orders.cancel (the three cancel endpoints; the order audit log
notes "override #n approved by user m"), ordering.prices.modify (price adjust), and
new pricing.discounts.over_limit (waiter discounts beyond their limits; the reason
goes in params). The venue switch discounts.enabled is never overridable.
- /orders/cancel-permissions adds override_possible; permission catalogues expose
`overridable`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,8 @@ class AccessContext:
|
||||
user: Any = None # User row, or the support ghost (step 1.10); None for device-only calls
|
||||
session: Any = None # session id (sid) of the user's login
|
||||
device: Any = None # Device row when the call comes from a paired device (D-8)
|
||||
override_keys: frozenset = frozenset() # step 1.9
|
||||
override_token: Optional[str] = None # X-Xenia-Override (D-10); consumed by check() when needed
|
||||
target: Optional[str] = None # what the request acts on, for the override audit row
|
||||
|
||||
|
||||
def module_of(key: str) -> str:
|
||||
@@ -53,6 +54,12 @@ def check(ctx: AccessContext, key: str, db=None) -> None:
|
||||
from core.access.context import in_scope
|
||||
if not in_scope(ctx.device.app_key, key):
|
||||
raise XeniaError("device.out_of_scope", app=ctx.device.app_key, key=key)
|
||||
if holds(ctx.user, key) or key in ctx.override_keys:
|
||||
if holds(ctx.user, key):
|
||||
return
|
||||
from core.access.override import consume, is_overridable
|
||||
if is_overridable(key):
|
||||
if ctx.override_token:
|
||||
consume(db, ctx.override_token, key, ctx.session, ctx.target)
|
||||
return
|
||||
raise XeniaError("access.override_possible", key=key)
|
||||
raise XeniaError("access.denied", key=key)
|
||||
|
||||
Reference in New Issue
Block a user