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:
@@ -116,6 +116,23 @@ def check_device_scope(device, module: str) -> None:
|
||||
raise XeniaError("device.out_of_scope", app=device.app_key, key=module)
|
||||
|
||||
|
||||
def context_for(request: Request, user, db) -> AccessContext:
|
||||
"""AccessContext of a request whose user is already known (require() and inline checks)."""
|
||||
from core.access.override import HEADER
|
||||
return AccessContext(user=user, session=getattr(request.state, "xenia_sid", None),
|
||||
device=current_device(request, db), override_token=request.headers.get(HEADER),
|
||||
target=f"{request.method} {request.url.path}")
|
||||
|
||||
|
||||
def authorize(request: Request, db, user, key: str, target: str | None = None) -> None:
|
||||
"""check() from inside an endpoint (module, device scope, key, manager override)."""
|
||||
from core.access.check import check
|
||||
ctx = context_for(request, user, db)
|
||||
if target:
|
||||
ctx.target = target
|
||||
check(ctx, key, db)
|
||||
|
||||
|
||||
def get_context(request: Request, db: Session = Depends(get_db),
|
||||
credentials: Optional[HTTPAuthorizationCredentials] = Depends(_optional_bearer)) -> AccessContext:
|
||||
"""Device (if any) + user (if a bearer token is sent). An invalid token is an error here:
|
||||
@@ -125,4 +142,6 @@ def get_context(request: Request, db: Session = Depends(get_db),
|
||||
user = sid = None
|
||||
if credentials:
|
||||
user, sid = user_from_token(credentials.credentials, request, db)
|
||||
return AccessContext(user=user, session=sid, device=device)
|
||||
from core.access.override import HEADER
|
||||
return AccessContext(user=user, session=sid, device=device, override_token=request.headers.get(HEADER),
|
||||
target=f"{request.method} {request.url.path}")
|
||||
|
||||
Reference in New Issue
Block a user