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:
@@ -0,0 +1,30 @@
|
||||
"""Manager overrides (APPS_PLATFORM D-10, plan step 1.9): audit + single-use tokens.
|
||||
|
||||
A user who lacks an overridable permission gets `access.override_possible`; a manager
|
||||
types their username + PIN on the same screen (POST /api/access/override) and the client
|
||||
retries with header X-Xenia-Override. One row per approval: who asked (user + session),
|
||||
who approved, which key, when it was used and on what (`target`). The token is valid for
|
||||
60 s, once, for that key and that session only; only its sha256 is stored.
|
||||
Written through core/access/override.py only. Rows are never deleted (audit).
|
||||
"""
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String
|
||||
|
||||
from core.timeutil import UTCDateTime, utcnow
|
||||
from database import Base
|
||||
|
||||
|
||||
class AccessOverride(Base):
|
||||
__tablename__ = "access_overrides"
|
||||
__table_args__ = {"sqlite_autoincrement": True}
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
key = Column(String, nullable=False, index=True)
|
||||
token_hash = Column(String, nullable=False, unique=True)
|
||||
requested_by = Column(Integer, ForeignKey("users.id", ondelete="SET NULL"), nullable=True)
|
||||
requested_session = Column(String, nullable=True) # sessions.id the token is bound to
|
||||
approved_by = Column(Integer, ForeignKey("users.id", ondelete="SET NULL"), nullable=True)
|
||||
device_id = Column(Integer, ForeignKey("devices.id", ondelete="SET NULL"), nullable=True)
|
||||
created_at = Column(UTCDateTime, nullable=False, default=utcnow, index=True)
|
||||
expires_at = Column(UTCDateTime, nullable=False)
|
||||
used_at = Column(UTCDateTime, nullable=True)
|
||||
target = Column(String, nullable=True) # e.g. "order:12", or "DELETE /api/x/3"
|
||||
@@ -31,3 +31,4 @@ import models.site_module # noqa: F401 SiteModule (module enablement, step 1.3
|
||||
import models.user_permission # noqa: F401 UserPermission (permission keys, step 1.5)
|
||||
import models.session # noqa: F401 LoginSession (step 1.6)
|
||||
import models.device # noqa: F401 Device, DevicePairRequest (step 1.8)
|
||||
import models.access_override # noqa: F401 AccessOverride (manager override, step 1.9)
|
||||
|
||||
Reference in New Issue
Block a user