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:
@@ -40,8 +40,13 @@ def test_check_module_off_beats_key(db):
|
||||
assert not can(_user(role="superadmin"), "kds.access", db)
|
||||
|
||||
|
||||
def test_check_override_keys_allow(db): # the step 1.9 path, wired already
|
||||
check(AccessContext(user=_user(), override_keys=frozenset({"ordering.orders.cancel"})), "ordering.orders.cancel", db)
|
||||
def test_check_overridable_key_says_so(db): # D-10; full flow in tests/test_override.py
|
||||
with pytest.raises(XeniaError) as e:
|
||||
check(AccessContext(user=_user()), "ordering.orders.cancel", db)
|
||||
assert (e.value.code, e.value.params) == ("access.override_possible", {"key": "ordering.orders.cancel"})
|
||||
with pytest.raises(XeniaError) as e:
|
||||
check(AccessContext(user=_user(), override_token="forged"), "ordering.orders.cancel", db)
|
||||
assert e.value.code == "access.override_invalid"
|
||||
|
||||
|
||||
def test_unknown_key_is_a_programming_error(db):
|
||||
|
||||
Reference in New Issue
Block a user