Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- api/routes_customers.py +103 -5
- platform/core/route_system.py +58 -0
- web/public/AIOS_DEPLOY_RECEIPT +1 -1
RELEASES.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v82",
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "86a7eedec2 (86a7eedec2ee)",
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v82",
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
86a7eedec2 (86a7eedec2ee)
|
api/routes_customers.py
CHANGED
|
@@ -1374,6 +1374,83 @@ def _ensure_route_migration(session):
|
|
| 1374 |
_ROUTE_MIGRATED_TENANTS.add(tenant)
|
| 1375 |
|
| 1376 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1377 |
def _route_application_body(raw, application):
|
| 1378 |
if "application" in raw and raw["application"] != application:
|
| 1379 |
raise err(400, "route_application_mismatch", "the body must name the same Routing App as the query")
|
|
@@ -1659,7 +1736,7 @@ def routes(session: Session = Depends(module_gate(MODULE)), application: str = N
|
|
| 1659 |
50,000 visible records sends exactly the same request as an empty grid; a future annotation
|
| 1660 |
door may accept a compact saved-View/filter reference without reopening that row-sized wire.
|
| 1661 |
"""
|
| 1662 |
-
application =
|
| 1663 |
allowed = allowed_pids(session)
|
| 1664 |
records = _route_share_records(session)
|
| 1665 |
navigation = _route_navigation(session, _visible_routes(session, records, application), application)
|
|
@@ -1672,7 +1749,7 @@ def routes(session: Session = Depends(module_gate(MODULE)), application: str = N
|
|
| 1672 |
|
| 1673 |
@router.get("/customers/routes/delivery-recipients")
|
| 1674 |
def route_delivery_recipients(session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1675 |
-
|
| 1676 |
return {"people": _route_delivery_people(session)}
|
| 1677 |
|
| 1678 |
|
|
@@ -1687,8 +1764,9 @@ def create_route(body: dict = Body(default=None), session: Session = Depends(mod
|
|
| 1687 |
application: str = None):
|
| 1688 |
from core import route_system
|
| 1689 |
raw = dict(body or {})
|
| 1690 |
-
application =
|
| 1691 |
_route_application_body(raw, application)
|
|
|
|
| 1692 |
_reject_client_create_id(raw, "Route")
|
| 1693 |
source_view = raw.get("sourceViewId", raw.get("source_view_id"))
|
| 1694 |
if source_view and not _route_view_can_edit(session, source_view):
|
|
@@ -1709,7 +1787,7 @@ def create_route(body: dict = Body(default=None), session: Session = Depends(mod
|
|
| 1709 |
def duplicate_route(route_id: str, body: dict = Body(default=None),
|
| 1710 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1711 |
from core import route_system
|
| 1712 |
-
application =
|
| 1713 |
_route_application_body(body or {}, application)
|
| 1714 |
prior = _route_or_404(session, route_id, application)
|
| 1715 |
if prior.get("sourceViewId"):
|
|
@@ -1728,6 +1806,7 @@ def duplicate_route(route_id: str, body: dict = Body(default=None),
|
|
| 1728 |
|
| 1729 |
@router.post("/customers/routes/{route_id}/share-ready")
|
| 1730 |
def route_share_ready(route_id: str, session: Session = Depends(module_gate(MODULE)), application: str = None):
|
|
|
|
| 1731 |
route = _route_or_404(session, route_id, application)
|
| 1732 |
_route_mutation_allowed(session, route)
|
| 1733 |
key = _ensure_route_share_bridge(session, route)
|
|
@@ -1738,9 +1817,11 @@ def route_share_ready(route_id: str, session: Session = Depends(module_gate(MODU
|
|
| 1738 |
def update_route(route_id: str, body: dict = Body(default=None),
|
| 1739 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1740 |
from core import route_system
|
|
|
|
| 1741 |
prior = _route_or_404(session, route_id, application)
|
| 1742 |
raw = dict(body or {})
|
| 1743 |
_route_application_body(raw, application)
|
|
|
|
| 1744 |
_route_mutation_allowed(session, prior, raw.get("sourceViewId", prior.get("sourceViewId")))
|
| 1745 |
raw["id"] = prior["id"]
|
| 1746 |
if "stops" in raw and any(pid not in allowed_pids(session) for pid in _route_input_pids(raw)):
|
|
@@ -1758,6 +1839,7 @@ def update_route(route_id: str, body: dict = Body(default=None),
|
|
| 1758 |
def move_route_stop(route_id: str, body: dict = Body(default=None),
|
| 1759 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1760 |
from core import route_system
|
|
|
|
| 1761 |
prior = _route_or_404(session, route_id, application)
|
| 1762 |
_route_mutation_allowed(session, prior)
|
| 1763 |
raw = dict(body or {})
|
|
@@ -1782,6 +1864,7 @@ def set_route_stop_membership(route_id: str, body: dict = Body(default=None),
|
|
| 1782 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1783 |
"""Add or remove one permitted customer while preserving every other ordered stop."""
|
| 1784 |
from core import route_system
|
|
|
|
| 1785 |
prior = _route_or_404(session, route_id, application)
|
| 1786 |
_route_mutation_allowed(session, prior)
|
| 1787 |
raw = dict(body or {})
|
|
@@ -1810,6 +1893,7 @@ def set_route_stop_membership(route_id: str, body: dict = Body(default=None),
|
|
| 1810 |
@router.delete("/customers/routes/{route_id}")
|
| 1811 |
def remove_route(route_id: str, session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1812 |
from core import route_system
|
|
|
|
| 1813 |
route = _route_or_404(session, route_id, application)
|
| 1814 |
_route_mutation_allowed(session, route)
|
| 1815 |
linked_delivery_ids = _linked_route_delivery_ids(session.runtime, route_id)
|
|
@@ -1835,6 +1919,7 @@ def remove_route(route_id: str, session: Session = Depends(module_gate(MODULE)),
|
|
| 1835 |
def move_route_to_folder(route_id: str, body: dict = Body(default=None),
|
| 1836 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1837 |
from core import route_system
|
|
|
|
| 1838 |
_route_application_body(body or {}, application)
|
| 1839 |
routes, legacy_folders, legacy_placements = _route_nav_mutation_context(session, **_route_scope(application))
|
| 1840 |
if str(route_id) not in {str(route.get("id")) for route in routes}:
|
|
@@ -1857,6 +1942,7 @@ def move_route_to_folder(route_id: str, body: dict = Body(default=None),
|
|
| 1857 |
def reorder_route_navigation(body: dict = Body(default=None),
|
| 1858 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1859 |
from core import route_system
|
|
|
|
| 1860 |
_route_application_body(body or {}, application)
|
| 1861 |
routes, legacy_folders, legacy_placements = _route_nav_mutation_context(session, **_route_scope(application))
|
| 1862 |
order = (body or {}).get("order")
|
|
@@ -1874,6 +1960,7 @@ def reorder_route_navigation(body: dict = Body(default=None),
|
|
| 1874 |
def create_route_folder(body: dict = Body(default=None),
|
| 1875 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1876 |
from core import route_system
|
|
|
|
| 1877 |
_route_application_body(body or {}, application)
|
| 1878 |
_reject_client_create_id(body or {}, "Route folder")
|
| 1879 |
routes, legacy_folders, legacy_placements = _route_nav_mutation_context(session, **_route_scope(application))
|
|
@@ -1889,6 +1976,7 @@ def create_route_folder(body: dict = Body(default=None),
|
|
| 1889 |
def update_route_folder(folder_id: str, body: dict = Body(default=None),
|
| 1890 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1891 |
from core import route_system
|
|
|
|
| 1892 |
_route_application_body(body or {}, application)
|
| 1893 |
routes, legacy_folders, legacy_placements = _route_nav_mutation_context(session, **_route_scope(application))
|
| 1894 |
current = next((folder for folder in _route_navigation(session, routes, **_route_scope(application))["folders"]
|
|
@@ -1909,6 +1997,7 @@ def update_route_folder(folder_id: str, body: dict = Body(default=None),
|
|
| 1909 |
@router.delete("/customers/route-folders/{folder_id}")
|
| 1910 |
def remove_route_folder(folder_id: str, session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1911 |
from core import route_system
|
|
|
|
| 1912 |
routes, legacy_folders, legacy_placements = _route_nav_mutation_context(session, **_route_scope(application))
|
| 1913 |
if not route_system.delete_route_folder(
|
| 1914 |
session.runtime, session.uname, folder_id, routes,
|
|
@@ -1921,6 +2010,7 @@ def remove_route_folder(folder_id: str, session: Session = Depends(module_gate(M
|
|
| 1921 |
def reorder_route_folder_navigation(body: dict = Body(default=None),
|
| 1922 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1923 |
from core import route_system
|
|
|
|
| 1924 |
_route_application_body(body or {}, application)
|
| 1925 |
routes, legacy_folders, legacy_placements = _route_nav_mutation_context(session, **_route_scope(application))
|
| 1926 |
order = (body or {}).get("order")
|
|
@@ -1940,7 +2030,7 @@ def route_selection(body: dict = Body(default=None), session: Session = Depends(
|
|
| 1940 |
"""Dedicated managed-OR mutation; user filter clauses are returned byte-for-byte intact."""
|
| 1941 |
from core import route_system
|
| 1942 |
raw = dict(body or {})
|
| 1943 |
-
application =
|
| 1944 |
_route_application_body(raw, application)
|
| 1945 |
chosen = [str(item) for item in raw.get("routeIds") or ()]
|
| 1946 |
compatible = _visible_routes(session, application=application)
|
|
@@ -2190,6 +2280,8 @@ def patch_customer(pid: int, body: dict = Body(default=None),
|
|
| 2190 |
# refused key or a truncated value must not be reported as accepted.
|
| 2191 |
stored = (grid_events.table_workspace(_ctx_for(session, pool), allowed_pids=None)
|
| 2192 |
.get("overlays") or {}).get(str(pid)) or {}
|
|
|
|
|
|
|
| 2193 |
accepted = {k: stored.get(k) for k in updates if k in stored}
|
| 2194 |
refused = sorted(k for k in updates if k not in accepted or stored.get(k) != str(updates[k]))
|
| 2195 |
# No cache to patch: the overlay stratum is re-read from the store on every `_payload`, so
|
|
@@ -2446,6 +2538,7 @@ def _linked_route_delivery_ids(runtime, route_id):
|
|
| 2446 |
@router.get("/customers/route-deliveries")
|
| 2447 |
def route_delivery_list(session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 2448 |
"""Saved C2 route deliveries owned by the caller (or all for an administrator)."""
|
|
|
|
| 2449 |
return {"deliveries": _route_delivery_definitions(session, application=application)}
|
| 2450 |
|
| 2451 |
|
|
@@ -2453,6 +2546,7 @@ def route_delivery_list(session: Session = Depends(module_gate(MODULE)), applica
|
|
| 2453 |
def normalized_route_delivery_list(route_id: str,
|
| 2454 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 2455 |
"""Deliveries for the one normalized Route whose detail is open."""
|
|
|
|
| 2456 |
_route_or_404(session, route_id, application)
|
| 2457 |
return {"deliveries": _route_delivery_definitions(session, route_id, application)}
|
| 2458 |
|
|
@@ -2492,6 +2586,7 @@ def _create_route_delivery_for_route(session, route, body):
|
|
| 2492 |
def normalized_route_delivery_create(route_id: str, body: dict = Body(default=None),
|
| 2493 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 2494 |
"""Schedule a named normalized Route from its server-resolved View and stop relation."""
|
|
|
|
| 2495 |
_route_application_body(body or {}, application)
|
| 2496 |
return _create_route_delivery_for_route(
|
| 2497 |
session, _route_or_404(session, route_id, application), body if isinstance(body, dict) else {})
|
|
@@ -2502,6 +2597,7 @@ def route_delivery_create(body: dict = Body(default=None),
|
|
| 2502 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 2503 |
"""Compatibility door: a normalized Route id is still mandatory and server-resolved."""
|
| 2504 |
body = body if isinstance(body, dict) else {}
|
|
|
|
| 2505 |
_route_application_body(body, application)
|
| 2506 |
route_id = str(body.get("routeId") or "").strip()
|
| 2507 |
if not route_id:
|
|
@@ -2538,6 +2634,7 @@ def _delete_route_delivery(session, delivery_id, route_id=None, application=None
|
|
| 2538 |
def normalized_route_delivery_delete(route_id: str, delivery_id: str,
|
| 2539 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 2540 |
"""Remove one delivery from the normalized Route detail that owns it."""
|
|
|
|
| 2541 |
route = _route_or_404(session, route_id, application)
|
| 2542 |
_route_mutation_allowed(session, route)
|
| 2543 |
return _delete_route_delivery(session, delivery_id, route_id, application)
|
|
@@ -2547,4 +2644,5 @@ def normalized_route_delivery_delete(route_id: str, delivery_id: str,
|
|
| 2547 |
def route_delivery_delete(delivery_id: str,
|
| 2548 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 2549 |
"""Compatibility removal for existing schedule links."""
|
|
|
|
| 2550 |
return _delete_route_delivery(session, delivery_id, application=application)
|
|
|
|
| 1374 |
_ROUTE_MIGRATED_TENANTS.add(tenant)
|
| 1375 |
|
| 1376 |
|
| 1377 |
+
#: (tenant, user, Routing App) triples with no no-App Route left to adopt in this process.
|
| 1378 |
+
_ROUTE_ADOPTED_USERS: set = set()
|
| 1379 |
+
|
| 1380 |
+
|
| 1381 |
+
def _home_route_application(session):
|
| 1382 |
+
"""The id of the caller's own Routing App, or None."""
|
| 1383 |
+
import application_registry as registry
|
| 1384 |
+
me = str(getattr(session, "uname", "") or "").strip().lower()
|
| 1385 |
+
if not me:
|
| 1386 |
+
return None
|
| 1387 |
+
try:
|
| 1388 |
+
doc = registry._read_strict(session.runtime, registry._KEY) or {}
|
| 1389 |
+
apps = doc.get("applications", {}) if isinstance(doc, dict) else None
|
| 1390 |
+
if not isinstance(apps, dict):
|
| 1391 |
+
return None
|
| 1392 |
+
candidates = []
|
| 1393 |
+
for app_id, app in apps.items():
|
| 1394 |
+
if (not isinstance(app, dict) or app.get("retired") is True
|
| 1395 |
+
or str(app.get("createdBy") or "").strip().lower() != me
|
| 1396 |
+
or app.get("tenant") != session.tenant
|
| 1397 |
+
or not (app.get("templateKind") == "route"
|
| 1398 |
+
or (app.get("type") == "route" and not app.get("templateKind")))
|
| 1399 |
+
or not registry.may_read(app, session.uname, is_admin=session.admin)):
|
| 1400 |
+
continue
|
| 1401 |
+
source = app.get("sourceDatabase")
|
| 1402 |
+
if source not in (MODULE, "ut_odoo_customers") and MODULE not in (app.get("compatibleDatabases") or ()):
|
| 1403 |
+
continue
|
| 1404 |
+
starred = me in {str(user or "").strip().lower() for user in app.get("starredBy") or ()}
|
| 1405 |
+
candidates.append((not starred, str(app.get("createdAt") or ""), str(app_id)))
|
| 1406 |
+
except Exception:
|
| 1407 |
+
# An unreadable registry falls back to the no-App partition, which still works.
|
| 1408 |
+
return None
|
| 1409 |
+
return min(candidates)[2] if candidates else None
|
| 1410 |
+
|
| 1411 |
+
|
| 1412 |
+
def _adopt_unscoped_routes(session, application):
|
| 1413 |
+
"""Move the caller's post-R20 no-App Routes into their own Routing App, once per process."""
|
| 1414 |
+
from core import route_system
|
| 1415 |
+
key = (str(getattr(session, "tenant", "") or ""), str(session.uname or "").strip().lower(), application)
|
| 1416 |
+
if key in _ROUTE_ADOPTED_USERS:
|
| 1417 |
+
return
|
| 1418 |
+
try:
|
| 1419 |
+
route_system.adopt_unscoped_routes(session.runtime, owner=session.uname, application=application)
|
| 1420 |
+
except Exception:
|
| 1421 |
+
# A failed adoption leaves the Routes where they are and retries on the next request.
|
| 1422 |
+
return
|
| 1423 |
+
_ROUTE_ADOPTED_USERS.add(key)
|
| 1424 |
+
|
| 1425 |
+
|
| 1426 |
+
def _entry_route_application(session, application, *, write=False):
|
| 1427 |
+
"""A Route request that names no Routing App uses the caller's own one, when they have one."""
|
| 1428 |
+
if application is not None:
|
| 1429 |
+
return _route_application(session, application, write=write)
|
| 1430 |
+
home = _home_route_application(session)
|
| 1431 |
+
if home is None:
|
| 1432 |
+
return _route_application(session, None, write=write)
|
| 1433 |
+
resolved = _route_application(session, home, write=write)
|
| 1434 |
+
_adopt_unscoped_routes(session, resolved)
|
| 1435 |
+
return resolved
|
| 1436 |
+
|
| 1437 |
+
|
| 1438 |
+
def _entry_route_zone(session, raw, requested, application):
|
| 1439 |
+
"""A no-App request may name a legacy Zone id. Map it to that Zone's R20 copy in the home App."""
|
| 1440 |
+
from core import route_system
|
| 1441 |
+
key = "zoneId" if "zoneId" in raw else "zone_id" if "zone_id" in raw else None
|
| 1442 |
+
wanted = str(raw.get(key) or "").strip() if key else ""
|
| 1443 |
+
if requested is not None or application is None or not wanted:
|
| 1444 |
+
return raw
|
| 1445 |
+
if wanted in route_system.zone_ids(session.runtime, table_key=route_system.DEFAULT_ZONE_TABLE,
|
| 1446 |
+
application=application):
|
| 1447 |
+
return raw
|
| 1448 |
+
receipt = route_system.read(session.runtime).get(route_system.APPLICATION_MIGRATION) or {}
|
| 1449 |
+
zones = ((receipt.get("applications") or {}).get(application) or {}).get("zones") or {}
|
| 1450 |
+
mapped = zones.get(f"{route_system.DEFAULT_ZONE_TABLE}:{wanted}")
|
| 1451 |
+
return dict(raw, **{key: mapped}) if mapped else raw
|
| 1452 |
+
|
| 1453 |
+
|
| 1454 |
def _route_application_body(raw, application):
|
| 1455 |
if "application" in raw and raw["application"] != application:
|
| 1456 |
raise err(400, "route_application_mismatch", "the body must name the same Routing App as the query")
|
|
|
|
| 1736 |
50,000 visible records sends exactly the same request as an empty grid; a future annotation
|
| 1737 |
door may accept a compact saved-View/filter reference without reopening that row-sized wire.
|
| 1738 |
"""
|
| 1739 |
+
application = _entry_route_application(session, application)
|
| 1740 |
allowed = allowed_pids(session)
|
| 1741 |
records = _route_share_records(session)
|
| 1742 |
navigation = _route_navigation(session, _visible_routes(session, records, application), application)
|
|
|
|
| 1749 |
|
| 1750 |
@router.get("/customers/routes/delivery-recipients")
|
| 1751 |
def route_delivery_recipients(session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1752 |
+
_entry_route_application(session, application)
|
| 1753 |
return {"people": _route_delivery_people(session)}
|
| 1754 |
|
| 1755 |
|
|
|
|
| 1764 |
application: str = None):
|
| 1765 |
from core import route_system
|
| 1766 |
raw = dict(body or {})
|
| 1767 |
+
requested, application = application, _entry_route_application(session, application, write=True)
|
| 1768 |
_route_application_body(raw, application)
|
| 1769 |
+
raw = _entry_route_zone(session, raw, requested, application)
|
| 1770 |
_reject_client_create_id(raw, "Route")
|
| 1771 |
source_view = raw.get("sourceViewId", raw.get("source_view_id"))
|
| 1772 |
if source_view and not _route_view_can_edit(session, source_view):
|
|
|
|
| 1787 |
def duplicate_route(route_id: str, body: dict = Body(default=None),
|
| 1788 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1789 |
from core import route_system
|
| 1790 |
+
application = _entry_route_application(session, application, write=True)
|
| 1791 |
_route_application_body(body or {}, application)
|
| 1792 |
prior = _route_or_404(session, route_id, application)
|
| 1793 |
if prior.get("sourceViewId"):
|
|
|
|
| 1806 |
|
| 1807 |
@router.post("/customers/routes/{route_id}/share-ready")
|
| 1808 |
def route_share_ready(route_id: str, session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1809 |
+
application = _entry_route_application(session, application)
|
| 1810 |
route = _route_or_404(session, route_id, application)
|
| 1811 |
_route_mutation_allowed(session, route)
|
| 1812 |
key = _ensure_route_share_bridge(session, route)
|
|
|
|
| 1817 |
def update_route(route_id: str, body: dict = Body(default=None),
|
| 1818 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1819 |
from core import route_system
|
| 1820 |
+
requested, application = application, _entry_route_application(session, application, write=True)
|
| 1821 |
prior = _route_or_404(session, route_id, application)
|
| 1822 |
raw = dict(body or {})
|
| 1823 |
_route_application_body(raw, application)
|
| 1824 |
+
raw = _entry_route_zone(session, raw, requested, application)
|
| 1825 |
_route_mutation_allowed(session, prior, raw.get("sourceViewId", prior.get("sourceViewId")))
|
| 1826 |
raw["id"] = prior["id"]
|
| 1827 |
if "stops" in raw and any(pid not in allowed_pids(session) for pid in _route_input_pids(raw)):
|
|
|
|
| 1839 |
def move_route_stop(route_id: str, body: dict = Body(default=None),
|
| 1840 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1841 |
from core import route_system
|
| 1842 |
+
application = _entry_route_application(session, application, write=True)
|
| 1843 |
prior = _route_or_404(session, route_id, application)
|
| 1844 |
_route_mutation_allowed(session, prior)
|
| 1845 |
raw = dict(body or {})
|
|
|
|
| 1864 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1865 |
"""Add or remove one permitted customer while preserving every other ordered stop."""
|
| 1866 |
from core import route_system
|
| 1867 |
+
application = _entry_route_application(session, application, write=True)
|
| 1868 |
prior = _route_or_404(session, route_id, application)
|
| 1869 |
_route_mutation_allowed(session, prior)
|
| 1870 |
raw = dict(body or {})
|
|
|
|
| 1893 |
@router.delete("/customers/routes/{route_id}")
|
| 1894 |
def remove_route(route_id: str, session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1895 |
from core import route_system
|
| 1896 |
+
application = _entry_route_application(session, application, write=True)
|
| 1897 |
route = _route_or_404(session, route_id, application)
|
| 1898 |
_route_mutation_allowed(session, route)
|
| 1899 |
linked_delivery_ids = _linked_route_delivery_ids(session.runtime, route_id)
|
|
|
|
| 1919 |
def move_route_to_folder(route_id: str, body: dict = Body(default=None),
|
| 1920 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1921 |
from core import route_system
|
| 1922 |
+
application = _entry_route_application(session, application, write=True)
|
| 1923 |
_route_application_body(body or {}, application)
|
| 1924 |
routes, legacy_folders, legacy_placements = _route_nav_mutation_context(session, **_route_scope(application))
|
| 1925 |
if str(route_id) not in {str(route.get("id")) for route in routes}:
|
|
|
|
| 1942 |
def reorder_route_navigation(body: dict = Body(default=None),
|
| 1943 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1944 |
from core import route_system
|
| 1945 |
+
application = _entry_route_application(session, application, write=True)
|
| 1946 |
_route_application_body(body or {}, application)
|
| 1947 |
routes, legacy_folders, legacy_placements = _route_nav_mutation_context(session, **_route_scope(application))
|
| 1948 |
order = (body or {}).get("order")
|
|
|
|
| 1960 |
def create_route_folder(body: dict = Body(default=None),
|
| 1961 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1962 |
from core import route_system
|
| 1963 |
+
application = _entry_route_application(session, application, write=True)
|
| 1964 |
_route_application_body(body or {}, application)
|
| 1965 |
_reject_client_create_id(body or {}, "Route folder")
|
| 1966 |
routes, legacy_folders, legacy_placements = _route_nav_mutation_context(session, **_route_scope(application))
|
|
|
|
| 1976 |
def update_route_folder(folder_id: str, body: dict = Body(default=None),
|
| 1977 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1978 |
from core import route_system
|
| 1979 |
+
application = _entry_route_application(session, application, write=True)
|
| 1980 |
_route_application_body(body or {}, application)
|
| 1981 |
routes, legacy_folders, legacy_placements = _route_nav_mutation_context(session, **_route_scope(application))
|
| 1982 |
current = next((folder for folder in _route_navigation(session, routes, **_route_scope(application))["folders"]
|
|
|
|
| 1997 |
@router.delete("/customers/route-folders/{folder_id}")
|
| 1998 |
def remove_route_folder(folder_id: str, session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 1999 |
from core import route_system
|
| 2000 |
+
application = _entry_route_application(session, application, write=True)
|
| 2001 |
routes, legacy_folders, legacy_placements = _route_nav_mutation_context(session, **_route_scope(application))
|
| 2002 |
if not route_system.delete_route_folder(
|
| 2003 |
session.runtime, session.uname, folder_id, routes,
|
|
|
|
| 2010 |
def reorder_route_folder_navigation(body: dict = Body(default=None),
|
| 2011 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 2012 |
from core import route_system
|
| 2013 |
+
application = _entry_route_application(session, application, write=True)
|
| 2014 |
_route_application_body(body or {}, application)
|
| 2015 |
routes, legacy_folders, legacy_placements = _route_nav_mutation_context(session, **_route_scope(application))
|
| 2016 |
order = (body or {}).get("order")
|
|
|
|
| 2030 |
"""Dedicated managed-OR mutation; user filter clauses are returned byte-for-byte intact."""
|
| 2031 |
from core import route_system
|
| 2032 |
raw = dict(body or {})
|
| 2033 |
+
application = _entry_route_application(session, application)
|
| 2034 |
_route_application_body(raw, application)
|
| 2035 |
chosen = [str(item) for item in raw.get("routeIds") or ()]
|
| 2036 |
compatible = _visible_routes(session, application=application)
|
|
|
|
| 2280 |
# refused key or a truncated value must not be reported as accepted.
|
| 2281 |
stored = (grid_events.table_workspace(_ctx_for(session, pool), allowed_pids=None)
|
| 2282 |
.get("overlays") or {}).get(str(pid)) or {}
|
| 2283 |
+
# A tenant-wide column saves to the shared stratum, so read it back from there too.
|
| 2284 |
+
stored = {**stored, **(shared_cells([pid], st=session.runtime).get(str(pid)) or {})}
|
| 2285 |
accepted = {k: stored.get(k) for k in updates if k in stored}
|
| 2286 |
refused = sorted(k for k in updates if k not in accepted or stored.get(k) != str(updates[k]))
|
| 2287 |
# No cache to patch: the overlay stratum is re-read from the store on every `_payload`, so
|
|
|
|
| 2538 |
@router.get("/customers/route-deliveries")
|
| 2539 |
def route_delivery_list(session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 2540 |
"""Saved C2 route deliveries owned by the caller (or all for an administrator)."""
|
| 2541 |
+
application = _entry_route_application(session, application)
|
| 2542 |
return {"deliveries": _route_delivery_definitions(session, application=application)}
|
| 2543 |
|
| 2544 |
|
|
|
|
| 2546 |
def normalized_route_delivery_list(route_id: str,
|
| 2547 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 2548 |
"""Deliveries for the one normalized Route whose detail is open."""
|
| 2549 |
+
application = _entry_route_application(session, application)
|
| 2550 |
_route_or_404(session, route_id, application)
|
| 2551 |
return {"deliveries": _route_delivery_definitions(session, route_id, application)}
|
| 2552 |
|
|
|
|
| 2586 |
def normalized_route_delivery_create(route_id: str, body: dict = Body(default=None),
|
| 2587 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 2588 |
"""Schedule a named normalized Route from its server-resolved View and stop relation."""
|
| 2589 |
+
application = _entry_route_application(session, application, write=True)
|
| 2590 |
_route_application_body(body or {}, application)
|
| 2591 |
return _create_route_delivery_for_route(
|
| 2592 |
session, _route_or_404(session, route_id, application), body if isinstance(body, dict) else {})
|
|
|
|
| 2597 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 2598 |
"""Compatibility door: a normalized Route id is still mandatory and server-resolved."""
|
| 2599 |
body = body if isinstance(body, dict) else {}
|
| 2600 |
+
application = _entry_route_application(session, application, write=True)
|
| 2601 |
_route_application_body(body, application)
|
| 2602 |
route_id = str(body.get("routeId") or "").strip()
|
| 2603 |
if not route_id:
|
|
|
|
| 2634 |
def normalized_route_delivery_delete(route_id: str, delivery_id: str,
|
| 2635 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 2636 |
"""Remove one delivery from the normalized Route detail that owns it."""
|
| 2637 |
+
application = _entry_route_application(session, application, write=True)
|
| 2638 |
route = _route_or_404(session, route_id, application)
|
| 2639 |
_route_mutation_allowed(session, route)
|
| 2640 |
return _delete_route_delivery(session, delivery_id, route_id, application)
|
|
|
|
| 2644 |
def route_delivery_delete(delivery_id: str,
|
| 2645 |
session: Session = Depends(module_gate(MODULE)), application: str = None):
|
| 2646 |
"""Compatibility removal for existing schedule links."""
|
| 2647 |
+
application = _entry_route_application(session, application, write=True)
|
| 2648 |
return _delete_route_delivery(session, delivery_id, application=application)
|
platform/core/route_system.py
CHANGED
|
@@ -553,6 +553,64 @@ def migrate_application_routes(st, applications, *, legacy_navigation=None):
|
|
| 553 |
return _persist(st, mutate)
|
| 554 |
|
| 555 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 556 |
def route_share_key(route_id):
|
| 557 |
"""Stable generic-field bridge id for the existing share registry.
|
| 558 |
|
|
|
|
| 553 |
return _persist(st, mutate)
|
| 554 |
|
| 555 |
|
| 556 |
+
def adopt_unscoped_routes(st, *, owner, application):
|
| 557 |
+
"""Move one owner's no-App Routes made after the R20 receipt into that owner's Routing App.
|
| 558 |
+
|
| 559 |
+
A moved Route keeps its id, stops, number, createdAt and createdBy. Returns the moved ids.
|
| 560 |
+
"""
|
| 561 |
+
owner = str(owner or "").strip().lower()
|
| 562 |
+
application = _application(application)
|
| 563 |
+
|
| 564 |
+
def when(value):
|
| 565 |
+
try:
|
| 566 |
+
stamp = _dt.datetime.fromisoformat(str(value or ""))
|
| 567 |
+
except (TypeError, ValueError):
|
| 568 |
+
return None
|
| 569 |
+
return stamp if stamp.tzinfo else stamp.replace(tzinfo=_dt.timezone.utc)
|
| 570 |
+
|
| 571 |
+
def signature(route):
|
| 572 |
+
return (str(route.get("createdBy") or "").strip().lower(), _name(route.get("name")),
|
| 573 |
+
tuple(_pid(stop.get("customerPid")) for stop in ordered_stops(route)))
|
| 574 |
+
|
| 575 |
+
def plan(state):
|
| 576 |
+
receipt = state.get(APPLICATION_MIGRATION)
|
| 577 |
+
cutoff = when(receipt.get("at")) if isinstance(receipt, dict) else None
|
| 578 |
+
if not owner or application is None or cutoff is None:
|
| 579 |
+
return []
|
| 580 |
+
taken = {signature(item) for item in state.get("routes") or [] if _in_application(item, application)}
|
| 581 |
+
moving = []
|
| 582 |
+
for index, item in enumerate(state.get("routes") or []):
|
| 583 |
+
if not _in_application(item, None) or str(item.get("createdBy") or "").strip().lower() != owner:
|
| 584 |
+
continue
|
| 585 |
+
made = when(item.get("createdAt"))
|
| 586 |
+
# A Route made before the receipt already has its R20 copy, and an identical one is a duplicate.
|
| 587 |
+
if made is None or made <= cutoff or signature(item) in taken:
|
| 588 |
+
continue
|
| 589 |
+
taken.add(signature(item))
|
| 590 |
+
moving.append(index)
|
| 591 |
+
return moving
|
| 592 |
+
|
| 593 |
+
# The read-only plan keeps the common request from writing the Route document.
|
| 594 |
+
if not plan(_store(st)):
|
| 595 |
+
return []
|
| 596 |
+
|
| 597 |
+
def mutate(state):
|
| 598 |
+
zones = (((state.get(APPLICATION_MIGRATION) or {}).get("applications") or {})
|
| 599 |
+
.get(application) or {}).get("zones") or {}
|
| 600 |
+
moved = []
|
| 601 |
+
for index in plan(state):
|
| 602 |
+
route = dict(state["routes"][index])
|
| 603 |
+
route.update(application=application, shareKey=route_share_key(route.get("id")),
|
| 604 |
+
zoneId=zones.get(f"{DEFAULT_ZONE_TABLE}:{route.get('zoneId')}"))
|
| 605 |
+
state["routes"][index] = route
|
| 606 |
+
moved.append(str(route.get("id")))
|
| 607 |
+
if moved:
|
| 608 |
+
_reconcile_inbox_state(state, _inbox_day(None, st=st))
|
| 609 |
+
return state, moved
|
| 610 |
+
|
| 611 |
+
return _persist(st, mutate) or []
|
| 612 |
+
|
| 613 |
+
|
| 614 |
def route_share_key(route_id):
|
| 615 |
"""Stable generic-field bridge id for the existing share registry.
|
| 616 |
|
web/public/AIOS_DEPLOY_RECEIPT
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
3b0027376beea356cfc814bf8fa6024cdc5aff0f3e282dcbe1da9a8f1cfed6e2
|