diff --git a/cloud_backend/models/site.py b/cloud_backend/models/site.py index 19f59c5..ca6514d 100644 --- a/cloud_backend/models/site.py +++ b/cloud_backend/models/site.py @@ -41,3 +41,10 @@ class Site(Base): # What the site reported it can run (heartbeat `module_catalog`, D-20): drives the editor. module_catalog = Column(JSON, nullable=True) module_catalog_at = Column(DateTime(timezone=True), nullable=True) + + @property + def apps_url(self) -> str | None: + """Where customers open this cloud's apps (PUBLIC_APPS_URL; phase 3S): the sysadmin's + menu and ordering links are built from it. Not stored per site.""" + from config import settings + return settings.PUBLIC_APPS_URL.rstrip("/") or None diff --git a/cloud_backend/schemas/site.py b/cloud_backend/schemas/site.py index 300686f..7c923ca 100644 --- a/cloud_backend/schemas/site.py +++ b/cloud_backend/schemas/site.py @@ -56,6 +56,7 @@ class SiteOut(BaseModel): menu_blurb_gr: str | None menu_hours: str | None menu_header_image_url: str | None + apps_url: str | None = None # PUBLIC_APPS_URL: the customer apps' address (phase 3S) model_config = {"from_attributes": True} diff --git a/cloud_backend/tests/test_qr.py b/cloud_backend/tests/test_qr.py index 0000070..a739cc3 100644 --- a/cloud_backend/tests/test_qr.py +++ b/cloud_backend/tests/test_qr.py @@ -60,3 +60,11 @@ def test_read_only_menus_take_no_table_orders(client, admin_h): r = client.put(f"/api/sites/{site['site_id']}", headers=admin_h, json={"menu_mode": "view_only"}) assert r.status_code == 200, r.text assert _code(_order(client, site, "dine_in", table_token="tok-five", items=[{"product_id": PIE, "quantity": 1}])) == "order.service_unavailable" + + +def test_the_sysadmin_gets_the_apps_address(client, admin_h, monkeypatch): + from config import settings + site, _ = _venue(client, admin_h) + monkeypatch.setattr(settings, "PUBLIC_APPS_URL", "https://menu.example.com/") + got = client.get(f"/api/sites/{site['site_id']}", headers=admin_h).json() + assert got["apps_url"] == "https://menu.example.com" diff --git a/docs/README.md b/docs/README.md index 5170a3c..4d3b4d4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -14,7 +14,7 @@ This folder is its **own git repo**, nested inside the `xenia-pos` parent repo. |---|---|---|---| | `cloud_backend` | FastAPI + SQLAlchemy + SQLite (`${BACKEND_DATA}`) | 8001 | local sites (heartbeat/sync), sysadmin, connect apps | | `sysadmin_panel` | React + Vite (`VITE_CLOUD_URL` baked in at build) | 5175 | the developer only | -| `connect_frontend` | nginx serving three SPAs: `menu-app` at `/menu/` (QR menu), `order-app` at `/order/` (online ordering: takeaway, delivery; phase 3S), `manager-app` at `/manage/` | 3100 | restaurant customers, remote managers | +| `connect_frontend` | nginx serving three SPAs: `menu-app` at `/menu/` (the QR menu: read, or order at a table with its QR code), `order-app` at `/order/` (online ordering: takeaway, delivery, table bookings; phase 3S), `manager-app` at `/manage/`. Public address = `PUBLIC_APPS_URL` (cloud `.env`), sent to sites with the heartbeat | 3100 | restaurant customers, remote managers | TLS and domains are handled in front of these ports on the VPS (`xenia-api.bonamin.net` → cloud_backend, `xenia-admin.bonamin.net` → sysadmin panel, `registry.bonamin.net` → image registry). @@ -25,8 +25,8 @@ TLS and domains are handled in front of these ports on the VPS (`xenia-api.bonam | `/api/auth` | `auth.py` | admin login | sysadmin panel | | `/api/sites` | `sites.py` | admin bearer | sysadmin panel | | `/api/heartbeat` | `heartbeat.py` | `X-Site-ID` + `X-Site-Key` | local sites | -| `/api/menu` | `menu.py` | public GET; site headers for sync | menu-app, local sites | -| `/api/orders` | `orders.py` | public create/quote/slots/track (priced by `services/checkout.py`, fees `services/fees.py`, hours and slots `services/ordering.py`, rate-limited `services/ratelimit.py`; never the browser's numbers); site headers for pending/synced/status (own site only) | menu-app, order-app, local sites | +| `/api/menu` | `menu.py` | public GET (`?t=` a table's QR token → `table`; the snapshot's `fees` and `qr` never leave the cloud); site headers for sync | menu-app, order-app, local sites | +| `/api/orders` | `orders.py` | public create/quote/slots/track (priced by `services/checkout.py`, fees `services/fees.py`, hours and slots `services/ordering.py` (bookings: `res_*`, `/reservation-slots`), table codes `services/qr.py`, rate-limited `services/ratelimit.py`; never the browser's numbers); site headers for pending/synced/status (own site only) | menu-app, order-app, local sites | | `/api/manager` | `manager_auth.py` | manager bearer | manager-app, sysadmin | | `/api/remote` | `remote_dashboard.py` | manager bearer; site headers for `POST /snapshot` | manager-app, local sites | @@ -56,6 +56,10 @@ If the cloud is down, restaurants must keep taking orders (global Rule 8). Don't **CL-6. The license signing key is permanent.** `LICENSE_SIGNING_KEY` (cloud `.env`) signs every site's license. Its public half is built into the site code. Never regenerate or lose it: a new key means every site needs a new image. Keep the backup at `%USERPROFILE%\.xenia\license_signing_key.txt` safe. Never add fields to the token payload that old sites would misread; bump `v` for incompatible changes. +**CL-9. Rate limits live in the process.** `services/ratelimit.py` counts per caller address in memory: right for the one uvicorn process the image runs. If the cloud ever runs several workers or replicas, move the counters to a shared store first, or each worker allows the full rate. + +**CL-10. Table QR tokens are the site's secret.** The cloud only receives their sha256 (`qr.tables[].token_hash`) and compares in constant time (`services/qr.py`). Never store or log a token the cloud receives, and never return `qr` from a public endpoint. + **CL-8. The fee engine has two copies.** `cloud_backend/services/fees.py` is byte-identical to the site's `local_backend/services/fees.py` (the cloud charges what the manager's "test an order" shows). Change both, and `tests/fixtures/fee_cases.json` in both repos; the site's `tests/test_fees.py` compares them. **CL-5. Frontend URLs are baked in at build time.** diff --git a/sysadmin_panel/src/pages/SiteDetailPage.jsx b/sysadmin_panel/src/pages/SiteDetailPage.jsx index 890f759..6db93d0 100644 --- a/sysadmin_panel/src/pages/SiteDetailPage.jsx +++ b/sysadmin_panel/src/pages/SiteDetailPage.jsx @@ -466,9 +466,12 @@ export default function SiteDetailPage() { {/* QR Codes */} {(() => { + // the customer apps' address comes from the cloud (PUBLIC_APPS_URL, phase 3S); the + // tables' own QR codes (ordering at a table) are printed by the venue's manager const slug = site.site_id - const menuUrl = `http://72.61.191.197:3100/menu/${slug}` - const orderUrl = `http://72.61.191.197:3100/menu/${slug}/order` + const base = site.apps_url || import.meta.env.VITE_CLOUD_URL || window.location.origin + const menuUrl = `${base}/menu/${slug}` + const orderUrl = `${base}/order/${slug}` function handleDownload(canvasId, filename) { const canvas = document.getElementById(canvasId) @@ -482,11 +485,12 @@ export default function SiteDetailPage() { return (
-

QR Codes

+

QR Codes

+

{site.apps_url ? '' : 'PUBLIC_APPS_URL is not set on the cloud: these links use the API address. '}Table codes (ordering at a table) are printed by the venue: manager → Table QR codes.

{[ - { id: `qr-menu-${site.id}`, url: menuUrl, label: 'Menu QR Code', file: `menu-qr-${slug}.png` }, - { id: `qr-order-${site.id}`, url: orderUrl, label: 'Order QR Code', file: `order-qr-${slug}.png` }, + { id: `qr-menu-${site.id}`, url: menuUrl, label: 'QR menu (to read)', file: `menu-qr-${slug}.png` }, + { id: `qr-order-${site.id}`, url: orderUrl, label: 'Online ordering (takeaway, delivery, bookings)', file: `order-qr-${slug}.png` }, ].map(({ id, url, label, file }) => (

{label}