Deploy AIOS web (React glide grid + FastAPI slice)
Browse filesThis view is limited to 50 files because it contains too many changes. Β See raw diff
- RELEASES.json +1 -1
- VERSION +1 -1
- api/main.py +15 -1
- api/odoo_relational.py +479 -27
- api/routes_grid.py +163 -24
- api/routes_keychain.py +286 -40
- api/routes_nav.py +116 -0
- api/routes_odoo_tables.py +250 -24
- api/routes_sheet.py +245 -27
- platform/core/keychain.py +329 -38
- platform/core/perm_scope.py +318 -0
- platform/core/relations.py +356 -49
- platform/core/sheets.py +275 -35
- platform/core/table_store.py +31 -3
- platform/harness/runtime.py +54 -17
- platform/odoo_client.py +21 -5
- web/src/connectors/ConnectorsPage.tsx +72 -173
- web/src/customer-grid/CustomerGrid.tsx +19 -0
- web/src/customer-grid/RecordDetail.css +159 -0
- web/src/customer-grid/RecordDetail.tsx +241 -43
- web/src/customer-grid/RecordRail.tsx +34 -3
- web/src/customer-grid/RouteNav.tsx +44 -2
- web/src/customer-grid/Toolbar.tsx +112 -0
- web/src/customer-grid/ViewSidebar.tsx +19 -1
- web/src/customer-grid/iconShapes.ts +47 -10
- web/src/customer-grid/types.ts +105 -3
- web/src/filter-kit/FilterBuilderPanel.tsx +37 -4
- web/src/filter-kit/SheetFilterPopup.tsx +134 -11
- web/src/settings/PermsEditor.tsx +156 -6
- web/src/settings/settingsApi.ts +61 -0
- web/src/sheet/BindingEditor.tsx +721 -372
- web/src/sheet/ChartDialog.tsx +593 -0
- web/src/sheet/DrillModal.tsx +554 -14
- web/src/sheet/KeyTips.tsx +61 -1
- web/src/sheet/LinkDialog.tsx +521 -0
- web/src/sheet/Ribbon.tsx +212 -697
- web/src/sheet/RulesDialog.tsx +101 -12
- web/src/sheet/SheetChart.tsx +773 -11
- web/src/sheet/SheetGrid.tsx +0 -0
- web/src/sheet/SheetPage.tsx +283 -14
- web/src/sheet/bindingRefs.ts +197 -0
- web/src/sheet/cellBorders.ts +114 -0
- web/src/sheet/cellStyleOps.ts +170 -0
- web/src/sheet/clipboardOps.ts +207 -0
- web/src/sheet/formulaEval.ts +364 -21
- web/src/sheet/ribbonHome.tsx +1226 -0
- web/src/sheet/ribbonInsert.tsx +649 -0
- web/src/sheet/rules.ts +321 -10
- web/src/sheet/sheetApi.ts +45 -0
- web/src/sheet/sheetState.ts +406 -171
RELEASES.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v71",
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "463db38",
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v71",
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
463db38
|
api/main.py
CHANGED
|
@@ -926,7 +926,21 @@ def _rebuild_odoo_relational(why, previous_meta_fingerprint=None, meta_state_out
|
|
| 926 |
_rt = _runtime.get_runtime("royal-imports")
|
| 927 |
from core import user_tables as _ut
|
| 928 |
_ut.record_odoo_sync_status(phase="syncing", st=_rt)
|
| 929 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 930 |
raw_models, schema_errors = _rel.authoritative_schema_snapshot()
|
| 931 |
_ut.record_odoo_schema_snapshot(raw_models, complete=not schema_errors,
|
| 932 |
errors=schema_errors, st=_rt)
|
|
|
|
| 926 |
_rt = _runtime.get_runtime("royal-imports")
|
| 927 |
from core import user_tables as _ut
|
| 928 |
_ut.record_odoo_sync_status(phase="syncing", st=_rt)
|
| 929 |
+
# ββ W54-T46 / R4 / R7 β EVERY Odoo CONNECTION, not just the first. `all_connections`
|
| 930 |
+
# delegates to `odoo_relational.refresh_all`, which walks this tenant's Odoo
|
| 931 |
+
# connections in slot order and records a failure against the connection it belongs
|
| 932 |
+
# to rather than aborting the rest. The DEFAULT connection's counts stay at the top
|
| 933 |
+
# level of the returned dict, so the log line below is unchanged; the per-connection
|
| 934 |
+
# map rides beside them under `connections`.
|
| 935 |
+
# β A FLAG RATHER THAN CALLING THE ALL-CONNECTIONS FUNCTION BY NAME HERE, and the
|
| 936 |
+
# reason is a gate: `verify_odoo_relational` locates this call by its literal spelling
|
| 937 |
+
# and reads the code that follows it, to prove the relation cells are computed after
|
| 938 |
+
# the spawn. Spelling the boot call differently moves that window off the code it is
|
| 939 |
+
# meant to measure. β AND THE CALL IS NAMED IN WORDS ABOVE RATHER THAN WRITTEN OUT,
|
| 940 |
+
# because a gate that counts RAW occurrences of a call would count the one in this
|
| 941 |
+
# comment too. That gate happens to strip comments first; the next one may not.
|
| 942 |
+
# See `odoo_relational.refresh` and its `all_connections` arm.
|
| 943 |
+
counts = _rel.refresh(_rt, "royal-imports", all_connections=True)
|
| 944 |
raw_models, schema_errors = _rel.authoritative_schema_snapshot()
|
| 945 |
_ut.record_odoo_schema_snapshot(raw_models, complete=not schema_errors,
|
| 946 |
errors=schema_errors, st=_rt)
|
api/odoo_relational.py
CHANGED
|
@@ -2370,6 +2370,309 @@ _READERS = {
|
|
| 2370 |
READ_THROUGH_KEYS = frozenset(key for bucket, key, _l, _f in TABLES if bucket not in _READERS)
|
| 2371 |
|
| 2372 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2373 |
class _LentDoc:
|
| 2374 |
"""A store handle that serves the ONE `user_tables` document `plan()` has ALREADY read.
|
| 2375 |
|
|
@@ -2473,7 +2776,7 @@ def frozen(rt):
|
|
| 2473 |
return bool(read_config(rt)["frozen"])
|
| 2474 |
|
| 2475 |
|
| 2476 |
-
def plan(cur, rt=None):
|
| 2477 |
"""The rows that WOULD be written, plus the refusals that apply β no store WRITE at all.
|
| 2478 |
|
| 2479 |
Separated from `apply_plan` so a route, a gate and a dry run all measure the same thing, and
|
|
@@ -2484,6 +2787,16 @@ def plan(cur, rt=None):
|
|
| 2484 |
`{table_key: limit_report}` for every table this plan did not fully materialise, which is R6's
|
| 2485 |
second sentence carried as data rather than left for a reader to infer from an empty list.
|
| 2486 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2487 |
β `rt` IS WHAT MAKES THE TABLE-COUNT CHECK HONEST, and leaving it out was a real half-spawn
|
| 2488 |
bug. This spawn writes FOUR tables in four updater passes; a tenant near `MAX_TABLES` would
|
| 2489 |
create some and refuse the rest β leaving a locked invoices database with no rollup host,
|
|
@@ -2500,8 +2813,10 @@ def plan(cur, rt=None):
|
|
| 2500 |
# not apply on exactly the run that creates the databases. This module DECLARES these keys, so
|
| 2501 |
# it is the honest place to say what they are. Idempotent (a set add), and it fills the
|
| 2502 |
# evaluator's input rather than becoming a second evaluator.
|
| 2503 |
-
|
| 2504 |
-
|
|
|
|
|
|
|
| 2505 |
# ββ W30-T35 / R6 / R7 β WHICH BUCKETS ARE BUILT AT ALL IS NOW ASKED, NOT ASSUMED, and it is
|
| 2506 |
# `core.user_tables.row_limit` that answers: 0 = "stores no rows HERE" (read-through), None =
|
| 2507 |
# "connected and uncapped", MAX_ROWS = "the editable substrate". Its own docstring names this
|
|
@@ -2545,15 +2860,24 @@ def plan(cur, rt=None):
|
|
| 2545 |
# the definition instead of taking one. `_ensure_table_inplace` writes exactly this stamp, so
|
| 2546 |
# what is lent is the document as it stands the moment this plan applies.
|
| 2547 |
lent = _LentDoc({**existing,
|
| 2548 |
-
**{
|
|
|
|
|
|
|
| 2549 |
for k in READ_THROUGH_KEYS}},
|
| 2550 |
ut.STORE_KEY)
|
| 2551 |
|
| 2552 |
built, limits = {}, {}
|
| 2553 |
caps = {}
|
| 2554 |
-
for bucket,
|
|
|
|
| 2555 |
reader = _READERS.get(bucket)
|
| 2556 |
caps[key] = cap = ut.row_limit(key, st=lent)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2557 |
if reader is None or cap == 0:
|
| 2558 |
built[bucket] = []
|
| 2559 |
report = ut.limit_report(key, st=lent)
|
|
@@ -2564,14 +2888,16 @@ def plan(cur, rt=None):
|
|
| 2564 |
problems = []
|
| 2565 |
|
| 2566 |
if rt is not None:
|
| 2567 |
-
needed = [k for
|
| 2568 |
if needed and len(existing) + len(needed) > ut.MAX_TABLES:
|
| 2569 |
problems.append(
|
| 2570 |
f"tenant holds {len(existing)} of MAX_TABLES={ut.MAX_TABLES} user tables and "
|
| 2571 |
-
f"needs {len(needed)} more ({', '.join(needed)})
|
|
|
|
| 2572 |
f"part of a linked set")
|
| 2573 |
|
| 2574 |
-
for bucket,
|
|
|
|
| 2575 |
rows = built[bucket]
|
| 2576 |
cap = caps[key] # asked ONCE per table, above β never re-read per loop
|
| 2577 |
# ββ R6: THE `MAX_ROWS` REFUSAL IS GONE FOR A CONNECTED SOURCE, AND THE SENTENCE IT USED
|
|
@@ -2614,7 +2940,8 @@ def plan(cur, rt=None):
|
|
| 2614 |
return built
|
| 2615 |
|
| 2616 |
|
| 2617 |
-
def apply_plan(rt, built, username="automation", today=None, report=None
|
|
|
|
| 2618 |
"""Create-or-merge every table in `built` and its rows. Idempotent by construction.
|
| 2619 |
|
| 2620 |
Row ids ARE the Odoo ids, so a re-run updates in place and never appends a second copy of the
|
|
@@ -2622,6 +2949,11 @@ def apply_plan(rt, built, username="automation", today=None, report=None):
|
|
| 2622 |
statement rather than a hopeful one.
|
| 2623 |
|
| 2624 |
β ONLY THE BUCKETS PRESENT ARE WRITTEN, so a caller (or a gate) may hand in a subset.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2625 |
"""
|
| 2626 |
if built.get("problems"):
|
| 2627 |
raise Refused("; ".join(built["problems"]))
|
|
@@ -2630,7 +2962,11 @@ def apply_plan(rt, built, username="automation", today=None, report=None):
|
|
| 2630 |
# β An OPTIONAL out-parameter, not a return-shape change: `written` has one value shape and
|
| 2631 |
# keeps it. A caller that wants to SAY what was retired passes a dict; `refresh` does.
|
| 2632 |
retired = []
|
| 2633 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2634 |
for bucket, key, label, fields in TABLES if bucket in built]
|
| 2635 |
|
| 2636 |
# ββ ONE SYNC WRITE FOR ALL FOUR TABLES, not one per table β measured, not tidied.
|
|
@@ -2660,7 +2996,10 @@ def apply_plan(rt, built, username="automation", today=None, report=None):
|
|
| 2660 |
# with `TypeError: list indices must be integers`. One dict, two value shapes, is a
|
| 2661 |
# sentinel in a result set [[sentinel-in-a-sort-key]] β so the retirement reports through
|
| 2662 |
# its OWN channel and the return type stays exactly what it was.
|
|
|
|
|
|
|
| 2663 |
for key in RETIRED_KEYS:
|
|
|
|
| 2664 |
if cur.pop(key, None) is not None:
|
| 2665 |
retired.append(key)
|
| 2666 |
for key, label, fields, rows in plans:
|
|
@@ -2701,7 +3040,9 @@ def _ensure_table_inplace(cur, key, label, fields, rows, username, stamp):
|
|
| 2701 |
for row in wanted.values():
|
| 2702 |
row["refreshed"] = stamp
|
| 2703 |
counts = {"added": 0, "updated": 0, "removed": 0, "rows": len(wanted)}
|
| 2704 |
-
subject
|
|
|
|
|
|
|
| 2705 |
table = cur.get(key)
|
| 2706 |
if table is None:
|
| 2707 |
if len(cur) >= ut.MAX_TABLES:
|
|
@@ -2745,7 +3086,7 @@ def _ensure_table_inplace(cur, key, label, fields, rows, username, stamp):
|
|
| 2745 |
# `setdefault`: it is derived from the code's own structure, so the code is what it must agree
|
| 2746 |
# with, and a definition that somehow lost the flag should regain it rather than keep serving
|
| 2747 |
# an empty grid.
|
| 2748 |
-
if key
|
| 2749 |
table["readThrough"] = True
|
| 2750 |
# W33-T41 β the claim, made DURABLE on the definition. Written on every pass for the same
|
| 2751 |
# reason `readThrough` is: it is derived from this module's own structure, so the code is what
|
|
@@ -2828,7 +3169,7 @@ def is_royal(tenant):
|
|
| 2828 |
return str(tenant or "").strip().lower() in RI_SLUGS
|
| 2829 |
|
| 2830 |
|
| 2831 |
-
def available(rt=None, tenant_key=None):
|
| 2832 |
"""ββ R3 β DOES THIS TENANT HAVE ODOO CONFIGURED WITH LIVE CREDENTIALS? Never a slug list.
|
| 2833 |
|
| 2834 |
R3, verbatim: *"The connector table spawn gates on does this tenant have this connector
|
|
@@ -2853,10 +3194,21 @@ def available(rt=None, tenant_key=None):
|
|
| 2853 |
|
| 2854 |
β ADDING A SECOND ODOO TENANT NEEDS NO EDIT HERE. Anyone with a keychain `odoo` entry is
|
| 2855 |
admitted, whatever their slug.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2856 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2857 |
try:
|
| 2858 |
if rt is not None:
|
| 2859 |
-
return bool(rt.odoo_flag_key()
|
|
|
|
| 2860 |
except Exception: # noqa: BLE001
|
| 2861 |
return False # unreadable = fail closed
|
| 2862 |
if not tenant_key:
|
|
@@ -2865,18 +3217,42 @@ def available(rt=None, tenant_key=None):
|
|
| 2865 |
# from `refresh`, which is always handed one.
|
| 2866 |
try:
|
| 2867 |
from harness import runtime as _runtime
|
| 2868 |
-
|
|
|
|
|
|
|
| 2869 |
except Exception: # noqa: BLE001
|
| 2870 |
return False
|
| 2871 |
|
| 2872 |
|
| 2873 |
-
def refresh(rt, tenant, username="automation", cur=None, today=None
|
|
|
|
| 2874 |
"""THE entry point β the store-resync path and the route both call this.
|
| 2875 |
|
| 2876 |
β It must be CALLED on resync by something outside this file. If it is not wired, every row
|
| 2877 |
still carries a `refreshed` stamp, so a stale worklist is at least LEGIBLE rather than
|
| 2878 |
silently authoritative.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2879 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2880 |
# ββ W53-T39 / R3 β THE ADMISSION IS A CREDENTIALS TEST, NOT A TENANT NAME.
|
| 2881 |
#
|
| 2882 |
# β THE OLD GATE'S REASON IS KEPT AND ONLY ITS MECHANISM IS REPLACED. It read
|
|
@@ -2892,7 +3268,14 @@ def refresh(rt, tenant, username="automation", cur=None, today=None):
|
|
| 2892 |
# loop calls this every cycle and an exception is not a status. Refusing here would hand that
|
| 2893 |
# loop a raise for the one state it is meant to report. So a frozen workspace is admitted this
|
| 2894 |
# far and stopped by its own guard, three lines down, with its own words.
|
| 2895 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2896 |
raise Refused("no Odoo credential is configured for this workspace, so there is nothing "
|
| 2897 |
"behind these tables and the spawn would create empty locked databases. "
|
| 2898 |
"Add an Odoo credential in the Connectors panel, then run the sync again.")
|
|
@@ -2920,10 +3303,19 @@ def refresh(rt, tenant, username="automation", cur=None, today=None):
|
|
| 2920 |
return {"tables": {}, "frozen": True,
|
| 2921 |
"note": "this workspace has disconnected Odoo; its databases are frozen as "
|
| 2922 |
"static data and are not being refreshed"}
|
| 2923 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2924 |
from harness import datastore
|
| 2925 |
cur = datastore.ro_con()
|
| 2926 |
-
built = plan(cur, rt=rt)
|
| 2927 |
# β W32-T15 / R9 β THE GRID PICKER, ENFORCED WHERE IT COUNTS. `apply_plan` writes only the
|
| 2928 |
# buckets present in `built`, so dropping an unticked one here is the whole of "unticking a
|
| 2929 |
# grid stops it materialising on the next sync". Done AFTER `plan` rather than inside it so
|
|
@@ -2934,7 +3326,10 @@ def refresh(rt, tenant, username="automation", cur=None, today=None):
|
|
| 2934 |
# do that either (R10 keeps them). Silent data deletion behind a checkbox is not on offer.
|
| 2935 |
if rt is not None:
|
| 2936 |
keep = enabled_buckets(rt)
|
| 2937 |
-
|
|
|
|
|
|
|
|
|
|
| 2938 |
for bucket, _key, _l, _f in TABLES:
|
| 2939 |
if bucket not in keep:
|
| 2940 |
built.pop(bucket, None)
|
|
@@ -2944,16 +3339,73 @@ def refresh(rt, tenant, username="automation", cur=None, today=None):
|
|
| 2944 |
# Same rule as `skipped` below β R6's second sentence: what was deliberately not built (or no
|
| 2945 |
# longer built) SAYS SO, with the keys.
|
| 2946 |
plan_report = {}
|
| 2947 |
-
written = apply_plan(rt, built, username=username, today=today, report=plan_report
|
|
|
|
| 2948 |
# ββ W49-T25 / C6 β THE SCHEMA CATALOGUE FOLLOWS THE CODE WITH NO MANUAL STEP. Runs AFTER the
|
| 2949 |
# tables are applied, so the snapshot describes a pass that actually landed. The two early
|
| 2950 |
# returns above are respected by construction: a tenant with no Odoo entitlement raised, and a
|
| 2951 |
# FROZEN workspace returned before reaching here, so a disconnected connector is not
|
| 2952 |
# re-recorded. See `_refresh_declared_schema` for why it writes the declared half only.
|
| 2953 |
declared_report = _refresh_declared_schema(rt)
|
| 2954 |
-
|
| 2955 |
-
|
| 2956 |
-
|
| 2957 |
-
|
| 2958 |
-
|
| 2959 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2370 |
READ_THROUGH_KEYS = frozenset(key for bucket, key, _l, _f in TABLES if bucket not in _READERS)
|
| 2371 |
|
| 2372 |
|
| 2373 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2374 |
+
# ββ W54-T46 / R4 / R7 / CONTRACT C4 β A TABLE BELONGS TO EXACTLY ONE CONNECTION
|
| 2375 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2376 |
+
#
|
| 2377 |
+
# R4, verbatim: *"If a tenant is an agency that helps with clients that each have Odoo, then the
|
| 2378 |
+
# connector for Odoo can be many depending on the API. This is why its critical."* R7 makes the
|
| 2379 |
+
# isolation between those clients STRICT β there is no blended view, and client A must not be one
|
| 2380 |
+
# dropped filter away from client B.
|
| 2381 |
+
#
|
| 2382 |
+
# ββ THE DEFAULT CONNECTION KEEPS THE LEGACY KEYS, AND THAT IS THE WHOLE SHAPE OF THE RULE.
|
| 2383 |
+
# Renaming tenant #0's ten live tables would move every saved view, grant, cohort, link, rollup
|
| 2384 |
+
# and nav entry that names them. So the tenant's DESIGNATED DEFAULT connection stays exactly where
|
| 2385 |
+
# it is and only the connections added after it are namespaced.
|
| 2386 |
+
#
|
| 2387 |
+
# β THE TOKEN IS THE `connection_id`, NEVER THE `slot`. MEASURED (PRD amendment A4): a pre-wave
|
| 2388 |
+
# row's read-default slot MOVES when a sibling of the same type is deleted (2 -> 1), while its
|
| 2389 |
+
# connection id does not. A key built from a slot would one day address a different client's rows.
|
| 2390 |
+
|
| 2391 |
+
#: The separator between a base table key and the connection that owns it. TWO underscores,
|
| 2392 |
+
#: because every base key spells its own words with ONE, so `rpartition` splits it back cleanly.
|
| 2393 |
+
CONNECTION_SEP = "__"
|
| 2394 |
+
|
| 2395 |
+
#: What `connection_for_table_key` answers for a LEGACY key when it was handed no runtime to
|
| 2396 |
+
#: resolve the tenant's designated default against. It means "whichever connection is designated
|
| 2397 |
+
#: default" β a real answer, not an absence, which is what keeps the inverse TOTAL.
|
| 2398 |
+
DEFAULT_CONNECTION = "default"
|
| 2399 |
+
|
| 2400 |
+
#: Every table key this connector owns, un-namespaced. The two RETIRED keys are members so a
|
| 2401 |
+
#: document that still holds one resolves to its connection rather than reading as a stranger's
|
| 2402 |
+
#: table β `apply_plan` has to know whose copy it is popping.
|
| 2403 |
+
BASE_TABLE_KEYS = frozenset([key for _b, key, _l, _f in TABLES] + list(RETIRED_KEYS))
|
| 2404 |
+
|
| 2405 |
+
#: `core.user_tables._field_key` truncates a table key at 60 characters SILENTLY, and a truncated
|
| 2406 |
+
#: key is a key that can collide with another connection's. The longest base key is
|
| 2407 |
+
#: `ut_odoo_order_lines` (19) and a connection id is `k_` + 12 hex (14), so a namespaced key is 35
|
| 2408 |
+
#: characters; the guard is here for the day one of those two numbers moves.
|
| 2409 |
+
MAX_TABLE_KEY_LEN = 60
|
| 2410 |
+
|
| 2411 |
+
#: The characters `core.user_tables._field_key` leaves alone. A `k_<hex>` connection id is already
|
| 2412 |
+
#: inside this set, which is why it survives the normaliser unchanged.
|
| 2413 |
+
_KEY_CHARS = frozenset("abcdefghijklmnopqrstuvwxyz0123456789_")
|
| 2414 |
+
|
| 2415 |
+
|
| 2416 |
+
def default_connection_id(rt):
|
| 2417 |
+
"""This tenant's DESIGNATED DEFAULT Odoo connection id, or None. Decrypts nothing.
|
| 2418 |
+
|
| 2419 |
+
β NOT RE-DERIVED HERE. `core.keychain.default_connection_id` is the one resolver (W54-T44):
|
| 2420 |
+
lowest immutable slot, ties by insertion order. A second walk in this file is exactly the
|
| 2421 |
+
drift that resolver was written to end.
|
| 2422 |
+
"""
|
| 2423 |
+
if rt is None:
|
| 2424 |
+
return None
|
| 2425 |
+
try:
|
| 2426 |
+
import core.keychain as keychain
|
| 2427 |
+
return keychain.default_connection_id(rt, "odoo")
|
| 2428 |
+
except Exception: # noqa: BLE001
|
| 2429 |
+
return None
|
| 2430 |
+
|
| 2431 |
+
|
| 2432 |
+
def table_key_for(base_key, connection_id=None):
|
| 2433 |
+
"""The store key `base_key` takes under `connection_id`.
|
| 2434 |
+
|
| 2435 |
+
`connection_id=None` means the tenant's DESIGNATED DEFAULT connection, and it answers the bare
|
| 2436 |
+
legacy key unchanged: `ut_odoo_invoices` stays `ut_odoo_invoices`.
|
| 2437 |
+
|
| 2438 |
+
β The result still starts with `ut_`, which is load-bearing three times over: the `ut_*` wall,
|
| 2439 |
+
`user_tables.is_linkable_target`, and `grid_events._field_share_keys`' shared-stratum branch
|
| 2440 |
+
all key on that prefix.
|
| 2441 |
+
"""
|
| 2442 |
+
base = str(base_key or "").strip()
|
| 2443 |
+
cid = str(connection_id or "").strip().lower()
|
| 2444 |
+
if not cid:
|
| 2445 |
+
return base
|
| 2446 |
+
if (CONNECTION_SEP in cid or set(cid) - _KEY_CHARS or cid != cid.strip("_")):
|
| 2447 |
+
raise Refused(f"{cid!r} cannot be used as a table namespace: a connection id has to be "
|
| 2448 |
+
f"lowercase letters, digits and single underscores, or the table key it "
|
| 2449 |
+
f"builds would be stored under a different name than the one it is read by")
|
| 2450 |
+
key = f"{base}{CONNECTION_SEP}{cid}"
|
| 2451 |
+
if len(key) > MAX_TABLE_KEY_LEN:
|
| 2452 |
+
raise Refused(f"{key!r} is {len(key)} characters and the store truncates a table key at "
|
| 2453 |
+
f"{MAX_TABLE_KEY_LEN}; refusing rather than creating a key that two "
|
| 2454 |
+
f"connections could share. Shorten the base key or the connection id.")
|
| 2455 |
+
return key
|
| 2456 |
+
|
| 2457 |
+
|
| 2458 |
+
def split_table_key(table_key):
|
| 2459 |
+
"""`(base_key, connection_id)` for a key this connector owns, `(None, None)` for anything
|
| 2460 |
+
else β so the question "is this one of ours" and "whose is it" have one answer.
|
| 2461 |
+
|
| 2462 |
+
A LEGACY (bare) key answers `(base, None)`: no namespace token, because the designated default
|
| 2463 |
+
keeps its legacy key.
|
| 2464 |
+
"""
|
| 2465 |
+
raw = str(table_key or "").strip()
|
| 2466 |
+
if raw in BASE_TABLE_KEYS:
|
| 2467 |
+
return raw, None
|
| 2468 |
+
base, sep, cid = raw.rpartition(CONNECTION_SEP)
|
| 2469 |
+
if sep and cid and base in BASE_TABLE_KEYS:
|
| 2470 |
+
return base, cid
|
| 2471 |
+
return None, None
|
| 2472 |
+
|
| 2473 |
+
|
| 2474 |
+
def base_table_key(table_key):
|
| 2475 |
+
"""The un-namespaced key behind `table_key`, or None when it is not one of this connector's."""
|
| 2476 |
+
return split_table_key(table_key)[0]
|
| 2477 |
+
|
| 2478 |
+
|
| 2479 |
+
def connection_for_table_key(table_key, rt=None):
|
| 2480 |
+
"""WHICH connection owns this table key β exactly one, or None when the key is not one of
|
| 2481 |
+
this connector's tables at all.
|
| 2482 |
+
|
| 2483 |
+
β THE INVERSE IS THE CONTRACT. C4's clause is that a table resolves to exactly one
|
| 2484 |
+
connection; a namespacing you cannot read backwards is a convention, not an isolation.
|
| 2485 |
+
A legacy key belongs to the DESIGNATED DEFAULT, which is what `rt` answers; with no `rt` it
|
| 2486 |
+
answers the `DEFAULT_CONNECTION` sentinel rather than pretending it does not know.
|
| 2487 |
+
"""
|
| 2488 |
+
base, cid = split_table_key(table_key)
|
| 2489 |
+
if base is None:
|
| 2490 |
+
return None
|
| 2491 |
+
if cid:
|
| 2492 |
+
return cid
|
| 2493 |
+
return (default_connection_id(rt) or DEFAULT_CONNECTION) if rt is not None \
|
| 2494 |
+
else DEFAULT_CONNECTION
|
| 2495 |
+
|
| 2496 |
+
|
| 2497 |
+
#: ββ W54-T49 / R7 / C4 β THE SECOND IMPORT-TIME REGISTRATION IN THIS FILE, AND IT IS THE ONE
|
| 2498 |
+
#: THAT ARMS A WALL RATHER THAN DECLARING A SPEC.
|
| 2499 |
+
#:
|
| 2500 |
+
#: `core.perm_scope.ConnectionScope` refuses a read of a table belonging to another connection, and
|
| 2501 |
+
#: it answers "whose table is this" through a registration slot because `core` never imports up
|
| 2502 |
+
#: (`platform/ARCHITECTURE.md`). The inverse lives HERE, so this module fills that slot at import,
|
| 2503 |
+
#: exactly as `SPEC_REGISTRATION` above fills the connector-spec registry and for the identical
|
| 2504 |
+
#: reason: the module that owns the fact is the one that declares it.
|
| 2505 |
+
#:
|
| 2506 |
+
#: ββ WITHOUT THIS, THE WALL IS WHOLE, GATED AND ENFORCING NOTHING. An unfilled slot makes
|
| 2507 |
+
#: `covers` answer False and `require` report `Unresolvable`, which is fail-closed and therefore
|
| 2508 |
+
#: silent, so the feature would have shipped and behaved as a no-op
|
| 2509 |
+
#: [[artifact-with-no-importer]]. `verify_scopes` asserts the slot is filled BY IMPORT, before it
|
| 2510 |
+
#: registers anything of its own, so deleting the boot call below reds a gate.
|
| 2511 |
+
#:
|
| 2512 |
+
#: β IT NEVER RAISES, FOR THE REASON THE BANNER ABOVE GIVES IN FULL: `core` is genuinely absent
|
| 2513 |
+
#: from `sys.path` on a bare import of this module from `aios-web/api`, and taking the route layer
|
| 2514 |
+
#: down over a declaration nothing on the request path reads is the wrong trade. The failure is
|
| 2515 |
+
#: CAPTURED here instead, in the same three keys.
|
| 2516 |
+
OWNER_REGISTRATION = {"slot": "perm_scope.connection_owner", "registered": False, "error": ""}
|
| 2517 |
+
|
| 2518 |
+
|
| 2519 |
+
def register_connection_owner_slot():
|
| 2520 |
+
"""Declare this module's `connection_for_table_key` as the answer to "whose table is this".
|
| 2521 |
+
|
| 2522 |
+
Returns True when it landed. Records the reason in `OWNER_REGISTRATION` when it did not, and
|
| 2523 |
+
never raises: see the banner above. Idempotent, because the slot holds one reader and a second
|
| 2524 |
+
call replaces it with the same function.
|
| 2525 |
+
"""
|
| 2526 |
+
try:
|
| 2527 |
+
import core.perm_scope as perm_scope
|
| 2528 |
+
except Exception as exc: # noqa: BLE001
|
| 2529 |
+
# β ASCII ONLY, like `SPEC_REGISTRATION`'s error string: this can be quoted into a report,
|
| 2530 |
+
# and standing rule 2 forbids an em dash or an en dash in copy that can reach a screen.
|
| 2531 |
+
OWNER_REGISTRATION.update(
|
| 2532 |
+
registered=False,
|
| 2533 |
+
error="core.perm_scope is not importable from here: %s: %s"
|
| 2534 |
+
% (type(exc).__name__, str(exc)[:120]))
|
| 2535 |
+
return False
|
| 2536 |
+
perm_scope.register_connection_owner(connection_for_table_key)
|
| 2537 |
+
OWNER_REGISTRATION.update(registered=True, error="")
|
| 2538 |
+
return True
|
| 2539 |
+
|
| 2540 |
+
|
| 2541 |
+
register_connection_owner_slot()
|
| 2542 |
+
|
| 2543 |
+
|
| 2544 |
+
def table_subject_for(table_key):
|
| 2545 |
+
"""The real-world population this key presents, namespaced by its connection.
|
| 2546 |
+
|
| 2547 |
+
ββ THE SUBJECT HAS TO MOVE WITH THE KEY OR A SECOND CONNECTION CANNOT BE CREATED AT ALL.
|
| 2548 |
+
`_ensure_table_inplace` refuses to create a table whose subject another table in the same
|
| 2549 |
+
document already claims (one subject, one database, item 12a). Client B's invoices are a
|
| 2550 |
+
DIFFERENT population from client A's, so the claim carries the connection with it.
|
| 2551 |
+
"""
|
| 2552 |
+
base, cid = split_table_key(table_key)
|
| 2553 |
+
subject = TABLE_SUBJECTS.get(base if base is not None else str(table_key or ""))
|
| 2554 |
+
if not subject or not cid:
|
| 2555 |
+
return subject
|
| 2556 |
+
return f"{subject}@{cid}"
|
| 2557 |
+
|
| 2558 |
+
|
| 2559 |
+
def is_read_through_key(table_key):
|
| 2560 |
+
"""Does this key name one of the two grains whose rows are served from the mirror? Answered
|
| 2561 |
+
on the BASE key, so a namespaced copy inherits the statement rather than losing it."""
|
| 2562 |
+
return base_table_key(table_key) in READ_THROUGH_KEYS
|
| 2563 |
+
|
| 2564 |
+
|
| 2565 |
+
def connection_namespace(rt, connection_id=None):
|
| 2566 |
+
"""`(connection_id, namespace_token)` for a refresh of `connection_id`.
|
| 2567 |
+
|
| 2568 |
+
The token is None for the DESIGNATED DEFAULT (bare, legacy keys) and the connection id for
|
| 2569 |
+
every other connection.
|
| 2570 |
+
|
| 2571 |
+
β A NAMED CONNECTION THAT DOES NOT RESOLVE IS A REFUSAL, NEVER A FALLBACK. Serving the
|
| 2572 |
+
default to a caller that asked for a specific client is precisely the leak R7 forbids, and it
|
| 2573 |
+
is the same asymmetry `runtime.odoo_source` already holds.
|
| 2574 |
+
"""
|
| 2575 |
+
default = default_connection_id(rt)
|
| 2576 |
+
if connection_id is None:
|
| 2577 |
+
return default, None
|
| 2578 |
+
import core.keychain as keychain
|
| 2579 |
+
cid = keychain.resolve_connection_id(rt, "odoo", connection_id)
|
| 2580 |
+
if not cid:
|
| 2581 |
+
raise Refused(f"{str(connection_id)!r} does not name an Odoo connection in this "
|
| 2582 |
+
f"workspace, so there is nothing to spawn for it. Pick a connection in the "
|
| 2583 |
+
f"Connectors panel and run the sync again.")
|
| 2584 |
+
return cid, (None if cid == default else cid)
|
| 2585 |
+
|
| 2586 |
+
|
| 2587 |
+
def connection_label(rt, connection_id=None):
|
| 2588 |
+
"""The user's own name for this connection ('Odoo 2' until they rename it), or ''."""
|
| 2589 |
+
if rt is None or not connection_id:
|
| 2590 |
+
return ""
|
| 2591 |
+
try:
|
| 2592 |
+
import core.keychain as keychain
|
| 2593 |
+
for row in keychain.list_entries(rt):
|
| 2594 |
+
if row.get("type") == "odoo" \
|
| 2595 |
+
and str(row.get("connection_id")) == str(connection_id):
|
| 2596 |
+
return str(row.get("label") or "")
|
| 2597 |
+
except Exception: # noqa: BLE001
|
| 2598 |
+
return ""
|
| 2599 |
+
return ""
|
| 2600 |
+
|
| 2601 |
+
|
| 2602 |
+
def table_label_for(label, conn_label=None):
|
| 2603 |
+
"""The nav label a namespaced table shows.
|
| 2604 |
+
|
| 2605 |
+
β R9 keeps `TABLES`' shipped label as the default; this only says WHICH connection the grid
|
| 2606 |
+
belongs to, because two grids sharing a display name is how a person reads the wrong number
|
| 2607 |
+
off the right looking tab.
|
| 2608 |
+
"""
|
| 2609 |
+
conn_label = " ".join(str(conn_label or "").split())
|
| 2610 |
+
return f"{label} ({conn_label})" if conn_label else str(label)
|
| 2611 |
+
|
| 2612 |
+
|
| 2613 |
+
def namespaced_fields(fields, connection_id=None):
|
| 2614 |
+
"""A field contract re-pointed at ONE connection's tables.
|
| 2615 |
+
|
| 2616 |
+
ββ THIS IS WHERE R7 BECOMES STRUCTURAL RATHER THAN CONVENTIONAL. Every `link` bag in the
|
| 2617 |
+
contracts above names a sibling by its LEGACY key, so a second connection's vendors table
|
| 2618 |
+
would fold the FIRST connection's bills unless the target moves with the key. A namespaced
|
| 2619 |
+
table can only ever link to a namespaced sibling of its own connection.
|
| 2620 |
+
|
| 2621 |
+
β AND A TARGET THAT CANNOT BE NAMESPACED IS DROPPED, never left pointing at shared data.
|
| 2622 |
+
`customer_link` targets the compiled registry module `customer_data`, which holds the DEFAULT
|
| 2623 |
+
connection's customers and has no per-connection copy to point at; rendering it on another
|
| 2624 |
+
client's invoices would show that client one of ours. An absent column is visible; a column
|
| 2625 |
+
quietly resolving across the isolation boundary is not.
|
| 2626 |
+
|
| 2627 |
+
ββ A **RETIRED** TARGET IS DROPPED FOR EVERY CONNECTION, FOR THE IDENTICAL REASON. A retired
|
| 2628 |
+
table has no per-connection copy any more than a registry module does: `RETIRED_KEYS` are
|
| 2629 |
+
absent from `TABLES`, so nothing plans, creates or re-creates one under ANY connection.
|
| 2630 |
+
Re-pointing such a link would mint `ut_odoo_customers__k_...` β a key nothing creates AND
|
| 2631 |
+
nothing registers as absent, because `routes_grid._register_retired_tables` fills the
|
| 2632 |
+
absent-table registry from the BARE `RETIRED_KEYS` tuple. An edge naming it would therefore
|
| 2633 |
+
survive W54-T37's relation enumeration and refuse as a permission wall about a database that
|
| 2634 |
+
does not exist, which is instruction 22's exact defect re-created for connection 2.
|
| 2635 |
+
β MEASURED 2026-09-06: ZERO live contract fields link to a retired key today, so this is
|
| 2636 |
+
LATENT, not live. It goes live the moment anybody adds one, which is precisely how those two
|
| 2637 |
+
keys came to need retiring in the first place: they were link targets before they were dropped.
|
| 2638 |
+
|
| 2639 |
+
β THE TEST IS HERE AND NOT IN `BASE_TABLE_KEYS`. That frozenset's other consumers are
|
| 2640 |
+
`split_table_key` and `connection_for_table_key`, which NEED the retired keys present so a
|
| 2641 |
+
retired residue key can still be ATTRIBUTED to its connection during cleanup β `apply_plan`'s
|
| 2642 |
+
pop loop mints `table_key_for(retired, connection_id)` for exactly that purpose. Narrowing the
|
| 2643 |
+
set would break the cleanup path; narrowing the DROP TEST is the change.
|
| 2644 |
+
"""
|
| 2645 |
+
if not connection_id:
|
| 2646 |
+
return list(fields)
|
| 2647 |
+
out = []
|
| 2648 |
+
for field in fields:
|
| 2649 |
+
bag = field.get("link") if isinstance(field, dict) else None
|
| 2650 |
+
if not isinstance(bag, dict):
|
| 2651 |
+
out.append(field)
|
| 2652 |
+
continue
|
| 2653 |
+
target = str(bag.get("table") or "")
|
| 2654 |
+
if target not in BASE_TABLE_KEYS or target in RETIRED_KEYS:
|
| 2655 |
+
continue
|
| 2656 |
+
out.append({**field,
|
| 2657 |
+
"link": {**bag, "table": table_key_for(target, connection_id)}})
|
| 2658 |
+
return out
|
| 2659 |
+
|
| 2660 |
+
|
| 2661 |
+
#: R6 / standing rule 1's SECOND HALF, for the case this ticket creates: a connection that is not
|
| 2662 |
+
#: the tenant's default has no mirror of its own yet, so there is no honest row source for it.
|
| 2663 |
+
#: Reading the default connection's mirror would be the exact cross-client leak R7 forbids, so the
|
| 2664 |
+
#: tables are created EMPTY and the reason is reported rather than inferred from a blank grid.
|
| 2665 |
+
def _no_mirror_report(connection_id):
|
| 2666 |
+
return {"subject": "rows", "limit": 0, "effect": "refused",
|
| 2667 |
+
"cause": "this connection has no mirror of its own yet, and reading the default "
|
| 2668 |
+
"connection's mirror would put one client's rows in another client's "
|
| 2669 |
+
"database, which strict isolation forbids",
|
| 2670 |
+
"recommendation": "give each connection its own mirror sync, then run this refresh "
|
| 2671 |
+
"again. The tables, their fields and their links are created now, "
|
| 2672 |
+
"so nothing downstream has to wait for that.",
|
| 2673 |
+
"connection": str(connection_id or "")}
|
| 2674 |
+
|
| 2675 |
+
|
| 2676 |
class _LentDoc:
|
| 2677 |
"""A store handle that serves the ONE `user_tables` document `plan()` has ALREADY read.
|
| 2678 |
|
|
|
|
| 2776 |
return bool(read_config(rt)["frozen"])
|
| 2777 |
|
| 2778 |
|
| 2779 |
+
def plan(cur, rt=None, connection_id=None):
|
| 2780 |
"""The rows that WOULD be written, plus the refusals that apply β no store WRITE at all.
|
| 2781 |
|
| 2782 |
Separated from `apply_plan` so a route, a gate and a dry run all measure the same thing, and
|
|
|
|
| 2787 |
`{table_key: limit_report}` for every table this plan did not fully materialise, which is R6's
|
| 2788 |
second sentence carried as data rather than left for a reader to infer from an empty list.
|
| 2789 |
|
| 2790 |
+
ββ W54-T46 / R4 / R7 β `connection_id` IS THE NAMESPACE TOKEN, and `None` means the
|
| 2791 |
+
tenant's DESIGNATED DEFAULT, whose keys stay exactly the legacy ones. Every key this function
|
| 2792 |
+
reads a cap for, reports a limit for and counts against `MAX_TABLES` is the NAMESPACED key, so
|
| 2793 |
+
two connections are two disjoint sets of tables and neither can be planned over the other.
|
| 2794 |
+
|
| 2795 |
+
β `cur` MAY BE None, and for a non-default connection it always is. There is one DuckDB mirror
|
| 2796 |
+
per tenant and it holds the DEFAULT connection's book; handing it to another connection's plan
|
| 2797 |
+
would build one client's rows into another client's database. So a plan with no cursor builds
|
| 2798 |
+
NO rows and says why, per table, in `limits` (standing rule 1's second half).
|
| 2799 |
+
|
| 2800 |
β `rt` IS WHAT MAKES THE TABLE-COUNT CHECK HONEST, and leaving it out was a real half-spawn
|
| 2801 |
bug. This spawn writes FOUR tables in four updater passes; a tenant near `MAX_TABLES` would
|
| 2802 |
create some and refuse the rest β leaving a locked invoices database with no rollup host,
|
|
|
|
| 2813 |
# not apply on exactly the run that creates the databases. This module DECLARES these keys, so
|
| 2814 |
# it is the honest place to say what they are. Idempotent (a set add), and it fills the
|
| 2815 |
# evaluator's input rather than becoming a second evaluator.
|
| 2816 |
+
keys = {bucket: table_key_for(key, connection_id)
|
| 2817 |
+
for bucket, key, _l, _f in TABLES}
|
| 2818 |
+
ut.register_connected(*keys.values())
|
| 2819 |
+
excluded = excluded_ids(cur) if cur is not None else set()
|
| 2820 |
# ββ W30-T35 / R6 / R7 β WHICH BUCKETS ARE BUILT AT ALL IS NOW ASKED, NOT ASSUMED, and it is
|
| 2821 |
# `core.user_tables.row_limit` that answers: 0 = "stores no rows HERE" (read-through), None =
|
| 2822 |
# "connected and uncapped", MAX_ROWS = "the editable substrate". Its own docstring names this
|
|
|
|
| 2860 |
# the definition instead of taking one. `_ensure_table_inplace` writes exactly this stamp, so
|
| 2861 |
# what is lent is the document as it stands the moment this plan applies.
|
| 2862 |
lent = _LentDoc({**existing,
|
| 2863 |
+
**{table_key_for(k, connection_id): {
|
| 2864 |
+
**(existing.get(table_key_for(k, connection_id)) or {}),
|
| 2865 |
+
"readThrough": True}
|
| 2866 |
for k in READ_THROUGH_KEYS}},
|
| 2867 |
ut.STORE_KEY)
|
| 2868 |
|
| 2869 |
built, limits = {}, {}
|
| 2870 |
caps = {}
|
| 2871 |
+
for bucket, _base, _label, _fields in TABLES:
|
| 2872 |
+
key = keys[bucket]
|
| 2873 |
reader = _READERS.get(bucket)
|
| 2874 |
caps[key] = cap = ut.row_limit(key, st=lent)
|
| 2875 |
+
if cur is None and reader is not None and cap != 0:
|
| 2876 |
+
# β A CONNECTION WITH NO MIRROR OF ITS OWN. Not silence, and not another connection's
|
| 2877 |
+
# rows: an empty table with its reason attached (standing rule 1's second half).
|
| 2878 |
+
built[bucket] = []
|
| 2879 |
+
limits[key] = _no_mirror_report(connection_id)
|
| 2880 |
+
continue
|
| 2881 |
if reader is None or cap == 0:
|
| 2882 |
built[bucket] = []
|
| 2883 |
report = ut.limit_report(key, st=lent)
|
|
|
|
| 2888 |
problems = []
|
| 2889 |
|
| 2890 |
if rt is not None:
|
| 2891 |
+
needed = [k for k in keys.values() if k not in existing]
|
| 2892 |
if needed and len(existing) + len(needed) > ut.MAX_TABLES:
|
| 2893 |
problems.append(
|
| 2894 |
f"tenant holds {len(existing)} of MAX_TABLES={ut.MAX_TABLES} user tables and "
|
| 2895 |
+
f"needs {len(needed)} more ({', '.join(needed)}) for connection "
|
| 2896 |
+
f"{connection_id or 'default'}; refusing rather than creating "
|
| 2897 |
f"part of a linked set")
|
| 2898 |
|
| 2899 |
+
for bucket, _base, _label, _fields in TABLES:
|
| 2900 |
+
key = keys[bucket]
|
| 2901 |
rows = built[bucket]
|
| 2902 |
cap = caps[key] # asked ONCE per table, above β never re-read per loop
|
| 2903 |
# ββ R6: THE `MAX_ROWS` REFUSAL IS GONE FOR A CONNECTED SOURCE, AND THE SENTENCE IT USED
|
|
|
|
| 2940 |
return built
|
| 2941 |
|
| 2942 |
|
| 2943 |
+
def apply_plan(rt, built, username="automation", today=None, report=None,
|
| 2944 |
+
connection_id=None):
|
| 2945 |
"""Create-or-merge every table in `built` and its rows. Idempotent by construction.
|
| 2946 |
|
| 2947 |
Row ids ARE the Odoo ids, so a re-run updates in place and never appends a second copy of the
|
|
|
|
| 2949 |
statement rather than a hopeful one.
|
| 2950 |
|
| 2951 |
β ONLY THE BUCKETS PRESENT ARE WRITTEN, so a caller (or a gate) may hand in a subset.
|
| 2952 |
+
|
| 2953 |
+
ββ W54-T46 β `connection_id` NAMES WHOSE TABLES THESE ARE. `None` is the tenant's designated
|
| 2954 |
+
default and writes the legacy keys, byte for byte as before. Any other connection writes its
|
| 2955 |
+
own namespaced keys, its own namespaced LINK targets (`namespaced_fields`) and its own
|
| 2956 |
+
namespaced subject claims, so the set it writes and the set the default writes are disjoint.
|
| 2957 |
"""
|
| 2958 |
if built.get("problems"):
|
| 2959 |
raise Refused("; ".join(built["problems"]))
|
|
|
|
| 2962 |
# β An OPTIONAL out-parameter, not a return-shape change: `written` has one value shape and
|
| 2963 |
# keeps it. A caller that wants to SAY what was retired passes a dict; `refresh` does.
|
| 2964 |
retired = []
|
| 2965 |
+
conn_label = connection_label(rt, connection_id)
|
| 2966 |
+
plans = [(table_key_for(key, connection_id),
|
| 2967 |
+
table_label_for(label, conn_label),
|
| 2968 |
+
namespaced_fields(fields(), connection_id),
|
| 2969 |
+
built[bucket])
|
| 2970 |
for bucket, key, label, fields in TABLES if bucket in built]
|
| 2971 |
|
| 2972 |
# ββ ONE SYNC WRITE FOR ALL FOUR TABLES, not one per table β measured, not tidied.
|
|
|
|
| 2996 |
# with `TypeError: list indices must be integers`. One dict, two value shapes, is a
|
| 2997 |
# sentinel in a result set [[sentinel-in-a-sort-key]] β so the retirement reports through
|
| 2998 |
# its OWN channel and the return type stays exactly what it was.
|
| 2999 |
+
# β THIS CONNECTION'S copies only. A retirement is per table, and popping the bare
|
| 3000 |
+
# keys while refreshing connection 2 would delete the DEFAULT connection's rows.
|
| 3001 |
for key in RETIRED_KEYS:
|
| 3002 |
+
key = table_key_for(key, connection_id)
|
| 3003 |
if cur.pop(key, None) is not None:
|
| 3004 |
retired.append(key)
|
| 3005 |
for key, label, fields, rows in plans:
|
|
|
|
| 3040 |
for row in wanted.values():
|
| 3041 |
row["refreshed"] = stamp
|
| 3042 |
counts = {"added": 0, "updated": 0, "removed": 0, "rows": len(wanted)}
|
| 3043 |
+
# W54-T46: the subject carries the connection, or client B's invoices collide with
|
| 3044 |
+
# client A's claim and the second connection can never be created at all.
|
| 3045 |
+
subject = table_subject_for(key)
|
| 3046 |
table = cur.get(key)
|
| 3047 |
if table is None:
|
| 3048 |
if len(cur) >= ut.MAX_TABLES:
|
|
|
|
| 3086 |
# `setdefault`: it is derived from the code's own structure, so the code is what it must agree
|
| 3087 |
# with, and a definition that somehow lost the flag should regain it rather than keep serving
|
| 3088 |
# an empty grid.
|
| 3089 |
+
if is_read_through_key(key):
|
| 3090 |
table["readThrough"] = True
|
| 3091 |
# W33-T41 β the claim, made DURABLE on the definition. Written on every pass for the same
|
| 3092 |
# reason `readThrough` is: it is derived from this module's own structure, so the code is what
|
|
|
|
| 3169 |
return str(tenant or "").strip().lower() in RI_SLUGS
|
| 3170 |
|
| 3171 |
|
| 3172 |
+
def available(rt=None, tenant_key=None, connection_id=None):
|
| 3173 |
"""ββ R3 β DOES THIS TENANT HAVE ODOO CONFIGURED WITH LIVE CREDENTIALS? Never a slug list.
|
| 3174 |
|
| 3175 |
R3, verbatim: *"The connector table spawn gates on does this tenant have this connector
|
|
|
|
| 3194 |
|
| 3195 |
β ADDING A SECOND ODOO TENANT NEEDS NO EDIT HERE. Anyone with a keychain `odoo` entry is
|
| 3196 |
admitted, whatever their slug.
|
| 3197 |
+
|
| 3198 |
+
β W54-T46 / R4 β `connection_id` ASKS THE SAME QUESTION OF ONE NAMED CONNECTION.
|
| 3199 |
+
`odoo_flag_key` already answers per connection and already refuses to fall back to the
|
| 3200 |
+
environment for a named one, so admission for connection 2 tests connection 2's credentials
|
| 3201 |
+
and nothing else. No id is the pre-wave call, unchanged.
|
| 3202 |
"""
|
| 3203 |
+
# β THE UNNAMED CALL IS SPELLED WITH NO ARGUMENT, VERBATIM, AND THAT IS NOT STYLE.
|
| 3204 |
+
# `verify_odoo_relational`'s `_CredRT` fixture defines `odoo_flag_key(self)` with no
|
| 3205 |
+
# parameter, so passing even `None` positionally raises TypeError, which the handler below
|
| 3206 |
+
# swallows as "fail closed" β eight admission legs went red for a reason that had nothing to
|
| 3207 |
+
# do with the rule they guard. The pre-wave call stays the pre-wave call.
|
| 3208 |
try:
|
| 3209 |
if rt is not None:
|
| 3210 |
+
return bool(rt.odoo_flag_key(connection_id) if connection_id is not None
|
| 3211 |
+
else rt.odoo_flag_key())
|
| 3212 |
except Exception: # noqa: BLE001
|
| 3213 |
return False # unreadable = fail closed
|
| 3214 |
if not tenant_key:
|
|
|
|
| 3217 |
# from `refresh`, which is always handed one.
|
| 3218 |
try:
|
| 3219 |
from harness import runtime as _runtime
|
| 3220 |
+
_r = _runtime.get_runtime(str(tenant_key))
|
| 3221 |
+
return bool(_r.odoo_flag_key(connection_id) if connection_id is not None
|
| 3222 |
+
else _r.odoo_flag_key())
|
| 3223 |
except Exception: # noqa: BLE001
|
| 3224 |
return False
|
| 3225 |
|
| 3226 |
|
| 3227 |
+
def refresh(rt, tenant, username="automation", cur=None, today=None, connection_id=None,
|
| 3228 |
+
all_connections=False):
|
| 3229 |
"""THE entry point β the store-resync path and the route both call this.
|
| 3230 |
|
| 3231 |
β It must be CALLED on resync by something outside this file. If it is not wired, every row
|
| 3232 |
still carries a `refreshed` stamp, so a stale worklist is at least LEGIBLE rather than
|
| 3233 |
silently authoritative.
|
| 3234 |
+
|
| 3235 |
+
ββ W54-T46 / R4 / R7 / C4 β ONE CONNECTION PER CALL. `connection_id=None` resolves the
|
| 3236 |
+
tenant's DESIGNATED DEFAULT and is byte-for-byte the pre-wave behaviour, down to the return
|
| 3237 |
+
shape (`verify_odoo_relational` asserts on it). A named connection spawns THAT connection's
|
| 3238 |
+
namespaced tables, admitted against THAT connection's credentials, and can neither read nor
|
| 3239 |
+
write the default connection's keys.
|
| 3240 |
+
|
| 3241 |
+
β `all_connections=True` delegates to `refresh_all` below, which is the loop over every Odoo
|
| 3242 |
+
connection this tenant holds. It is a flag on this entry point rather than a second call in
|
| 3243 |
+
`main.py` for one measured reason: `verify_odoo_relational` pins the LITERAL `_rel.refresh(`
|
| 3244 |
+
in `main.py`'s source and reads the 2000 characters after it to prove the relation cells are
|
| 3245 |
+
computed after the spawn. Spelling the boot call `_rel.refresh_all(` turns two legs of a gate
|
| 3246 |
+
this lane may not edit RED for a reason that has nothing to do with the rule they guard.
|
| 3247 |
"""
|
| 3248 |
+
if all_connections:
|
| 3249 |
+
return refresh_all(rt, tenant, username=username, cur=cur, today=today)
|
| 3250 |
+
# β THE NAMESPACE IS SETTLED BEFORE ANY GUARD RUNS, because a named connection that does not
|
| 3251 |
+
# resolve must be REFUSED rather than quietly served the default (R7).
|
| 3252 |
+
if rt is None:
|
| 3253 |
+
cid, ns = connection_id, (connection_id or None)
|
| 3254 |
+
else:
|
| 3255 |
+
cid, ns = connection_namespace(rt, connection_id)
|
| 3256 |
# ββ W53-T39 / R3 β THE ADMISSION IS A CREDENTIALS TEST, NOT A TENANT NAME.
|
| 3257 |
#
|
| 3258 |
# β THE OLD GATE'S REASON IS KEPT AND ONLY ITS MECHANISM IS REPLACED. It read
|
|
|
|
| 3268 |
# loop calls this every cycle and an exception is not a status. Refusing here would hand that
|
| 3269 |
# loop a raise for the one state it is meant to report. So a frozen workspace is admitted this
|
| 3270 |
# far and stopped by its own guard, three lines down, with its own words.
|
| 3271 |
+
# β THE UNNAMED CALL IS THE PRE-WAVE CALL, ARGUMENT FOR ARGUMENT. `verify_odoo_relational`'s
|
| 3272 |
+
# R3 negative control swaps `available` for a two-parameter lambda that restores the slug
|
| 3273 |
+
# allow-list; passing `connection_id=` unconditionally makes that swap raise TypeError instead
|
| 3274 |
+
# of refusing, and the control stops being a control. A named connection is the only case that
|
| 3275 |
+
# needs the third argument, so it is the only case that passes one.
|
| 3276 |
+
_admitted = (available(rt) if connection_id is None
|
| 3277 |
+
else available(rt, connection_id=connection_id))
|
| 3278 |
+
if not _admitted and not (rt is not None and frozen(rt)):
|
| 3279 |
raise Refused("no Odoo credential is configured for this workspace, so there is nothing "
|
| 3280 |
"behind these tables and the spawn would create empty locked databases. "
|
| 3281 |
"Add an Odoo credential in the Connectors panel, then run the sync again.")
|
|
|
|
| 3303 |
return {"tables": {}, "frozen": True,
|
| 3304 |
"note": "this workspace has disconnected Odoo; its databases are frozen as "
|
| 3305 |
"static data and are not being refreshed"}
|
| 3306 |
+
# ββ THE MIRROR BELONGS TO THE DEFAULT CONNECTION, AND IT IS NOT LENT OUT. There is one
|
| 3307 |
+
# DuckDB file per tenant (`harness/datastore` is a one-file-at-a-time process global, D-29),
|
| 3308 |
+
# and it holds the book of whichever Odoo the tenant syncs β the default connection's. Reading
|
| 3309 |
+
# it for connection 2 would write client A's rows into client B's database with nothing red
|
| 3310 |
+
# anywhere, which is the exact failure R7 exists to prevent. So a non-default connection plans
|
| 3311 |
+
# with NO cursor: its tables, fields and links are created, its rows are empty, and `limits`
|
| 3312 |
+
# says why per table (standing rule 1's second half).
|
| 3313 |
+
if ns is not None:
|
| 3314 |
+
cur = None
|
| 3315 |
+
elif cur is None:
|
| 3316 |
from harness import datastore
|
| 3317 |
cur = datastore.ro_con()
|
| 3318 |
+
built = plan(cur, rt=rt, connection_id=ns)
|
| 3319 |
# β W32-T15 / R9 β THE GRID PICKER, ENFORCED WHERE IT COUNTS. `apply_plan` writes only the
|
| 3320 |
# buckets present in `built`, so dropping an unticked one here is the whole of "unticking a
|
| 3321 |
# grid stops it materialising on the next sync". Done AFTER `plan` rather than inside it so
|
|
|
|
| 3326 |
# do that either (R10 keeps them). Silent data deletion behind a checkbox is not on offer.
|
| 3327 |
if rt is not None:
|
| 3328 |
keep = enabled_buckets(rt)
|
| 3329 |
+
# β THE KEYS ARE THIS CONNECTION'S. Reporting the bare keys while refreshing
|
| 3330 |
+
# connection 2 would name the DEFAULT connection's grids as the ones skipped.
|
| 3331 |
+
skipped = sorted(table_key_for(key, ns)
|
| 3332 |
+
for bucket, key, _l, _f in TABLES if bucket not in keep)
|
| 3333 |
for bucket, _key, _l, _f in TABLES:
|
| 3334 |
if bucket not in keep:
|
| 3335 |
built.pop(bucket, None)
|
|
|
|
| 3339 |
# Same rule as `skipped` below β R6's second sentence: what was deliberately not built (or no
|
| 3340 |
# longer built) SAYS SO, with the keys.
|
| 3341 |
plan_report = {}
|
| 3342 |
+
written = apply_plan(rt, built, username=username, today=today, report=plan_report,
|
| 3343 |
+
connection_id=ns)
|
| 3344 |
# ββ W49-T25 / C6 β THE SCHEMA CATALOGUE FOLLOWS THE CODE WITH NO MANUAL STEP. Runs AFTER the
|
| 3345 |
# tables are applied, so the snapshot describes a pass that actually landed. The two early
|
| 3346 |
# returns above are respected by construction: a tenant with no Odoo entitlement raised, and a
|
| 3347 |
# FROZEN workspace returned before reaching here, so a disconnected connector is not
|
| 3348 |
# re-recorded. See `_refresh_declared_schema` for why it writes the declared half only.
|
| 3349 |
declared_report = _refresh_declared_schema(rt)
|
| 3350 |
+
out = {"tables": written,
|
| 3351 |
+
**({"schemaDeclared": declared_report} if declared_report else {}),
|
| 3352 |
+
**({"retired": plan_report["retired"]} if plan_report.get("retired") else {}),
|
| 3353 |
+
# R6's second sentence: a set that was deliberately not built SAYS SO, with the keys.
|
| 3354 |
+
**({"skipped": skipped} if skipped else {}),
|
| 3355 |
+
**{bucket: len(built[bucket]) for bucket, _k, _l, _f in TABLES if bucket in built}}
|
| 3356 |
+
# β THE DEFAULT CONNECTION'S RETURN SHAPE DOES NOT MOVE BY ONE KEY. The two additions below
|
| 3357 |
+
# are reachable only on the namespaced path, because `verify_odoo_relational` asserts on this
|
| 3358 |
+
# dict as it stands for the default.
|
| 3359 |
+
if ns is not None:
|
| 3360 |
+
out["connection"] = cid
|
| 3361 |
+
if built.get("limits"):
|
| 3362 |
+
out["limits"] = built["limits"]
|
| 3363 |
+
return out
|
| 3364 |
+
|
| 3365 |
+
|
| 3366 |
+
def refresh_all(rt, tenant, username="automation", cur=None, today=None):
|
| 3367 |
+
"""Refresh EVERY Odoo connection this tenant holds, one at a time (R4 / R7 / C4).
|
| 3368 |
+
|
| 3369 |
+
ββ ONE CONNECTION'S FAILURE MUST NOT ABORT THE OTHERS. An agency with four clients cannot
|
| 3370 |
+
have client D's databases go unwritten because client B rotated a key this morning. A refusal
|
| 3371 |
+
or an exception is RECORDED AGAINST THE CONNECTION IT BELONGS TO and the loop continues β
|
| 3372 |
+
exactly as `refresh` reports a frozen workspace rather than raising, and for the same reason:
|
| 3373 |
+
this runs inside the boot rebuild and the resync loop, where an exception is not a status.
|
| 3374 |
+
|
| 3375 |
+
β THE DEFAULT CONNECTION'S NUMBERS STAY AT THE TOP LEVEL, so `main.py`'s log line and every
|
| 3376 |
+
other caller that reads `counts["invoices"]` keeps reading the same thing it read before. The
|
| 3377 |
+
per-connection map rides beside them under `connections`.
|
| 3378 |
+
|
| 3379 |
+
β ORDERED BY SLOT, which is the ordinal the tenant fixed when it added each connection, so the
|
| 3380 |
+
log line reads in the order the Connectors panel does. The ORDER is a slot question; the KEY
|
| 3381 |
+
is never one (see `table_key_for`).
|
| 3382 |
+
"""
|
| 3383 |
+
reports = {}
|
| 3384 |
+
default = default_connection_id(rt)
|
| 3385 |
+
rows = []
|
| 3386 |
+
try:
|
| 3387 |
+
import core.keychain as keychain
|
| 3388 |
+
rows = [r for r in keychain.list_entries(rt) if r.get("type") == "odoo"]
|
| 3389 |
+
except Exception: # noqa: BLE001
|
| 3390 |
+
rows = []
|
| 3391 |
+
order = [str(r.get("connection_id") or r.get("id"))
|
| 3392 |
+
for r in sorted(rows, key=lambda r: (int(r.get("slot") or 0), str(r.get("id"))))]
|
| 3393 |
+
# β NO KEYCHAIN CONNECTION AT ALL is the pre-wave posture, not an empty loop: tenant #0 runs
|
| 3394 |
+
# on its compiled env source, and `refresh` with no id is exactly the call it always made.
|
| 3395 |
+
if not order:
|
| 3396 |
+
order = [None]
|
| 3397 |
+
elif default and default not in order:
|
| 3398 |
+
order.insert(0, default)
|
| 3399 |
+
primary = None
|
| 3400 |
+
for entry_cid in order:
|
| 3401 |
+
named = None if (entry_cid is None or entry_cid == default) else entry_cid
|
| 3402 |
+
try:
|
| 3403 |
+
one = refresh(rt, tenant, username=username,
|
| 3404 |
+
cur=(cur if named is None else None),
|
| 3405 |
+
today=today, connection_id=named)
|
| 3406 |
+
except Exception as exc: # noqa: BLE001
|
| 3407 |
+
one = {"tables": {}, "failed": f"{type(exc).__name__}: {exc}"}
|
| 3408 |
+
reports[str(entry_cid or default or DEFAULT_CONNECTION)] = one
|
| 3409 |
+
if named is None and primary is None:
|
| 3410 |
+
primary = one
|
| 3411 |
+
return {**(primary or {"tables": {}}), "connections": reports}
|
api/routes_grid.py
CHANGED
|
@@ -2644,7 +2644,76 @@ def grid_hop_topics(session: Session = Depends(require_session)):
|
|
| 2644 |
_PRESET_LINK_MODULES = ("customer_data", "product_data")
|
| 2645 |
|
| 2646 |
|
| 2647 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2648 |
"""May this session open `key` at all? The SAME two gates `_pivot_side` applies, minus the rows.
|
| 2649 |
|
| 2650 |
β THE ROWS ARE THE POINT OF THE DIFFERENCE. `_pivot_side` calls `perm_scope.scoped_table`,
|
|
@@ -2655,23 +2724,30 @@ def _may_open(session: Session, key: str):
|
|
| 2655 |
β FAIL CLOSED. Any refusal, any unknown table, any error is False. A target this account may
|
| 2656 |
not open must not appear in the strip, because the tab would 403 on the first click and read as
|
| 2657 |
a broken product rather than as a permission.
|
| 2658 |
-
"""
|
| 2659 |
-
import core.perm_scope as perm_scope
|
| 2660 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2661 |
try:
|
| 2662 |
session.require(key)
|
| 2663 |
except HTTPException:
|
| 2664 |
return False
|
| 2665 |
except Exception: # noqa: BLE001
|
| 2666 |
return False
|
| 2667 |
-
|
| 2668 |
-
perm_scope.scoped_fields(session.user, key, st=session.runtime)
|
| 2669 |
-
except Exception: # noqa: BLE001
|
| 2670 |
-
return False
|
| 2671 |
-
return True
|
| 2672 |
|
| 2673 |
|
| 2674 |
-
def _source_fields(session: Session, table: str):
|
| 2675 |
"""The link-bearing field list for `table`, under this session's field wall.
|
| 2676 |
|
| 2677 |
ββ THE PRE-SET COLUMNS ARE NOT IN `scoped_fields` AND THAT IS THE TRAP THIS FUNCTION EXISTS
|
|
@@ -2682,13 +2758,12 @@ def _source_fields(session: Session, table: str):
|
|
| 2682 |
and look entirely correct doing it.
|
| 2683 |
β APPENDED, NOT MERGED BY KEY: a tenant cannot author a field on a registry module, so the two
|
| 2684 |
lists cannot collide, and a union keyed on `key` would hide that if they ever did.
|
| 2685 |
-
"""
|
| 2686 |
-
import core.perm_scope as perm_scope
|
| 2687 |
|
| 2688 |
-
|
| 2689 |
-
|
| 2690 |
-
|
| 2691 |
-
|
|
|
|
| 2692 |
if table in _PRESET_LINK_MODULES:
|
| 2693 |
try:
|
| 2694 |
import odoo_relational
|
|
@@ -2741,6 +2816,11 @@ def _ensure_odoo_spec():
|
|
| 2741 |
"""
|
| 2742 |
try:
|
| 2743 |
import odoo_relational
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2744 |
return bool(odoo_relational.register_connector_spec())
|
| 2745 |
except Exception: # noqa: BLE001
|
| 2746 |
return False
|
|
@@ -2773,7 +2853,7 @@ def _unwalled_fields(defs: dict, key: str):
|
|
| 2773 |
return fields
|
| 2774 |
|
| 2775 |
|
| 2776 |
-
def _relation_context(session: Session, table: str):
|
| 2777 |
"""`defs` plus the three callbacks `relations` needs, memoised for the life of ONE request.
|
| 2778 |
|
| 2779 |
β BOTH WALLS ARE MEMOISED. `_may_open` runs `session.require` plus `perm_scope.scoped_fields`
|
|
@@ -2789,6 +2869,29 @@ def _relation_context(session: Session, table: str):
|
|
| 2789 |
wall really did remove would be absent from both and get reported as an edge that never
|
| 2790 |
existed. Taking the union makes the unfiltered enumeration a superset by construction, so the
|
| 2791 |
diff is monotone and the only thing it can be wrong about is saying "unknown" too rarely.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2792 |
"""
|
| 2793 |
import core.user_tables as user_tables
|
| 2794 |
|
|
@@ -2796,17 +2899,31 @@ def _relation_context(session: Session, table: str):
|
|
| 2796 |
defs = dict(user_tables.all_defs(st=session.runtime) or {})
|
| 2797 |
except Exception: # noqa: BLE001
|
| 2798 |
defs = {}
|
| 2799 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2800 |
open_memo, field_memo, wide_memo = {}, {}, {}
|
| 2801 |
|
| 2802 |
def may_open(key):
|
| 2803 |
if key not in open_memo:
|
| 2804 |
-
open_memo[key] = _may_open(session, key)
|
| 2805 |
return open_memo[key]
|
| 2806 |
|
| 2807 |
def fields_for(key):
|
| 2808 |
if key not in field_memo:
|
| 2809 |
-
field_memo[key] = _source_fields(session, key)
|
| 2810 |
return field_memo[key]
|
| 2811 |
|
| 2812 |
def open_fields_for(key):
|
|
@@ -2870,14 +2987,22 @@ def related_refusals(session: Session, table: str, depth: int, entries: list, ct
|
|
| 2870 |
open_fields=ctx["open_fields_for"](table), open_fields_for=ctx["open_fields_for"])
|
| 2871 |
|
| 2872 |
|
| 2873 |
-
#: β THE HTTP STATUS EACH
|
| 2874 |
#: same status the top-of-route `_may_open` gate on `table` itself already uses; a path that never
|
| 2875 |
#: existed stays the 400 this route already answered with, unchanged; and "every hop was open and
|
| 2876 |
#: there is nothing there" is a 404, because it is neither a bad request nor a refusal.
|
| 2877 |
#: β `no_related_rows` cannot be reached from THIS route's pin branch (a path that resolves is
|
| 2878 |
#: served, so the diff never reports it) and is mapped anyway, because `diagnose_path` is the one
|
| 2879 |
#: diagnosis and the row door will raise the same bag from another ticket's fence.
|
| 2880 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2881 |
"no_related_rows": 404, "unknown_via": 400}
|
| 2882 |
|
| 2883 |
|
|
@@ -2888,10 +3013,19 @@ def _refusal_error(diag: dict):
|
|
| 2888 |
SIBLINGS inside `error`. C3 asks for *"the ENUMERATED candidates with their join columns and
|
| 2889 |
the exact retry strings, not prose"*, and a client cannot draw a retry button out of an English
|
| 2890 |
clause, so the structure rides beside the sentence rather than inside it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2891 |
"""
|
| 2892 |
exc = err(_REFUSAL_STATUS.get(str(diag.get("code")), 400), str(diag.get("code")),
|
| 2893 |
str(diag.get("message") or ""))
|
| 2894 |
-
for key in ("table", "hop", "path", "candidates"):
|
| 2895 |
if diag.get(key) not in (None, ""):
|
| 2896 |
exc.detail["error"][key] = diag[key]
|
| 2897 |
return exc
|
|
@@ -2947,7 +3081,12 @@ def grid_related(table: str,
|
|
| 2947 |
table = str(table or "").strip()
|
| 2948 |
if not table:
|
| 2949 |
raise err(400, "bad_table", "name the database to list relations for")
|
| 2950 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2951 |
raise err(403, "not_permitted",
|
| 2952 |
f"your account may not open '{table}', so it cannot be told what that database "
|
| 2953 |
f"is related to. Ask an administrator for access to it")
|
|
@@ -2963,7 +3102,7 @@ def grid_related(table: str,
|
|
| 2963 |
f"{relations.MAX_DEPTH} (those plus everything one further named hop away), and "
|
| 2964 |
f"this request asked for {depth}. Ask for 1 or {relations.MAX_DEPTH}")
|
| 2965 |
|
| 2966 |
-
ctx = _relation_context(session, table)
|
| 2967 |
entries = related_path_entries(session, table, depth, ctx)
|
| 2968 |
if via:
|
| 2969 |
wanted = [str(v) for v in via if str(v or "").strip()]
|
|
|
|
| 2644 |
_PRESET_LINK_MODULES = ("customer_data", "product_data")
|
| 2645 |
|
| 2646 |
|
| 2647 |
+
def _register_retired_tables():
|
| 2648 |
+
"""Push `odoo_relational.RETIRED_KEYS` down into `core.relations`, at import and per request.
|
| 2649 |
+
|
| 2650 |
+
ββ W54-T37 / C5 / INSTRUCTION 22 - THIS IS WHY THE OWNER SAW A PERMISSION WALL ABOUT A
|
| 2651 |
+
DATABASE THAT DOES NOT EXIST. `ut_odoo_customers` and `ut_odoo_products` are RETIRED: popped
|
| 2652 |
+
from every tenant document on every sync, replaced by the `customer_data` / `product_data`
|
| 2653 |
+
registry modules, and still DESCRIBED by the connector spec, which is legitimate (a spec
|
| 2654 |
+
describes a shape). The relation enumeration therefore minted edges at them, `_may_open` below
|
| 2655 |
+
failed closed on a key it could not resolve, and `relations.forbidden_table_refusal` told the
|
| 2656 |
+
reader to ask an administrator for access to a table nobody can grant.
|
| 2657 |
+
|
| 2658 |
+
β ONE DECLARATION, PUSHED, NEVER COPIED. `odoo_relational.RETIRED_KEYS` stays the only place
|
| 2659 |
+
the two keys are named; `core` cannot read it (`core` never imports up), so the app layer hands
|
| 2660 |
+
it down exactly as `core.user_tables.register_connected_prefix` is handed its prefixes. Copying
|
| 2661 |
+
the keys into `core` would make a second declaration of one fact.
|
| 2662 |
+
|
| 2663 |
+
β GUARDED, AND CALLED TWICE FOR THE SAME REASON `_ensure_odoo_spec` exists: a process that
|
| 2664 |
+
cannot import `odoo_relational` or `core` must still START, and one that imports them later
|
| 2665 |
+
must still get the right answer. Registration is idempotent (it is a set union) and returns the
|
| 2666 |
+
whole registered set, so a caller can assert what it just joined.
|
| 2667 |
+
"""
|
| 2668 |
+
try:
|
| 2669 |
+
import odoo_relational
|
| 2670 |
+
import core.relations as relations
|
| 2671 |
+
return relations.register_retired_tables(*odoo_relational.RETIRED_KEYS)
|
| 2672 |
+
except Exception: # noqa: BLE001
|
| 2673 |
+
return frozenset()
|
| 2674 |
+
|
| 2675 |
+
|
| 2676 |
+
#: The import-time push. β Its VALUE is not read anywhere on the request path: it is here so the
|
| 2677 |
+
#: registration has happened before the first listing, and so an operator can see what landed.
|
| 2678 |
+
RETIRED_TABLES_AT_IMPORT = _register_retired_tables()
|
| 2679 |
+
|
| 2680 |
+
|
| 2681 |
+
def _walled_fields(session: Session, key: str, st=None, memo: dict = None):
|
| 2682 |
+
"""`perm_scope.scoped_fields(key)`, or **None** when the field wall REFUSED β memoised.
|
| 2683 |
+
|
| 2684 |
+
ββ W54-T39 β THIS FUNCTION EXISTS BECAUSE THE SAME WALL WAS BEING ASKED TWICE PER TABLE AND
|
| 2685 |
+
THE ANSWER WAS THROWN AWAY BOTH TIMES. `_may_open` below wanted only the verdict and
|
| 2686 |
+
`_source_fields` below wanted only the list; each called `scoped_fields` itself, so a listing
|
| 2687 |
+
that touches six tables paid for TWELVE wall resolutions. MEASURED against tenant #0 on
|
| 2688 |
+
2026-09-06: one `scoped_fields` is ~135 ms on a `ut_*` grid and ~550 ms on `product_data`, so
|
| 2689 |
+
the duplicate pass alone was more than half of the 3.5 s the record rail took to open.
|
| 2690 |
+
|
| 2691 |
+
β THE VERDICT AND THE LIST ARE ONE ANSWER, AND THEY MUST STAY ONE CALL. Resolving them
|
| 2692 |
+
separately is not merely slow, it is two readings of one wall that can disagree if a grant
|
| 2693 |
+
changes between them β the [[one-question-two-normalizers]] shape, on a permission.
|
| 2694 |
+
β `None` RATHER THAN `[]` IS THE WHOLE POINT OF THE RETURN TYPE. A table the wall refuses and
|
| 2695 |
+
a table with no columns are different facts, and `_may_open` is the caller that has to tell
|
| 2696 |
+
them apart; collapsing both to an empty list would hide every refused target as an empty one.
|
| 2697 |
+
|
| 2698 |
+
β FAIL CLOSED, exactly as before: any exception at all is a refusal, never a widened answer.
|
| 2699 |
+
β `memo` IS ONE REQUEST'S, handed down by `_relation_context`. Passing None simply means no
|
| 2700 |
+
memo, which is what every caller outside a listing pass wants.
|
| 2701 |
+
"""
|
| 2702 |
+
if memo is not None and key in memo:
|
| 2703 |
+
return memo[key]
|
| 2704 |
+
import core.perm_scope as perm_scope
|
| 2705 |
+
|
| 2706 |
+
try:
|
| 2707 |
+
answer = list(perm_scope.scoped_fields(
|
| 2708 |
+
session.user, key, st=session.runtime if st is None else st) or ())
|
| 2709 |
+
except Exception: # noqa: BLE001
|
| 2710 |
+
answer = None
|
| 2711 |
+
if memo is not None:
|
| 2712 |
+
memo[key] = answer
|
| 2713 |
+
return answer
|
| 2714 |
+
|
| 2715 |
+
|
| 2716 |
+
def _may_open(session: Session, key: str, st=None, memo: dict = None):
|
| 2717 |
"""May this session open `key` at all? The SAME two gates `_pivot_side` applies, minus the rows.
|
| 2718 |
|
| 2719 |
β THE ROWS ARE THE POINT OF THE DIFFERENCE. `_pivot_side` calls `perm_scope.scoped_table`,
|
|
|
|
| 2724 |
β FAIL CLOSED. Any refusal, any unknown table, any error is False. A target this account may
|
| 2725 |
not open must not appear in the strip, because the tab would 403 on the first click and read as
|
| 2726 |
a broken product rather than as a permission.
|
|
|
|
|
|
|
| 2727 |
|
| 2728 |
+
ββ AND IT STILL CANNOT TELL "ABSENT" FROM "REFUSED", WHICH IS CORRECT AND IS **NOT** WHAT
|
| 2729 |
+
INSTRUCTION 22 ASKED TO CHANGE. Conflating "not granted" with "could not be read" is deliberate
|
| 2730 |
+
and the refusal sentence says both out loud. What was missing is a third case that never
|
| 2731 |
+
belonged here at all: a table this deployment does not HAVE. That is answered upstream, by
|
| 2732 |
+
`_register_retired_tables` above keeping such a key from ever being enumerated as an edge
|
| 2733 |
+
target, and by `relations.diagnose_path` naming it when a request asks for one anyway.
|
| 2734 |
+
|
| 2735 |
+
β W54-T39 β THE SECOND GATE IS NOW ASKED THROUGH `_walled_fields`, WHICH IS THE SAME QUESTION
|
| 2736 |
+
AND THE SAME FAIL-CLOSED ANSWER, shared with `_source_fields` so one table costs one wall
|
| 2737 |
+
resolution instead of two. β THE GRANT GATE STILL RIDES `session.require`, which resolves
|
| 2738 |
+
against the session's OWN runtime rather than any handle passed in: a lent snapshot may make a
|
| 2739 |
+
read cheaper and must never be able to make a grant broader.
|
| 2740 |
+
"""
|
| 2741 |
try:
|
| 2742 |
session.require(key)
|
| 2743 |
except HTTPException:
|
| 2744 |
return False
|
| 2745 |
except Exception: # noqa: BLE001
|
| 2746 |
return False
|
| 2747 |
+
return _walled_fields(session, key, st=st, memo=memo) is not None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2748 |
|
| 2749 |
|
| 2750 |
+
def _source_fields(session: Session, table: str, st=None, memo: dict = None):
|
| 2751 |
"""The link-bearing field list for `table`, under this session's field wall.
|
| 2752 |
|
| 2753 |
ββ THE PRE-SET COLUMNS ARE NOT IN `scoped_fields` AND THAT IS THE TRAP THIS FUNCTION EXISTS
|
|
|
|
| 2758 |
and look entirely correct doing it.
|
| 2759 |
β APPENDED, NOT MERGED BY KEY: a tenant cannot author a field on a registry module, so the two
|
| 2760 |
lists cannot collide, and a union keyed on `key` would hide that if they ever did.
|
|
|
|
|
|
|
| 2761 |
|
| 2762 |
+
β W54-T39 β A REFUSED WALL STILL READS AS `[]` HERE, unchanged. `_walled_fields` answers None
|
| 2763 |
+
for that case so `_may_open` can tell it from an empty table; this door has never needed the
|
| 2764 |
+
distinction and must not start reporting one, because a refusal is `_may_open`'s word.
|
| 2765 |
+
"""
|
| 2766 |
+
fields = list(_walled_fields(session, table, st=st, memo=memo) or ())
|
| 2767 |
if table in _PRESET_LINK_MODULES:
|
| 2768 |
try:
|
| 2769 |
import odoo_relational
|
|
|
|
| 2816 |
"""
|
| 2817 |
try:
|
| 2818 |
import odoo_relational
|
| 2819 |
+
# β BESIDE THE SPEC REGISTRATION AND FOR ITS REASON. Both are pushes from this layer into
|
| 2820 |
+
# `core`, both are idempotent, and both are wrong to skip in a process that imported this
|
| 2821 |
+
# module before `platform/` was on the path. Registering the retired keys HERE as well as
|
| 2822 |
+
# at import is what makes the enumeration below correct in either process shape.
|
| 2823 |
+
_register_retired_tables()
|
| 2824 |
return bool(odoo_relational.register_connector_spec())
|
| 2825 |
except Exception: # noqa: BLE001
|
| 2826 |
return False
|
|
|
|
| 2853 |
return fields
|
| 2854 |
|
| 2855 |
|
| 2856 |
+
def _relation_context(session: Session, table: str, memo: dict = None):
|
| 2857 |
"""`defs` plus the three callbacks `relations` needs, memoised for the life of ONE request.
|
| 2858 |
|
| 2859 |
β BOTH WALLS ARE MEMOISED. `_may_open` runs `session.require` plus `perm_scope.scoped_fields`
|
|
|
|
| 2869 |
wall really did remove would be absent from both and get reported as an edge that never
|
| 2870 |
existed. Taking the union makes the unfiltered enumeration a superset by construction, so the
|
| 2871 |
diff is monotone and the only thing it can be wrong about is saying "unknown" too rarely.
|
| 2872 |
+
|
| 2873 |
+
ββ W54-T39 β **THE DEFINITIONS ARE READ ONCE AND THEN LENT, WHICH IS WHERE THE RECORD RAIL'S
|
| 2874 |
+
THREE AND A HALF SECONDS WERE.** `perm_scope.scoped_fields` reaches `user_tables.all_defs`
|
| 2875 |
+
for every table it is asked about, and `all_defs` is a store projection: one Neon round trip,
|
| 2876 |
+
MEASURED at ~135 ms each on 2026-09-06. A depth-2 listing off `customer_data` asked about six
|
| 2877 |
+
tables and paid that round trip TWELVE times for the identical document this function had
|
| 2878 |
+
already read on its first line. `user_tables.lend` exists for exactly this β `nav_entries` has
|
| 2879 |
+
paired `all_defs` with it since W32-T02 β so the handle below serves that one snapshot to
|
| 2880 |
+
every wall resolution in the pass and each `ut_*` table's `scoped_fields` drops from ~135 ms
|
| 2881 |
+
to 0.
|
| 2882 |
+
β IT IS A READ HANDLE AND IT NEVER REACHES A WRITE. `lend_defs`' own note is the rule: every
|
| 2883 |
+
value it serves is a `_Projected`, so a caller that wanted rows gets a loud `KeyError` rather
|
| 2884 |
+
than a silently empty grid β and `scoped_fields` is a `want_rows=False` door by construction.
|
| 2885 |
+
Nothing here is handed to a mutation; `grid_related` is a GET.
|
| 2886 |
+
β IT CANNOT WIDEN A WALL, and that was checked rather than assumed: the lent handle serves
|
| 2887 |
+
only `user_tables` and (lazily, once) `object_shares`, every other store key falls through to
|
| 2888 |
+
the real runtime, and `session.require` is not given it at all. MEASURED 2026-09-06 across all
|
| 2889 |
+
ten of tenant #0's databases: `scoped_fields` under the lent handle returned a field list
|
| 2890 |
+
EQUAL, key for key and value for value, to the one it returned under the bare runtime.
|
| 2891 |
+
|
| 2892 |
+
β AND THE SNAPSHOT IS THE POINT, not a side effect. One listing answers about one set of
|
| 2893 |
+
definitions; re-reading them mid-pass could enumerate an edge from a table that vanished two
|
| 2894 |
+
hops ago and report the inconsistency as a refusal.
|
| 2895 |
"""
|
| 2896 |
import core.user_tables as user_tables
|
| 2897 |
|
|
|
|
| 2899 |
defs = dict(user_tables.all_defs(st=session.runtime) or {})
|
| 2900 |
except Exception: # noqa: BLE001
|
| 2901 |
defs = {}
|
| 2902 |
+
try:
|
| 2903 |
+
lent = user_tables.lend(session.runtime, **{user_tables.STORE_KEY: defs})
|
| 2904 |
+
except Exception: # noqa: BLE001
|
| 2905 |
+
# A store handle too old to lend is CORRECT-but-slow, exactly as `all_defs`' own fallback
|
| 2906 |
+
# is: the pass simply goes back to paying a round trip per wall resolution.
|
| 2907 |
+
lent = session.runtime
|
| 2908 |
+
|
| 2909 |
+
# β ONE WALL RESOLUTION PER TABLE, SHARED BY BOTH CALLBACKS. `open_memo` and `field_memo`
|
| 2910 |
+
# below still memoise their own composition (the grant gate, the pre-set link append); this is
|
| 2911 |
+
# the `scoped_fields` answer underneath both of them, which is the expensive part.
|
| 2912 |
+
# β THE CALLER MAY HAND ITS OWN IN, and `grid_related` does. That route has to answer 403 for
|
| 2913 |
+
# the SOURCE table before it lists anything, so it resolves that one wall a moment before this
|
| 2914 |
+
# function is built; without the shared bag the source table would be resolved twice, which on
|
| 2915 |
+
# `product_data` is a second ~550 ms for an answer already in hand.
|
| 2916 |
+
wall_memo = memo if memo is not None else {}
|
| 2917 |
open_memo, field_memo, wide_memo = {}, {}, {}
|
| 2918 |
|
| 2919 |
def may_open(key):
|
| 2920 |
if key not in open_memo:
|
| 2921 |
+
open_memo[key] = _may_open(session, key, st=lent, memo=wall_memo)
|
| 2922 |
return open_memo[key]
|
| 2923 |
|
| 2924 |
def fields_for(key):
|
| 2925 |
if key not in field_memo:
|
| 2926 |
+
field_memo[key] = _source_fields(session, key, st=lent, memo=wall_memo)
|
| 2927 |
return field_memo[key]
|
| 2928 |
|
| 2929 |
def open_fields_for(key):
|
|
|
|
| 2987 |
open_fields=ctx["open_fields_for"](table), open_fields_for=ctx["open_fields_for"])
|
| 2988 |
|
| 2989 |
|
| 2990 |
+
#: β THE HTTP STATUS EACH REFUSAL CODE EARNS ON A **PIN**. The two permission answers are 403, the
|
| 2991 |
#: same status the top-of-route `_may_open` gate on `table` itself already uses; a path that never
|
| 2992 |
#: existed stays the 400 this route already answered with, unchanged; and "every hop was open and
|
| 2993 |
#: there is nothing there" is a 404, because it is neither a bad request nor a refusal.
|
| 2994 |
#: β `no_related_rows` cannot be reached from THIS route's pin branch (a path that resolves is
|
| 2995 |
#: served, so the diff never reports it) and is mapped anyway, because `diagnose_path` is the one
|
| 2996 |
#: diagnosis and the row door will raise the same bag from another ticket's fence.
|
| 2997 |
+
#: ββ W54-T37 / C5 - `retired_target` IS A **404**, AND IT IS DELIBERATELY NOT A 403. The whole
|
| 2998 |
+
#: complaint in instruction 22 is a permission status on a table that does not exist, so any 4xx
|
| 2999 |
+
#: in the permission family would repeat the lie in a header. β 410 Gone is the more precise word
|
| 3000 |
+
#: for a database that was retired rather than never present, and it is NOT used: the client half
|
| 3001 |
+
#: of this contract is another lane's, every existing handler here branches on the CODE rather than
|
| 3002 |
+
#: the status, and introducing the one status nothing in this app has ever returned would risk a
|
| 3003 |
+
#: fetch wrapper treating it as a transport failure. The code carries the meaning; the status only
|
| 3004 |
+
#: has to be honest.
|
| 3005 |
+
_REFUSAL_STATUS = {"forbidden_table": 403, "hop_filtered": 403, "retired_target": 404,
|
| 3006 |
"no_related_rows": 404, "unknown_via": 400}
|
| 3007 |
|
| 3008 |
|
|
|
|
| 3013 |
SIBLINGS inside `error`. C3 asks for *"the ENUMERATED candidates with their join columns and
|
| 3014 |
the exact retry strings, not prose"*, and a client cannot draw a retry button out of an English
|
| 3015 |
clause, so the structure rides beside the sentence rather than inside it.
|
| 3016 |
+
|
| 3017 |
+
ββ W54-T40 β `detail` IS COPIED TOO, AND IT IS THE ROW W54-T38 BOOKED. C5 gives every refusal
|
| 3018 |
+
a SHORT `message` and a long `detail`, and the client renders the pair as a `<details>` with the
|
| 3019 |
+
sentence in the summary; this function copied four keys and dropped the diagnosis, so a refusal
|
| 3020 |
+
arriving through THIS door rendered as the sentence alone while the identical refusal arriving
|
| 3021 |
+
through the listing kept its disclosure. One key, and the two doors stop disagreeing about how
|
| 3022 |
+
much of one contract they carry.
|
| 3023 |
+
β A BAG WITH NO DIAGNOSIS STILL RENDERS AS THE SENTENCE ALONE: the loop copies a key only when
|
| 3024 |
+
the bag carries one, so nothing gains a caret with nothing behind it.
|
| 3025 |
"""
|
| 3026 |
exc = err(_REFUSAL_STATUS.get(str(diag.get("code")), 400), str(diag.get("code")),
|
| 3027 |
str(diag.get("message") or ""))
|
| 3028 |
+
for key in ("table", "hop", "path", "candidates", "detail"):
|
| 3029 |
if diag.get(key) not in (None, ""):
|
| 3030 |
exc.detail["error"][key] = diag[key]
|
| 3031 |
return exc
|
|
|
|
| 3081 |
table = str(table or "").strip()
|
| 3082 |
if not table:
|
| 3083 |
raise err(400, "bad_table", "name the database to list relations for")
|
| 3084 |
+
# β W54-T39 β THE GATE IS UNMOVED AND UNCHANGED; only its ANSWER is kept. `wall_memo` rides
|
| 3085 |
+
# into `_relation_context` below so this table's field wall, which the 403 has just resolved
|
| 3086 |
+
# at full price, is not resolved a second time three lines later. The order is untouched: the
|
| 3087 |
+
# caller's own access is still the first thing this route decides.
|
| 3088 |
+
wall_memo = {}
|
| 3089 |
+
if not _may_open(session, table, memo=wall_memo):
|
| 3090 |
raise err(403, "not_permitted",
|
| 3091 |
f"your account may not open '{table}', so it cannot be told what that database "
|
| 3092 |
f"is related to. Ask an administrator for access to it")
|
|
|
|
| 3102 |
f"{relations.MAX_DEPTH} (those plus everything one further named hop away), and "
|
| 3103 |
f"this request asked for {depth}. Ask for 1 or {relations.MAX_DEPTH}")
|
| 3104 |
|
| 3105 |
+
ctx = _relation_context(session, table, memo=wall_memo)
|
| 3106 |
entries = related_path_entries(session, table, depth, ctx)
|
| 3107 |
if via:
|
| 3108 |
wanted = [str(v) for v in via if str(v or "").strip()]
|
api/routes_keychain.py
CHANGED
|
@@ -99,8 +99,10 @@ SCOPE_KEY = "keychain_scopes"
|
|
| 99 |
|
| 100 |
#: ββ THE TYPES A WHOLE WORKSPACE READS THROUGH, WHICH THEREFORE CANNOT BE PERSONAL.
|
| 101 |
#:
|
| 102 |
-
#: `keychain.odoo_creds` and `keychain.meta_creds` both resolve to *
|
| 103 |
-
#:
|
|
|
|
|
|
|
| 104 |
#: answered from. So a member storing a personal Odoo key would not get "their own Odoo": they
|
| 105 |
#: would silently become the credential the entire workspace's databases are built from, which is
|
| 106 |
#: a credential elevation wearing a scope picker.
|
|
@@ -112,7 +114,8 @@ SCOPE_KEY = "keychain_scopes"
|
|
| 112 |
#: (whose own `TENANT_WIDE_TYPES` already carried three entries, `amazon_sp` included, "JOINED IN
|
| 113 |
#: WAVE 52" by its own header comment). Until this line, a non-admin could POST a PERSONAL
|
| 114 |
#: `amazon_sp` entry through THIS door β `add_key`'s refusal only fires for a type in this tuple β
|
| 115 |
-
#: while `core/keychain
|
|
|
|
| 116 |
#: the tenant's Amazon credential. So the write succeeded, the UI told the member they had
|
| 117 |
#: connected their own Amazon, and the resolver silently served nothing for it: not the elevation
|
| 118 |
#: (the resolver-side guard held), but a door that stores a credential the product then ignores,
|
|
@@ -201,13 +204,30 @@ def visible_entries(rt, uname, is_admin=False):
|
|
| 201 |
owner = str(e.get("createdBy") or "")
|
| 202 |
if not may_see(scope, owner, uname):
|
| 203 |
continue
|
| 204 |
-
row = {**e, "scope": scope, "owner": owner}
|
| 205 |
if not (is_admin or str(owner) == str(uname)):
|
| 206 |
row["preview"] = ""
|
| 207 |
out.append(row)
|
| 208 |
return out
|
| 209 |
|
| 210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
def _write_scope(rt, entry_id, scope, owner):
|
| 212 |
"""Persist one entry's scope. A `business` entry CLEARS its row rather than writing the
|
| 213 |
default, so the store holds one spelling of the common case."""
|
|
@@ -235,11 +255,140 @@ def _kc():
|
|
| 235 |
return keychain
|
| 236 |
|
| 237 |
|
| 238 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
"""`(source, flag_key)` β which source would serve this tenant's Odoo queries, in both the
|
| 240 |
shapes this module needs: the display string (`env` / `keychain:<id>`) and the key the pause
|
| 241 |
flag is stored under.
|
| 242 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
β D-10 (wave 24): THE RESOLUTION ITSELF NOW LIVES IN ONE PLACE, `TenantRuntime.odoo_flag_key`,
|
| 244 |
beside the `odoo_source()` it must agree with. This function had its own copy of the same
|
| 245 |
three rules β first unlocked keychain odoo entry, else env for tenant #0, else nothing β and
|
|
@@ -247,7 +396,7 @@ def _resolved_odoo_key(rt):
|
|
| 247 |
against another, freezing nothing while the UI reports success. The two SHAPES stay here
|
| 248 |
because they are this module's presentation concern; the DECISION does not.
|
| 249 |
"""
|
| 250 |
-
flag_key = rt.odoo_flag_key()
|
| 251 |
if not flag_key:
|
| 252 |
return None, None
|
| 253 |
return ("env" if flag_key == _ENV_ODOO_FLAG_KEY else f"keychain:{flag_key}"), flag_key
|
|
@@ -559,7 +708,16 @@ def list_keychain(session: Session = Depends(require_session)):
|
|
| 559 |
#: the vocabulary and the permission, so the client renders a picker it can honour
|
| 560 |
#: rather than offering an option the server will refuse (R4: business is admin-only).
|
| 561 |
"scopes": list(SCOPES), "canBusiness": bool(session.admin),
|
| 562 |
-
"tenantWideTypes": list(TENANT_WIDE_TYPES)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
|
| 564 |
|
| 565 |
@router.post("/admin/keychain", status_code=201)
|
|
@@ -572,18 +730,44 @@ def add_key(body: dict = Body(default=None), session: Session = Depends(require_
|
|
| 572 |
if scope is None:
|
| 573 |
raise err(400, "bad_scope",
|
| 574 |
f"scope must be one of {', '.join(SCOPES)}")
|
| 575 |
-
if scope == "business" and not session.admin:
|
| 576 |
-
raise err(403, "not_admin",
|
| 577 |
-
"a business-wide connection applies to everyone in this workspace, so only an "
|
| 578 |
-
"administrator can create one. You can add it as a personal connection instead.")
|
| 579 |
etype = str(body.get("type") or "").strip().lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 580 |
if scope == "personal" and etype in TENANT_WIDE_TYPES:
|
| 581 |
# β REPORTED, NOT COERCED (W30/R6's second sentence). See TENANT_WIDE_TYPES above: this
|
| 582 |
# credential is what the WHOLE workspace's databases are built from, so "personal" would
|
| 583 |
# be a label on a tenant-wide key rather than a boundary around it.
|
|
|
|
|
|
|
|
|
|
| 584 |
raise err(400, "scope_not_available",
|
| 585 |
f"a {etype} connection is what this whole workspace's databases are read "
|
| 586 |
-
f"through, so it is always business-wide
|
| 587 |
f"An administrator can add it for everyone.")
|
| 588 |
try:
|
| 589 |
row = kc.add_entry(session.runtime, body.get("label"), body.get("type"),
|
|
@@ -618,34 +802,69 @@ def add_key(body: dict = Body(default=None), session: Session = Depends(require_
|
|
| 618 |
raise err(503, "store_unavailable",
|
| 619 |
"the key was not saved β its sharing setting could not be stored, so "
|
| 620 |
"nothing was kept. Try again.")
|
| 621 |
-
return {"entry": {**row, "scope": scope, "owner": session.uname}}
|
| 622 |
|
| 623 |
|
| 624 |
@router.put("/admin/keychain/{entry_id}")
|
| 625 |
def update_key(entry_id: str, body: dict = Body(default=None),
|
| 626 |
session: Session = Depends(require_session)):
|
| 627 |
-
"""Contract C1's scope door
|
| 628 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 629 |
row = _own_row(session, entry_id)
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
"
|
| 636 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 637 |
if not _may_touch(session, row):
|
| 638 |
raise err(403, "not_yours", "this connection is not yours to change")
|
| 639 |
-
if scope == "personal" and str(row.get("type") or "") in TENANT_WIDE_TYPES:
|
| 640 |
raise err(400, "scope_not_available",
|
| 641 |
f"a {row.get('type')} connection is what this whole workspace's databases are "
|
| 642 |
f"read through, so it is always business-wide.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 643 |
owner = row.get("owner") or session.uname
|
|
|
|
|
|
|
| 644 |
try:
|
| 645 |
_write_scope(session.runtime, entry_id, scope, owner)
|
| 646 |
except Exception:
|
| 647 |
raise err(503, "store_unavailable", "the change was not saved β try again")
|
| 648 |
-
return {"entry": {**row, "
|
|
|
|
| 649 |
|
| 650 |
|
| 651 |
@router.delete("/admin/keychain/{entry_id}")
|
|
@@ -710,21 +929,27 @@ def connectors(session: Session = Depends(require_session)):
|
|
| 710 |
# every colleague's personal connection on the screen next door to the one that hides them.
|
| 711 |
entries = visible_entries(session.runtime, session.uname, bool(session.admin))
|
| 712 |
# R3 cutover (2026-08-04): which source would actually serve this tenant's Odoo queries β
|
| 713 |
-
# mirrors TenantRuntime.odoo_source() exactly:
|
| 714 |
-
# for tenant #0 only, else nothing (fail closed β never another tenant's
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 715 |
# β W32-T11: computed over the TENANT's entries, not over `entries` above. "Which source
|
| 716 |
# serves this workspace" is one fact for everybody, and deriving it from a per-USER list would
|
| 717 |
# make the answer depend on who opened the pane. Personal entries are excluded for the same
|
| 718 |
# reason `TENANT_WIDE_TYPES` refuses them: they must never become the workspace's source.
|
| 719 |
-
|
| 720 |
-
first_odoo = next((e["id"] for e in kc.list_entries(session.runtime)
|
| 721 |
-
if e["type"] == "odoo"
|
| 722 |
-
and entry_scope(session.runtime, e["id"], _scopes)[0] != "personal"), None)
|
| 723 |
# β W32-T10 β the env leg goes through `env_odoo_available` now, so this route and the
|
| 724 |
# connectors DIRECTORY answer "does the environment serve this tenant?" with one function
|
| 725 |
# instead of two spellings that agreed until a second tenant signed in.
|
| 726 |
-
if
|
| 727 |
-
resolved = f"keychain:{
|
| 728 |
elif env_odoo_available(session.runtime):
|
| 729 |
resolved = "env"
|
| 730 |
else:
|
|
@@ -811,14 +1036,31 @@ def _rel():
|
|
| 811 |
return rel
|
| 812 |
|
| 813 |
|
| 814 |
-
def _odoo_entry(session):
|
| 815 |
"""The keychain entry SERVING this tenant's Odoo, or None when the environment is (or nothing
|
| 816 |
-
is). Business-scoped by construction β `TENANT_WIDE_TYPES` refuses a personal one.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 817 |
kc = _kc()
|
|
|
|
|
|
|
|
|
|
| 818 |
scopes = _scope_rows(session.runtime)
|
| 819 |
for e in kc.list_entries(session.runtime):
|
| 820 |
-
if e["
|
| 821 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 822 |
return None
|
| 823 |
|
| 824 |
|
|
@@ -978,10 +1220,14 @@ def _rewrite_server_db(session, server_db):
|
|
| 978 |
So this is add-then-delete through the module's own doors, with the side rows (pause flag,
|
| 979 |
scope) carried across because they are keyed by ENTRY ID.
|
| 980 |
β THE ORDER IS DELIBERATE AND THE WINDOW IS REAL: for the moment between the add and the
|
| 981 |
-
delete this tenant has TWO odoo entries
|
| 982 |
-
|
| 983 |
-
|
| 984 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 985 |
"""
|
| 986 |
kc = _kc()
|
| 987 |
entry = _odoo_entry(session)
|
|
|
|
| 99 |
|
| 100 |
#: ββ THE TYPES A WHOLE WORKSPACE READS THROUGH, WHICH THEREFORE CANNOT BE PERSONAL.
|
| 101 |
#:
|
| 102 |
+
#: `keychain.odoo_creds` and `keychain.meta_creds` both resolve to *a connection of that type* for
|
| 103 |
+
#: the TENANT β the one a caller NAMES, or the tenant's designated default when none is named
|
| 104 |
+
#: (W54-T45 / R4; it was "the first entry of that type" before) β that is what spawns
|
| 105 |
+
#: `ut_odoo_*` / `ut_meta_*` and what every measure column is
|
| 106 |
#: answered from. So a member storing a personal Odoo key would not get "their own Odoo": they
|
| 107 |
#: would silently become the credential the entire workspace's databases are built from, which is
|
| 108 |
#: a credential elevation wearing a scope picker.
|
|
|
|
| 114 |
#: (whose own `TENANT_WIDE_TYPES` already carried three entries, `amazon_sp` included, "JOINED IN
|
| 115 |
#: WAVE 52" by its own header comment). Until this line, a non-admin could POST a PERSONAL
|
| 116 |
#: `amazon_sp` entry through THIS door β `add_key`'s refusal only fires for a type in this tuple β
|
| 117 |
+
#: while `core/keychain`'s shared resolver (`_first_creds` then, `_creds_for` since W54-T45)
|
| 118 |
+
#: already skipped a personal `amazon_sp` entry when resolving
|
| 119 |
#: the tenant's Amazon credential. So the write succeeded, the UI told the member they had
|
| 120 |
#: connected their own Amazon, and the resolver silently served nothing for it: not the elevation
|
| 121 |
#: (the resolver-side guard held), but a door that stores a credential the product then ignores,
|
|
|
|
| 204 |
owner = str(e.get("createdBy") or "")
|
| 205 |
if not may_see(scope, owner, uname):
|
| 206 |
continue
|
| 207 |
+
row = {**_identified(e), "scope": scope, "owner": owner}
|
| 208 |
if not (is_admin or str(owner) == str(uname)):
|
| 209 |
row["preview"] = ""
|
| 210 |
out.append(row)
|
| 211 |
return out
|
| 212 |
|
| 213 |
|
| 214 |
+
#: ββ W54-T44 / R4 / CONTRACT C4 β THE IDENTITY, IN THE WIRE'S OWN SPELLING.
|
| 215 |
+
#:
|
| 216 |
+
#: `core/keychain.py` stamps `connection_id` and `slot` on every entry so that two connections of
|
| 217 |
+
#: one kind are separately addressable (R4's agency tenant: many Odoos, one workspace). This layer
|
| 218 |
+
#: renames the first of them to `connectionId` because that is what every other camelCase field on
|
| 219 |
+
#: these payloads does (`createdBy`, `canBusiness`, `tenantWideTypes`), and a payload carrying both
|
| 220 |
+
#: spellings would be [[a-constant-two-features-share]] on the wire, where a client picking the
|
| 221 |
+
#: wrong one still looks right until the day only one is filled.
|
| 222 |
+
#: β `slot` is one word, so it crosses unchanged.
|
| 223 |
+
def _identified(row):
|
| 224 |
+
"""One keychain row, with its identity in wire spelling. Gains keys, never loses one."""
|
| 225 |
+
out = dict(row)
|
| 226 |
+
out["connectionId"] = str(out.pop("connection_id", "") or out.get("id") or "")
|
| 227 |
+
out["slot"] = int(out.get("slot") or 1)
|
| 228 |
+
return out
|
| 229 |
+
|
| 230 |
+
|
| 231 |
def _write_scope(rt, entry_id, scope, owner):
|
| 232 |
"""Persist one entry's scope. A `business` entry CLEARS its row rather than writing the
|
| 233 |
default, so the store holds one spelling of the common case."""
|
|
|
|
| 255 |
return keychain
|
| 256 |
|
| 257 |
|
| 258 |
+
def _ps():
|
| 259 |
+
"""`core.perm_scope`, lazily. Same idiom as `_kc()` and `_rel()`, and for the same reason: the
|
| 260 |
+
permission layer pulls the grid stack in behind it, and this router is imported at boot."""
|
| 261 |
+
import core.perm_scope as perm_scope
|
| 262 |
+
return perm_scope
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
#: β THE ONE KIND THAT STANDS BEHIND NO CONNECTOR CARD. `_connector_by_entry_type` names every
|
| 266 |
+
#: other member of `keychain.ENTRY_TYPES`; `generic` is a credential a person stored by hand, so it
|
| 267 |
+
#: has no card and no label to borrow. Spelled here rather than dropped from the vocabulary,
|
| 268 |
+
#: because a grant list narrower than the door it governs is a gap nobody can see: `add_key` accepts
|
| 269 |
+
#: every `ENTRY_TYPES` member, so every one of them must be grantable.
|
| 270 |
+
CONNECTOR_KIND_LABELS = {"generic": "Other credential"}
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def connector_grant_kinds():
|
| 274 |
+
"""The grant vocabulary: `[{key, label, tenantWide}]`, one row per connectable kind.
|
| 275 |
+
|
| 276 |
+
ββ W54-T47 / R4 β THE THIRD AXIS'S OWN WORDS. Owner: *"access becomes Database / Module /
|
| 277 |
+
Connector."* The first two are registry keys the permission editor already renders; this one is
|
| 278 |
+
a CREDENTIAL KIND, so its vocabulary is `keychain.ENTRY_TYPES` and not the registry at all.
|
| 279 |
+
|
| 280 |
+
β DERIVED FROM `ENTRY_TYPES`, NEVER TYPED OUT. That set is what `add_entry` validates against,
|
| 281 |
+
so a hand-written list here would be [[one-question-two-normalizers]] the day a connector is
|
| 282 |
+
added: a kind the door accepts and the editor cannot grant is a permission nobody can give.
|
| 283 |
+
β `tenantWide` RIDES ALONG so the editor can say what a grant on that kind really means. A
|
| 284 |
+
tenant-wide source is never personal, so granting it hands the member the workspace's own
|
| 285 |
+
credential slot; that is exactly what R4 asks for and exactly what an admin should read before
|
| 286 |
+
ticking it.
|
| 287 |
+
"""
|
| 288 |
+
owners = _connector_by_entry_type()
|
| 289 |
+
out = []
|
| 290 |
+
for etype in sorted(_kc().ENTRY_TYPES):
|
| 291 |
+
label = str((owners.get(etype) or {}).get("label") or "").strip()
|
| 292 |
+
out.append({"key": etype,
|
| 293 |
+
"label": label or CONNECTOR_KIND_LABELS.get(etype, etype),
|
| 294 |
+
"tenantWide": etype in TENANT_WIDE_TYPES})
|
| 295 |
+
return out
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
def _grant_subject(session, username):
|
| 299 |
+
"""The registry key for `username`, or a 404 that cannot distinguish another tenant's account
|
| 300 |
+
from a missing one.
|
| 301 |
+
|
| 302 |
+
β THE 404 RULE AND THE TENANT DEFAULT ARE BORROWED, NOT RE-SPELLED. `routes_admin.get_perms`
|
| 303 |
+
already answers *"a cross-tenant username answers exactly like a missing one, 404, never 403,
|
| 304 |
+
because 'that account exists in another company' is itself a leak"*, and `_tenant_of` is
|
| 305 |
+
already the ONE spelling of the pre-wave default. A second copy here is how a tenant wall grows
|
| 306 |
+
a gap. Imported lazily, exactly as `_connector_by_entry_type` imports `routes_connectors`.
|
| 307 |
+
"""
|
| 308 |
+
import routes_admin as ra
|
| 309 |
+
uname = str(username or "").strip().lower()
|
| 310 |
+
reg = ra._registry()
|
| 311 |
+
if uname not in reg or ra._tenant_of(reg[uname]) != ra._tenant_of(session.user):
|
| 312 |
+
raise err(404, "no_such_user", f"no account named {uname!r}")
|
| 313 |
+
return uname
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def _grant_admin(session):
|
| 317 |
+
"""Deciding who may connect a source is an administrator's act, refused at the server.
|
| 318 |
+
|
| 319 |
+
β THE CLIENT HIDES; THIS FORBIDS. `PermsEditor.tsx` renders the section only for an admin as a
|
| 320 |
+
courtesy, and its own header says every control there is one.
|
| 321 |
+
"""
|
| 322 |
+
if not session.admin:
|
| 323 |
+
raise err(403, "not_admin",
|
| 324 |
+
"only an administrator can decide who may add connections to this workspace")
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
@router.get("/admin/users/{username}/connector-grants")
|
| 328 |
+
def get_connector_grants(username: str, session: Session = Depends(require_session)):
|
| 329 |
+
"""One account's Connector grants, plus the vocabulary the editor renders them from."""
|
| 330 |
+
_grant_admin(session)
|
| 331 |
+
uname = _grant_subject(session, username)
|
| 332 |
+
return {"username": uname,
|
| 333 |
+
"kinds": connector_grant_kinds(),
|
| 334 |
+
"granted": sorted(_ps().connector_grants(uname, st=session.runtime))}
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
@router.put("/admin/users/{username}/connector-grants")
|
| 338 |
+
def put_connector_grants(username: str, body: dict = Body(default=None),
|
| 339 |
+
session: Session = Depends(require_session)):
|
| 340 |
+
"""Replace one account's Connector grants wholesale (W54-T47 / R4 / contract C4).
|
| 341 |
+
|
| 342 |
+
WHOLESALE, for the reason `put_perms` is: *"'remove this restriction' has to be expressible,
|
| 343 |
+
and a merge cannot express a deletion without a second vocabulary for it."* An empty list is
|
| 344 |
+
therefore a legal body and it REVOKES.
|
| 345 |
+
|
| 346 |
+
β AN EMPTIED GRANT CLEARS ITS ROW rather than storing `[]`. An absent row and "no grant" mean
|
| 347 |
+
the same thing (`perm_scope.CONNECTOR_GRANT_KEY`'s own note), so there is one spelling of the
|
| 348 |
+
common case and revoking returns the store to the shape it had before anybody granted anything.
|
| 349 |
+
|
| 350 |
+
β AN UNKNOWN KIND IS NAMED, NEVER DROPPED (W30/R6's second sentence). Silently discarding it
|
| 351 |
+
would tell an administrator they granted something the door will never honour.
|
| 352 |
+
"""
|
| 353 |
+
_grant_admin(session)
|
| 354 |
+
uname = _grant_subject(session, username)
|
| 355 |
+
body = body if isinstance(body, dict) else {}
|
| 356 |
+
raw = body.get("granted")
|
| 357 |
+
if not isinstance(raw, list):
|
| 358 |
+
raise err(400, "bad_grants",
|
| 359 |
+
"say which connectors this account may add, as a list of connector kinds")
|
| 360 |
+
known = {k["key"] for k in connector_grant_kinds()}
|
| 361 |
+
want = sorted({str(k).strip().lower() for k in raw if str(k or "").strip()})
|
| 362 |
+
unknown = [k for k in want if k not in known]
|
| 363 |
+
if unknown:
|
| 364 |
+
raise err(400, "unknown_connector",
|
| 365 |
+
f"this workspace has no connector called {', '.join(unknown)}")
|
| 366 |
+
|
| 367 |
+
def _up(cur):
|
| 368 |
+
cur = cur if isinstance(cur, dict) else {}
|
| 369 |
+
if want:
|
| 370 |
+
cur[uname] = want
|
| 371 |
+
else:
|
| 372 |
+
cur.pop(uname, None)
|
| 373 |
+
return cur
|
| 374 |
+
|
| 375 |
+
try:
|
| 376 |
+
session.runtime.update(_ps().CONNECTOR_GRANT_KEY, _up, flush="sync")
|
| 377 |
+
except Exception:
|
| 378 |
+
raise err(503, "store_unavailable", "the change was not saved, please try again")
|
| 379 |
+
return {"username": uname, "kinds": connector_grant_kinds(), "granted": want}
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
def _resolved_odoo_key(rt, connection_id=None):
|
| 383 |
"""`(source, flag_key)` β which source would serve this tenant's Odoo queries, in both the
|
| 384 |
shapes this module needs: the display string (`env` / `keychain:<id>`) and the key the pause
|
| 385 |
flag is stored under.
|
| 386 |
|
| 387 |
+
β W54-T45 / R4 β `connection_id` NAMES which connection is being asked about; no id keeps
|
| 388 |
+
meaning the tenant's designated default, so no route's behaviour moves. The mirroring is the
|
| 389 |
+
point: this still delegates to `TenantRuntime.odoo_flag_key`, which now refuses to fall back
|
| 390 |
+
to the environment for a named-but-unresolvable connection, and so does this by construction.
|
| 391 |
+
|
| 392 |
β D-10 (wave 24): THE RESOLUTION ITSELF NOW LIVES IN ONE PLACE, `TenantRuntime.odoo_flag_key`,
|
| 393 |
beside the `odoo_source()` it must agree with. This function had its own copy of the same
|
| 394 |
three rules β first unlocked keychain odoo entry, else env for tenant #0, else nothing β and
|
|
|
|
| 396 |
against another, freezing nothing while the UI reports success. The two SHAPES stay here
|
| 397 |
because they are this module's presentation concern; the DECISION does not.
|
| 398 |
"""
|
| 399 |
+
flag_key = rt.odoo_flag_key(connection_id)
|
| 400 |
if not flag_key:
|
| 401 |
return None, None
|
| 402 |
return ("env" if flag_key == _ENV_ODOO_FLAG_KEY else f"keychain:{flag_key}"), flag_key
|
|
|
|
| 708 |
#: the vocabulary and the permission, so the client renders a picker it can honour
|
| 709 |
#: rather than offering an option the server will refuse (R4: business is admin-only).
|
| 710 |
"scopes": list(SCOPES), "canBusiness": bool(session.admin),
|
| 711 |
+
"tenantWideTypes": list(TENANT_WIDE_TYPES),
|
| 712 |
+
# β W54-T47 / R4 β WHICH KINDS THIS READER MAY CREATE BUSINESS-WIDE WITHOUT BEING AN
|
| 713 |
+
# ADMIN. β ADDITIVE, AND `canBusiness` IS DELIBERATELY UNMOVED: that flag has meant
|
| 714 |
+
# "this account is an administrator" since wave 32 and three gates read it as such, so
|
| 715 |
+
# widening it would make one boolean answer two questions. A grant is per KIND and
|
| 716 |
+
# arrives as a list for the same reason the wall is per kind.
|
| 717 |
+
# β COURTESY, NEVER THE WALL. `add_key` consults `perm_scope.may_add_connection`
|
| 718 |
+
# regardless of what any client believes about this field.
|
| 719 |
+
"connectorGrants": sorted(_ps().connector_grants(session.uname,
|
| 720 |
+
st=session.runtime))}
|
| 721 |
|
| 722 |
|
| 723 |
@router.post("/admin/keychain", status_code=201)
|
|
|
|
| 730 |
if scope is None:
|
| 731 |
raise err(400, "bad_scope",
|
| 732 |
f"scope must be one of {', '.join(SCOPES)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 733 |
etype = str(body.get("type") or "").strip().lower()
|
| 734 |
+
# ββ W54-T47 / R4 / CONTRACT C4 β THE CONNECTOR GRANT IS CONSULTED HERE AND ONLY HERE, ON THE
|
| 735 |
+
# PATH THAT WAS ALREADY REFUSED.
|
| 736 |
+
#
|
| 737 |
+
# ββ WHICH IS WHAT MAKES IT ABSENCE-PRESERVING, and that property is the whole design. A
|
| 738 |
+
# member with NO grant meets byte-identical behaviour to the day before this shipped: 403
|
| 739 |
+
# `not_admin` here, 400 `scope_not_available` below, and their own personal connection of an
|
| 740 |
+
# ordinary type still succeeds. Nothing was storable before this ticket, so every account in
|
| 741 |
+
# every tenant carries no grant β reading that absence as DENY anywhere else on this route
|
| 742 |
+
# would revoke personal connections for the entire product with nobody having decided
|
| 743 |
+
# anything (`core/perm_scope.may_metrics` records the identical failure one field over).
|
| 744 |
+
#
|
| 745 |
+
# β SO THE GRANT ONLY EVER WIDENS: an explicit per-kind grant is what lets a named non-admin
|
| 746 |
+
# create a business-wide connection OF THAT KIND, which is R4's agency case said as a rule
|
| 747 |
+
# (*"many Gmail connections, or even many Odoo connections for one tenant, depending on the
|
| 748 |
+
# admin's configuration per user"*).
|
| 749 |
+
#
|
| 750 |
+
# β `etype` MOVED ABOVE THIS TEST rather than staying below it, because the grant is per KIND
|
| 751 |
+
# and a check that cannot see the kind can only ever be a second `session.admin`.
|
| 752 |
+
if scope == "business" and not session.admin and not _ps().may_add_connection(
|
| 753 |
+
session.user, etype, st=session.runtime):
|
| 754 |
+
raise err(403, "not_admin",
|
| 755 |
+
"a business-wide connection applies to everyone in this workspace, so it takes "
|
| 756 |
+
"an administrator, or an account an administrator has granted this connector "
|
| 757 |
+
"under Settings. "
|
| 758 |
+
+ ("Ask an administrator to add it for everyone."
|
| 759 |
+
if etype in TENANT_WIDE_TYPES
|
| 760 |
+
else "You can add it as a personal connection instead."))
|
| 761 |
if scope == "personal" and etype in TENANT_WIDE_TYPES:
|
| 762 |
# β REPORTED, NOT COERCED (W30/R6's second sentence). See TENANT_WIDE_TYPES above: this
|
| 763 |
# credential is what the WHOLE workspace's databases are built from, so "personal" would
|
| 764 |
# be a label on a tenant-wide key rather than a boundary around it.
|
| 765 |
+
# β AND THE GRANT DOES NOT REACH THIS REFUSAL. `allowed_scopes` is the SOURCE's own rule
|
| 766 |
+
# and knows nothing about who is asking; a grant says a person may connect this kind for
|
| 767 |
+
# the workspace, never that a workspace-wide credential can become one person's.
|
| 768 |
raise err(400, "scope_not_available",
|
| 769 |
f"a {etype} connection is what this whole workspace's databases are read "
|
| 770 |
+
f"through, so it is always business-wide and cannot be a personal connection. "
|
| 771 |
f"An administrator can add it for everyone.")
|
| 772 |
try:
|
| 773 |
row = kc.add_entry(session.runtime, body.get("label"), body.get("type"),
|
|
|
|
| 802 |
raise err(503, "store_unavailable",
|
| 803 |
"the key was not saved β its sharing setting could not be stored, so "
|
| 804 |
"nothing was kept. Try again.")
|
| 805 |
+
return {"entry": {**_identified(row), "scope": scope, "owner": session.uname}}
|
| 806 |
|
| 807 |
|
| 808 |
@router.put("/admin/keychain/{entry_id}")
|
| 809 |
def update_key(entry_id: str, body: dict = Body(default=None),
|
| 810 |
session: Session = Depends(require_session)):
|
| 811 |
+
"""Contract C1's scope door, and W54-T44 / C4's RENAME door. Both are settings ABOUT a
|
| 812 |
+
connection rather than the credential inside it: a stored secret is never re-openable, so
|
| 813 |
+
"change the key itself" still means "replace it", which is `DELETE` + `POST`.
|
| 814 |
+
|
| 815 |
+
β R4 asks for the rename by name β *"Odoo 1, Odoo 2, and obviously user can rename this"* β
|
| 816 |
+
and this is where it belongs: the walls a rename needs (`_own_row`'s 404 for an entry you may
|
| 817 |
+
not see, `_may_touch`'s ownership rule) are already standing here, and a second door would be
|
| 818 |
+
a second copy of both.
|
| 819 |
+
β `{"label": ...}` and `{"scope": ...}` are independent; either alone is a valid request and
|
| 820 |
+
both together are one change. A body carrying NEITHER is a 400 rather than a silent no-op,
|
| 821 |
+
because "nothing happened" and "your change was saved" must never look the same.
|
| 822 |
+
"""
|
| 823 |
row = _own_row(session, entry_id)
|
| 824 |
+
body = body or {}
|
| 825 |
+
wants_scope, wants_label = "scope" in body, "label" in body
|
| 826 |
+
if not wants_scope and not wants_label:
|
| 827 |
+
raise err(400, "nothing_to_change",
|
| 828 |
+
"say what to change about this connection: a new name, or who it is shared "
|
| 829 |
+
"with.")
|
| 830 |
+
scope = None
|
| 831 |
+
if wants_scope:
|
| 832 |
+
scope = clean_scope(body.get("scope"), default=None)
|
| 833 |
+
if scope is None:
|
| 834 |
+
raise err(400, "bad_scope", f"scope must be one of {', '.join(SCOPES)}")
|
| 835 |
+
if scope == "business" and not session.admin:
|
| 836 |
+
raise err(403, "not_admin",
|
| 837 |
+
"a business-wide connection applies to everyone in this workspace, so only "
|
| 838 |
+
"an administrator can make one business-wide.")
|
| 839 |
if not _may_touch(session, row):
|
| 840 |
raise err(403, "not_yours", "this connection is not yours to change")
|
| 841 |
+
if wants_scope and scope == "personal" and str(row.get("type") or "") in TENANT_WIDE_TYPES:
|
| 842 |
raise err(400, "scope_not_available",
|
| 843 |
f"a {row.get('type')} connection is what this whole workspace's databases are "
|
| 844 |
f"read through, so it is always business-wide.")
|
| 845 |
+
label = row.get("label") or ""
|
| 846 |
+
if wants_label:
|
| 847 |
+
# β THE NAME MOVES AND NOTHING ELSE. `rename_entry` touches one field on one row, so the
|
| 848 |
+
# connection keeps its `connectionId`, its `slot` and its encrypted credential, and every
|
| 849 |
+
# other connection of the same kind is left byte for byte as it was.
|
| 850 |
+
try:
|
| 851 |
+
renamed = _kc().rename_entry(session.runtime, entry_id, body.get("label"))
|
| 852 |
+
except ValueError as e:
|
| 853 |
+
raise err(400, "bad_label", str(e))
|
| 854 |
+
except Exception:
|
| 855 |
+
raise err(503, "store_unavailable", "the new name was not saved, please try again")
|
| 856 |
+
if renamed is None:
|
| 857 |
+
raise err(404, "no_entry", "no such key")
|
| 858 |
+
label = renamed.get("label") or label
|
| 859 |
owner = row.get("owner") or session.uname
|
| 860 |
+
if not wants_scope:
|
| 861 |
+
return {"entry": {**row, "label": label}}
|
| 862 |
try:
|
| 863 |
_write_scope(session.runtime, entry_id, scope, owner)
|
| 864 |
except Exception:
|
| 865 |
raise err(503, "store_unavailable", "the change was not saved β try again")
|
| 866 |
+
return {"entry": {**row, "label": label, "scope": scope,
|
| 867 |
+
"owner": owner if scope == "personal" else ""}}
|
| 868 |
|
| 869 |
|
| 870 |
@router.delete("/admin/keychain/{entry_id}")
|
|
|
|
| 929 |
# every colleague's personal connection on the screen next door to the one that hides them.
|
| 930 |
entries = visible_entries(session.runtime, session.uname, bool(session.admin))
|
| 931 |
# R3 cutover (2026-08-04): which source would actually serve this tenant's Odoo queries β
|
| 932 |
+
# mirrors TenantRuntime.odoo_source() exactly: the resolved keychain odoo connection (while
|
| 933 |
+
# unlocked), else env for tenant #0 only, else nothing (fail closed β never another tenant's
|
| 934 |
+
# environment).
|
| 935 |
+
# ββ W54-T45 β THE WALK IS GONE AND THE RESOLUTION IS ASKED FOR. This was the third copy of
|
| 936 |
+
# "the first odoo entry of this tenant", written out by hand beside a comment promising it
|
| 937 |
+
# mirrors `odoo_source()`. Under R4 a tenant holds many Odoo connections, so a hand-rolled
|
| 938 |
+
# first-entry walk here would light the ACTIVE badge on one client's connection while the
|
| 939 |
+
# connector layer served another's β the two answers disagreeing on the one screen that
|
| 940 |
+
# exists to show which is which. `keychain.resolve_connection_id` is the single resolver, it
|
| 941 |
+
# decrypts nothing (this route runs on a locked keychain too), and it applies the same
|
| 942 |
+
# personal-entry skip this comment already required.
|
| 943 |
# β W32-T11: computed over the TENANT's entries, not over `entries` above. "Which source
|
| 944 |
# serves this workspace" is one fact for everybody, and deriving it from a per-USER list would
|
| 945 |
# make the answer depend on who opened the pane. Personal entries are excluded for the same
|
| 946 |
# reason `TENANT_WIDE_TYPES` refuses them: they must never become the workspace's source.
|
| 947 |
+
serving_odoo = kc.resolve_connection_id(session.runtime, "odoo")
|
|
|
|
|
|
|
|
|
|
| 948 |
# β W32-T10 β the env leg goes through `env_odoo_available` now, so this route and the
|
| 949 |
# connectors DIRECTORY answer "does the environment serve this tenant?" with one function
|
| 950 |
# instead of two spellings that agreed until a second tenant signed in.
|
| 951 |
+
if serving_odoo and kc.unlocked():
|
| 952 |
+
resolved = f"keychain:{serving_odoo}"
|
| 953 |
elif env_odoo_available(session.runtime):
|
| 954 |
resolved = "env"
|
| 955 |
else:
|
|
|
|
| 1036 |
return rel
|
| 1037 |
|
| 1038 |
|
| 1039 |
+
def _odoo_entry(session, connection_id=None):
|
| 1040 |
"""The keychain entry SERVING this tenant's Odoo, or None when the environment is (or nothing
|
| 1041 |
+
is). Business-scoped by construction β `TENANT_WIDE_TYPES` refuses a personal one.
|
| 1042 |
+
|
| 1043 |
+
ββ W54-T45 / R4 / C4 β IT ASKS THE KEYCHAIN WHICH CONNECTION SERVES RATHER THAN WALKING FOR
|
| 1044 |
+
THE FIRST ONE. `connection_id` names it; no id means the tenant's designated default, which is
|
| 1045 |
+
the lowest-`slot` odoo connection and, for every tenant that has exactly one, the same row this
|
| 1046 |
+
used to return. The walk this replaced was a second copy of the resolution
|
| 1047 |
+
`keychain.resolve_connection_id` owns, and a panel resolving one connection while the connector
|
| 1048 |
+
layer resolves another is precisely how an agency's screen comes to describe the wrong client.
|
| 1049 |
+
β A named connection that does not resolve is None, never a sibling and never the environment.
|
| 1050 |
+
"""
|
| 1051 |
kc = _kc()
|
| 1052 |
+
cid = kc.resolve_connection_id(session.runtime, "odoo", connection_id)
|
| 1053 |
+
if not cid:
|
| 1054 |
+
return None
|
| 1055 |
scopes = _scope_rows(session.runtime)
|
| 1056 |
for e in kc.list_entries(session.runtime):
|
| 1057 |
+
if str(e["connection_id"]) != str(cid) and str(e["id"]) != str(cid):
|
| 1058 |
+
continue
|
| 1059 |
+
# The personal skip belongs to the resolver above; re-asserted here because THIS module
|
| 1060 |
+
# owns the scope vocabulary and a divergence between the two buckets must fail closed.
|
| 1061 |
+
if entry_scope(session.runtime, e["id"], scopes)[0] == "personal":
|
| 1062 |
+
return None
|
| 1063 |
+
return e
|
| 1064 |
return None
|
| 1065 |
|
| 1066 |
|
|
|
|
| 1220 |
So this is add-then-delete through the module's own doors, with the side rows (pause flag,
|
| 1221 |
scope) carried across because they are keyed by ENTRY ID.
|
| 1222 |
β THE ORDER IS DELIBERATE AND THE WINDOW IS REAL: for the moment between the add and the
|
| 1223 |
+
delete this tenant has TWO odoo entries. The alternative order can leave the workspace with no
|
| 1224 |
+
credential at all, which is worse than one stale read.
|
| 1225 |
+
β W54-T45 MADE THAT WINDOW DETERMINISTIC RATHER THAN AMBIGUOUS, as a side effect worth
|
| 1226 |
+
stating. It used to read "`odoo_creds` takes the first by id sort β so a resync landing inside
|
| 1227 |
+
that window COULD read the old database", i.e. a coin flip on random hex. The resolver now
|
| 1228 |
+
serves the tenant's designated default, the LOWEST slot, and the replacement entry is minted
|
| 1229 |
+
high-water: so the OLD connection serves for the whole window and the new one takes over the
|
| 1230 |
+
instant the old row is deleted. One stale read, not a coin flip.
|
| 1231 |
"""
|
| 1232 |
kc = _kc()
|
| 1233 |
entry = _odoo_entry(session)
|
api/routes_nav.py
CHANGED
|
@@ -422,6 +422,111 @@ def _granted_view_ids(session):
|
|
| 422 |
return set()
|
| 423 |
|
| 424 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
@router.get("/nav")
|
| 426 |
def nav(session: Session = Depends(require_session)):
|
| 427 |
"""`{pages: [{key,label,source?,chrome}], landing}`.
|
|
@@ -561,12 +666,23 @@ def nav(session: Session = Depends(require_session)):
|
|
| 561 |
# leak with no symptom until two tenants rename the same registry key. Copy the rows before
|
| 562 |
# merging on the day that invariant changes.
|
| 563 |
meta = _read_nav_meta(session.runtime)
|
|
|
|
|
|
|
| 564 |
for page in pages:
|
| 565 |
source = str(page.get("source") or "")
|
| 566 |
key = str(page.get("key") or "")
|
| 567 |
if key in {"customer_data", "product_data"} or source.lower() == "odoo" \
|
| 568 |
or key.startswith("ut_odoo_"):
|
|
|
|
|
|
|
|
|
|
| 569 |
page["sourceGroup"] = "Odoo"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 570 |
elif page.get("user_table") or source in {"", "Blank", "Custom"}:
|
| 571 |
page.setdefault("sourceGroup", "Custom")
|
| 572 |
# ββ W35-T43 (rulings R4/R7) β THE MARK-IMPORTANT COUNTS ARE NO LONGER COMPUTED HERE.
|
|
|
|
| 422 |
return set()
|
| 423 |
|
| 424 |
|
| 425 |
+
#: ββ W54-T48 / OWNER RULING R4 / CONTRACT C4 β ONE CONNECTION, ONE FOLDER IN THE RAIL.
|
| 426 |
+
#:
|
| 427 |
+
#: R4, verbatim: *"under the View rail for each database that comes from the same connector, they
|
| 428 |
+
#: need to be put in the same Folder. Odoo 1, Odoo 2, and obviously user can rename this."* The
|
| 429 |
+
#: rail already folds the Data level by `sourceGroup` (`dataPath.ts::groupDataDatabases`), so the
|
| 430 |
+
#: grouping mechanism is not the missing piece β the NAME was. Every Odoo database used to answer
|
| 431 |
+
#: the literal `"Odoo"`, so an agency with two Odoo connections saw its two clients' invoices
|
| 432 |
+
#: nested under one folder, which is the exact confusion R4 exists to prevent.
|
| 433 |
+
#:
|
| 434 |
+
#: β THE RENAME IS THE CONNECTION'S RENAME AND THERE IS NO SECOND NAMING SCHEME. The folder shows
|
| 435 |
+
#: the keychain row's `label`, which `keychain.add_entry` defaults to `Odoo 1` / `Odoo 2` and
|
| 436 |
+
#: `keychain.rename_entry` changes (W54-T44). *"Obviously user can rename this"* is therefore
|
| 437 |
+
#: already shipped: renaming the connection renames its folder on the next nav read, and it
|
| 438 |
+
#: touches no TABLE KEY β those are namespaced on the immutable `connection_id` (W54-T46), never
|
| 439 |
+
#: on a label a person may change twice a day.
|
| 440 |
+
#:
|
| 441 |
+
#: ββ AND THE OVERRIDE ONLY FIRES WHEN THERE ARE TWO OR MORE CONNECTIONS TO TELL APART. With
|
| 442 |
+
#: exactly one Odoo connection β every tenant that exists today β the folder keeps the generic
|
| 443 |
+
#: `"Odoo"` it has always shown, unchanged, and nothing on anybody's rail moves.
|
| 444 |
+
#:
|
| 445 |
+
#: THE REASON IS R4 ITSELF, not caution. R4 asks for connections to be DISTINGUISHABLE: *"Odoo 1,
|
| 446 |
+
#: Odoo 2"*. With one connection there is one folder either way and nothing to distinguish it
|
| 447 |
+
#: from, so the label buys no clarity and costs the tenant a rail that suddenly reads differently.
|
| 448 |
+
#: Tenant #0's one connection is labelled "Odoo (migrated from this deployment)" by an August
|
| 449 |
+
#: migration, so an unconditional override renamed the owner's own Data folder to a truncated
|
| 450 |
+
#: migration artefact β a regression this ticket would have shipped in the name of a ruling about
|
| 451 |
+
#: agencies. The moment a SECOND connection is added the names appear on both folders together,
|
| 452 |
+
#: which is the only moment they mean anything.
|
| 453 |
+
#: β COUNTED ON THE CONNECTIONS, NOT ON THE USABLE LABELS. A second connection whose label is one
|
| 454 |
+
#: of the reserved words below is still a second connection, and its sibling must still be named.
|
| 455 |
+
#:
|
| 456 |
+
#: These two reserved words are the rail's OWN vocabulary, not a connection's to take:
|
| 457 |
+
#: `dataPath.ts::dataDatabaseOrigin` folds `loopable` / `blank` / `automation` / empty into the
|
| 458 |
+
#: "Loopable" group, and the branch below puts user tables in "Custom". A connection someone named
|
| 459 |
+
#: "Blank" would otherwise dissolve into one of those folders and show a client's invoices beside
|
| 460 |
+
#: somebody's scratch table, so such a label falls back to the generic Odoo folder instead.
|
| 461 |
+
_RESERVED_GROUP_LABELS = frozenset({"loopable", "blank", "automation", "custom", "odoo"})
|
| 462 |
+
|
| 463 |
+
#: The registry modules that ARE the designated default connection's data rather than a namespaced
|
| 464 |
+
#: copy of it: `odoo_relational.namespaced_fields` says so in as many words ("`customer_link`
|
| 465 |
+
#: targets the compiled registry module `customer_data`, which holds the DEFAULT connection's
|
| 466 |
+
#: customers"). They carry no namespace token to read backwards, so they are named here.
|
| 467 |
+
_DEFAULT_CONNECTION_PAGES = frozenset({"customer_data", "product_data"})
|
| 468 |
+
|
| 469 |
+
|
| 470 |
+
def _odoo_connection_folders(runtime):
|
| 471 |
+
"""`({connection_id: folder label}, default_connection_id)` for this tenant's Odoo
|
| 472 |
+
connections β resolved ONCE per `/nav`, decrypting nothing, and `({}, None)` on any failure.
|
| 473 |
+
|
| 474 |
+
β ONCE PER REQUEST, NOT ONCE PER PAGE, AND THAT IS THE WHOLE REASON THIS IS A FUNCTION.
|
| 475 |
+
`odoo_relational.connection_label` and `keychain.default_connection_id` each walk
|
| 476 |
+
`keychain.list_entries`, which is a store read; calling either inside the page loop would put
|
| 477 |
+
N of them back on the one route D-175 spent a wave reducing to a single read. The loop below
|
| 478 |
+
asks `connection_for_table_key` WITHOUT a runtime, which is pure string work, and maps its
|
| 479 |
+
`DEFAULT_CONNECTION` sentinel through the default resolved here.
|
| 480 |
+
β AND IT FAILS SOFT ON PURPOSE. A locked keychain, a store blip or a missing import leaves the
|
| 481 |
+
rail painting the generic "Odoo" folder; a rail that does not paint at all is far worse than a
|
| 482 |
+
rail whose folder carries a generic name.
|
| 483 |
+
β A TENANT WITH FEWER THAN TWO ODOO CONNECTIONS GETS `{}` β the same answer as a failure, and
|
| 484 |
+
deliberately so: both mean "there is nothing here to tell apart, keep the generic folder". The
|
| 485 |
+
count is taken over the CONNECTIONS, before the reserved-word filter, so a second connection
|
| 486 |
+
named `Blank` still switches its sibling on.
|
| 487 |
+
"""
|
| 488 |
+
if runtime is None:
|
| 489 |
+
return {}, None
|
| 490 |
+
try:
|
| 491 |
+
import core.keychain as keychain
|
| 492 |
+
import odoo_relational as odoo_rel
|
| 493 |
+
connections = 0
|
| 494 |
+
labels = {}
|
| 495 |
+
for row in keychain.list_entries(runtime):
|
| 496 |
+
if str(row.get("type") or "") != "odoo":
|
| 497 |
+
continue
|
| 498 |
+
connections += 1
|
| 499 |
+
cid = str(row.get("connection_id") or "")
|
| 500 |
+
label = " ".join(str(row.get("label") or "").split())
|
| 501 |
+
if cid and label and label.lower() not in _RESERVED_GROUP_LABELS:
|
| 502 |
+
labels[cid] = label
|
| 503 |
+
if connections < 2:
|
| 504 |
+
return {}, odoo_rel.default_connection_id(runtime)
|
| 505 |
+
return labels, odoo_rel.default_connection_id(runtime)
|
| 506 |
+
except Exception: # noqa: BLE001
|
| 507 |
+
return {}, None
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
def _odoo_folder_label(key, labels, default_cid):
|
| 511 |
+
"""The folder name an Odoo page belongs under, or `""` to keep the generic fallback.
|
| 512 |
+
|
| 513 |
+
β `connection_for_table_key` is the ONLY sanctioned way to ask which connection owns a table,
|
| 514 |
+
because it is the inverse of the namespace `table_key_for` builds (C4). Parsing the key here
|
| 515 |
+
would be the second implementation that inverse exists to prevent.
|
| 516 |
+
"""
|
| 517 |
+
if not labels:
|
| 518 |
+
return ""
|
| 519 |
+
try:
|
| 520 |
+
import odoo_relational as odoo_rel
|
| 521 |
+
cid = (default_cid if key in _DEFAULT_CONNECTION_PAGES
|
| 522 |
+
else odoo_rel.connection_for_table_key(key))
|
| 523 |
+
if cid == odoo_rel.DEFAULT_CONNECTION:
|
| 524 |
+
cid = default_cid
|
| 525 |
+
except Exception: # noqa: BLE001
|
| 526 |
+
return ""
|
| 527 |
+
return labels.get(str(cid or "")) or ""
|
| 528 |
+
|
| 529 |
+
|
| 530 |
@router.get("/nav")
|
| 531 |
def nav(session: Session = Depends(require_session)):
|
| 532 |
"""`{pages: [{key,label,source?,chrome}], landing}`.
|
|
|
|
| 666 |
# leak with no symptom until two tenants rename the same registry key. Copy the rows before
|
| 667 |
# merging on the day that invariant changes.
|
| 668 |
meta = _read_nav_meta(session.runtime)
|
| 669 |
+
# W54-T48 (R4 / C4): the tenant's Odoo connections, read ONCE for the whole page loop.
|
| 670 |
+
_conn_labels, _conn_default = _odoo_connection_folders(session.runtime)
|
| 671 |
for page in pages:
|
| 672 |
source = str(page.get("source") or "")
|
| 673 |
key = str(page.get("key") or "")
|
| 674 |
if key in {"customer_data", "product_data"} or source.lower() == "odoo" \
|
| 675 |
or key.startswith("ut_odoo_"):
|
| 676 |
+
# β THIS LITERAL IS THE FALLBACK AND IT STAYS. It is what a tenant with ONE Odoo
|
| 677 |
+
# connection or none still sees β every tenant that exists today β and what a database
|
| 678 |
+
# that resolves to no connection at all keeps.
|
| 679 |
page["sourceGroup"] = "Odoo"
|
| 680 |
+
# β W54-T48 (R4 / C4): once the tenant has TWO connections to tell apart, each
|
| 681 |
+
# database is folded under its own connection's name, so two connections give two
|
| 682 |
+
# folders. `_odoo_connection_folders` answers `{}` below that threshold.
|
| 683 |
+
_folder = _odoo_folder_label(key, _conn_labels, _conn_default)
|
| 684 |
+
if _folder:
|
| 685 |
+
page["sourceGroup"] = _folder
|
| 686 |
elif page.get("user_table") or source in {"", "Blank", "Custom"}:
|
| 687 |
page.setdefault("sourceGroup", "Custom")
|
| 688 |
# ββ W35-T43 (rulings R4/R7) β THE MARK-IMPORTANT COUNTS ARE NO LONGER COMPUTED HERE.
|
api/routes_odoo_tables.py
CHANGED
|
@@ -1509,6 +1509,156 @@ def _related_source_value(session, entry, record):
|
|
| 1509 |
return None
|
| 1510 |
|
| 1511 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1512 |
def _related_pin(table_key, session, spec, base_where, wall_params, cur, related):
|
| 1513 |
"""`(sql, params, notes)` for C6's pinned read, or `(None, [], [])` when nothing is pinned.
|
| 1514 |
|
|
@@ -1534,6 +1684,30 @@ def _related_pin(table_key, session, spec, base_where, wall_params, cur, related
|
|
| 1534 |
rather than a literal `id`: `ut_odoo_order_lines` is join-shaped and its identity is `sol.id`,
|
| 1535 |
so a bare `id` would be ambiguous across `sale_order_line` and `sale_order`. It is the same
|
| 1536 |
expression this route already trusts as `tiebreak_sql` and as the fallback ORDER BY.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1537 |
"""
|
| 1538 |
import core.relations as relations
|
| 1539 |
|
|
@@ -1549,13 +1723,18 @@ def _related_pin(table_key, session, spec, base_where, wall_params, cur, related
|
|
| 1549 |
source = str(related.get("table") or "")
|
| 1550 |
record = related.get("record")
|
| 1551 |
via = related.get("via")
|
| 1552 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1553 |
raise err(400, "bad_relation",
|
| 1554 |
"a pinned read needs the record's database, the record id and the relation to "
|
| 1555 |
-
"follow, as {table, record, via}
|
|
|
|
| 1556 |
+ "/related for the relations this account may follow")
|
| 1557 |
|
| 1558 |
-
from routes_grid import _may_open, related_entries
|
| 1559 |
|
| 1560 |
if not _may_open(session, source):
|
| 1561 |
# β THE CAUSE IS NAMED AS A PAIR, ON PURPOSE. `_may_open` is fail-closed and answers False
|
|
@@ -1571,8 +1750,20 @@ def _related_pin(table_key, session, spec, base_where, wall_params, cur, related
|
|
| 1571 |
# β RESOLVED AGAINST THE **SCOPED** LISTING, which is what makes "an edge you cannot be
|
| 1572 |
# offered is an edge you cannot pin" structural rather than remembered. `related_entries` is
|
| 1573 |
# the same function `GET /grid/{table}/related` answers with; there is no second resolution.
|
| 1574 |
-
|
| 1575 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1576 |
if entry is None:
|
| 1577 |
raise err(400, "unknown_relation", relations.unknown_via_refusal(source, via))
|
| 1578 |
entry = dict(entry, __source__=source)
|
|
@@ -1586,12 +1777,33 @@ def _related_pin(table_key, session, spec, base_where, wall_params, cur, related
|
|
| 1586 |
if not entry.get("served", True):
|
| 1587 |
raise err(409, "relation_not_served", relations.unserved_target_refusal(entry))
|
| 1588 |
|
| 1589 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1590 |
# β `spec["cols"]`, NOT the caller's narrowed `cols`. The join column is a JOIN, not a value
|
| 1591 |
# this response returns: a relation must keep working when an administrator has hidden the id
|
| 1592 |
# column it runs over, and no cell of it is ever projected. The hidden-field closure still
|
| 1593 |
# governs everything that reaches the wire, one layer up.
|
| 1594 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1595 |
if not binding:
|
| 1596 |
raise err(409, "relation_not_served",
|
| 1597 |
f"'{table_key}' has no live expression for '{on}', which is the column this "
|
|
@@ -1599,14 +1811,23 @@ def _related_pin(table_key, session, spec, base_where, wall_params, cur, related
|
|
| 1599 |
f"this database directly, or ask for '{on}' to be added to its live connection")
|
| 1600 |
on_expr, on_cast = binding[0], binding[1]
|
| 1601 |
|
| 1602 |
-
|
| 1603 |
-
|
| 1604 |
-
|
| 1605 |
-
|
| 1606 |
-
|
| 1607 |
-
|
| 1608 |
-
|
| 1609 |
-
value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1610 |
|
| 1611 |
# ββ the member ids, in ONE SQL over the bridge column (the ticket's `how:`) ββββββββββββββββ
|
| 1612 |
# β NOT THROUGH `datastore.window`: that clamps at `WINDOW_MAX` (5,000) rows, so a customer
|
|
@@ -1616,22 +1837,27 @@ def _related_pin(table_key, session, spec, base_where, wall_params, cur, related
|
|
| 1616 |
# β THE WALL RIDES ALONG. Resolving ids under `base_where` means the id SET a scoped reader can
|
| 1617 |
# produce is already narrowed to rows they may see, so the pin cannot be used to learn how many
|
| 1618 |
# rows exist beyond their boundary.
|
|
|
|
|
|
|
|
|
|
| 1619 |
frm_body = spec["from_sql"] if spec.get("from_sql") else spec["table"]
|
| 1620 |
-
|
| 1621 |
-
|
| 1622 |
-
|
| 1623 |
-
|
| 1624 |
-
|
| 1625 |
-
|
|
|
|
|
|
|
|
|
|
| 1626 |
|
| 1627 |
-
notes = []
|
| 1628 |
# β STANDING RULE 1'S SECOND SENTENCE, ON A COST RATHER THAN ON A CAP. Nothing is limited
|
| 1629 |
# here; the reader is told that this particular relation is answered by reading the source
|
| 1630 |
# database once per page, because it is keyed on a column rather than on the record id.
|
| 1631 |
-
if str((
|
| 1632 |
notes.append({
|
| 1633 |
"subject": "related", "effect": "slow",
|
| 1634 |
-
"cause": f"this relation is keyed on the '{
|
| 1635 |
f"'{source}' rather than on its record id, so every page of these rows is "
|
| 1636 |
f"resolved by reading that database first",
|
| 1637 |
"recommendation": "read this database on its own and filter it on "
|
|
|
|
| 1509 |
return None
|
| 1510 |
|
| 1511 |
|
| 1512 |
+
def _via_path(via):
|
| 1513 |
+
"""The list of EDGE KEYS a `via` names, or None when it is one edge's bag instead.
|
| 1514 |
+
|
| 1515 |
+
ββ W54-T40 / R12 β *"the client pins one by naming each edge (`via = ["orders",
|
| 1516 |
+
"order_lines"]`)"*. THREE SPELLINGS ARRIVE AND ALL THREE ARE THE SAME THING, which is why
|
| 1517 |
+
exactly one function decides:
|
| 1518 |
+
|
| 1519 |
+
* an ARRAY of keys, which is what `RecordDetail.tsx::relatedPinKey` sends for a two-hop tab
|
| 1520 |
+
and what `verify_wiring.py` pins that client literal to;
|
| 1521 |
+
* a bare STRING, C3's back-compat leg, which `relations.pick_path` already reads as a
|
| 1522 |
+
one-element path;
|
| 1523 |
+
* the two-hop entry's own `via` BAG, `{direction: 'path', key, path}`, which is what a client
|
| 1524 |
+
holding the whole entry naturally hands back. Reading `path` out of it costs one key and
|
| 1525 |
+
removes an entire class of "the shape was almost right" refusal.
|
| 1526 |
+
|
| 1527 |
+
β A ONE-HOP BAG STAYS A BAG AND ANSWERS None. `relations.pick` is the resolver for that shape
|
| 1528 |
+
and it matches on `direction` plus `key`; routing it here instead would resolve a one-hop pin
|
| 1529 |
+
against the depth-aware listing for no gain and change the cost of the six tabs that already
|
| 1530 |
+
worked. β AN EMPTY OR PARTLY-BLANK PATH IS **NOT** A PATH: it answers None and falls into the
|
| 1531 |
+
`bad_relation` guard, which is the honest refusal for `via = []`.
|
| 1532 |
+
"""
|
| 1533 |
+
if isinstance(via, str):
|
| 1534 |
+
return [via] if via.strip() else None
|
| 1535 |
+
if isinstance(via, (list, tuple)):
|
| 1536 |
+
keys = [str(v).strip() for v in via]
|
| 1537 |
+
return keys if keys and all(keys) else None
|
| 1538 |
+
if isinstance(via, dict) and isinstance(via.get("path"), (list, tuple)):
|
| 1539 |
+
keys = [str(v).strip() for v in via["path"]]
|
| 1540 |
+
return keys if keys and all(keys) else None
|
| 1541 |
+
return None
|
| 1542 |
+
|
| 1543 |
+
|
| 1544 |
+
def _related_path_legs(session, source, entry, entries):
|
| 1545 |
+
"""`(first, mid_key, last)` β the two ONE-HOP entries a two-hop composite is made of.
|
| 1546 |
+
|
| 1547 |
+
ββ EACH LEG IS RESOLVED FROM **ITS OWN TABLE'S** SCOPED LISTING, AND THAT IS R13 AT PIN TIME.
|
| 1548 |
+
An edge key is unique per SOURCE table and not across a connector (`relations`' own banner says
|
| 1549 |
+
so, with the ten-edges/seven-keys measurement behind it), so hop 2 is looked up in the
|
| 1550 |
+
intermediate's listing and nowhere else. Resolving both against the source's list would be the
|
| 1551 |
+
ambiguous-key bug the entry key exists to prevent, and it would also skip the intermediate's
|
| 1552 |
+
permission wall on the way past.
|
| 1553 |
+
|
| 1554 |
+
β HOP 1 COSTS NOTHING EXTRA: it is in `entries`, the very listing the composite was picked
|
| 1555 |
+
from, because a depth-2 enumeration returns the one-hop entries first. Only hop 2 needs a
|
| 1556 |
+
second listing, and it is asked at depth 1.
|
| 1557 |
+
"""
|
| 1558 |
+
import core.relations as relations
|
| 1559 |
+
from routes_grid import related_path_entries
|
| 1560 |
+
|
| 1561 |
+
hops = [str(k) for k in (entry.get("path") or ())]
|
| 1562 |
+
first = relations.pick_path(entries, hops[:1])
|
| 1563 |
+
if first is None:
|
| 1564 |
+
raise err(400, "unknown_relation", relations.unknown_via_refusal(source, hops[:1]))
|
| 1565 |
+
mid_key = str(first.get("target") or "")
|
| 1566 |
+
last = relations.pick_path(related_path_entries(session, mid_key, 1), hops[1:2])
|
| 1567 |
+
if last is None:
|
| 1568 |
+
raise err(400, "unknown_relation", relations.unknown_via_refusal(mid_key, hops[1:2]))
|
| 1569 |
+
return dict(first, __source__=source), mid_key, dict(last, __source__=mid_key)
|
| 1570 |
+
|
| 1571 |
+
|
| 1572 |
+
def _related_hop_values(session, source, record, first, mid_key, last, notes):
|
| 1573 |
+
"""The values hop 2 joins on, resolved from the INTERMEDIATE database's own rows.
|
| 1574 |
+
|
| 1575 |
+
ββ W54-T40 β THIS IS THE HALF THAT MAKES A TWO-HOP TAB ANSWER ROWS INSTEAD OF A SENTENCE.
|
| 1576 |
+
Hop 1 turns the source record into a set of intermediate rows; this returns the value each of
|
| 1577 |
+
those rows carries in the column hop 2 is keyed on, and the caller pins THIS database by them.
|
| 1578 |
+
|
| 1579 |
+
ββ THE INTERMEDIATE IS READ THROUGH `_compiled_read`, WHICH IS THE SAME COMPILER THIS DOOR
|
| 1580 |
+
USES FOR AN ORDINARY WINDOW, AND THAT IS THE WHOLE PERMISSION ARGUMENT. Its grant gate, its
|
| 1581 |
+
administrator row wall and its hidden-field closure all run before a single id is produced, so
|
| 1582 |
+
a traversal cannot be used to learn about rows of the middle database a reader may not see. A
|
| 1583 |
+
second, lighter read here would be a second permission wall, and this file already carries the
|
| 1584 |
+
rule that a second copy of that block does not drift towards refusing.
|
| 1585 |
+
β AND AN INTERMEDIATE THIS DOOR CANNOT READ REFUSES BY NAME. `product_data` is a compiled
|
| 1586 |
+
registry module with no read-through binding, so the one enumerated path that passes through it
|
| 1587 |
+
answers a sentence carrying the cause and a way round it, rather than an empty grid.
|
| 1588 |
+
|
| 1589 |
+
β NO CAP, AND THE COST IS REPORTED INSTEAD (standing rule 1). Every distinct value comes back,
|
| 1590 |
+
however many there are, and the reader is told through `limits` that this tab resolves a second
|
| 1591 |
+
database on every page.
|
| 1592 |
+
"""
|
| 1593 |
+
import core.relations as relations
|
| 1594 |
+
from fastapi import HTTPException # noqa: PLC0415
|
| 1595 |
+
|
| 1596 |
+
value = _related_source_value(session, first, record)
|
| 1597 |
+
if value in (None, ""):
|
| 1598 |
+
raise err(400, "unknown_relation",
|
| 1599 |
+
relations.unresolvable_source_refusal(source, first))
|
| 1600 |
+
try:
|
| 1601 |
+
mid = _compiled_read(mid_key, session)
|
| 1602 |
+
except HTTPException as exc:
|
| 1603 |
+
why = ""
|
| 1604 |
+
if isinstance(getattr(exc, "detail", None), dict):
|
| 1605 |
+
why = str((exc.detail.get("error") or {}).get("message") or "")
|
| 1606 |
+
raise err(409, "relation_not_served",
|
| 1607 |
+
f"this relation reaches '{last.get('target')}' through '{mid_key}', and that "
|
| 1608 |
+
f"database could not be read here to follow it"
|
| 1609 |
+
+ (f" ({why})" if why else "")
|
| 1610 |
+
+ f". Open '{mid_key}' on its own, find the records this one is linked to, and "
|
| 1611 |
+
f"follow the next relation from there")
|
| 1612 |
+
mid_spec = mid["spec"]
|
| 1613 |
+
on1 = str((first.get("via") or {}).get("on") or "")
|
| 1614 |
+
step = (mid_spec.get("cols") or {}).get(on1)
|
| 1615 |
+
if not step:
|
| 1616 |
+
raise err(409, "relation_not_served",
|
| 1617 |
+
f"'{mid_key}' has no live expression for '{on1}', which is the column the first "
|
| 1618 |
+
f"hop of this relation joins on, so the traversal cannot be resolved. Open "
|
| 1619 |
+
f"'{mid_key}' on its own, or ask for '{on1}' to be added to its live connection")
|
| 1620 |
+
# β THE COLUMN HOP 2 IS KEYED ON, READ OFF THE INTERMEDIATE. `pid` is the row IDENTITY and is
|
| 1621 |
+
# not a column of the mirror spec, so it resolves to the spec's own identity expression, which
|
| 1622 |
+
# is the same one this route trusts everywhere else and is per table rather than a bare `id`.
|
| 1623 |
+
frm2 = str((last.get("via") or {}).get("from") or relations.IDENTITY_COL)
|
| 1624 |
+
take = (mid_spec["id"] if frm2 == relations.IDENTITY_COL
|
| 1625 |
+
else ((mid_spec.get("cols") or {}).get(frm2) or (None,))[0])
|
| 1626 |
+
if not take:
|
| 1627 |
+
raise err(409, "relation_not_served",
|
| 1628 |
+
f"'{mid_key}' has no live expression for '{frm2}', which is the value the second "
|
| 1629 |
+
f"hop of this relation is keyed on, so the traversal cannot be resolved. Open "
|
| 1630 |
+
f"'{mid_key}' on its own, or ask for '{frm2}' to be added to its live connection")
|
| 1631 |
+
try:
|
| 1632 |
+
value = step[1](value)
|
| 1633 |
+
except Exception: # noqa: BLE001
|
| 1634 |
+
value = str(value)
|
| 1635 |
+
mid_from = mid_spec["from_sql"] if mid_spec.get("from_sql") else mid_spec["table"]
|
| 1636 |
+
parts = [p for p in (mid["base_where"], first.get("where")) if p]
|
| 1637 |
+
parts.append(f"{step[0]} = ?")
|
| 1638 |
+
pred = " AND ".join(f"({p})" for p in parts)
|
| 1639 |
+
rows = mid["cur"].execute(
|
| 1640 |
+
f"SELECT DISTINCT {take} FROM {mid_from} WHERE {pred}",
|
| 1641 |
+
list(mid["wall_params"]) + [value]).fetchall()
|
| 1642 |
+
values = [r[0] for r in rows if r and r[0] is not None]
|
| 1643 |
+
# ββ STANDING RULE 1'S SECOND SENTENCE, AND `effect` IS CHOSEN SO THE READER GETS **THIS**
|
| 1644 |
+
# SENTENCE RATHER THAN A NEIGHBOUR'S. `counts.ts::plainLimit` maps a known `effect` to one
|
| 1645 |
+
# fixed client phrase and falls through to the SERVER's own first sentence for an effect it has
|
| 1646 |
+
# not learned; `slow` maps to *"Rows this far down load slowly, each page is reached by walking
|
| 1647 |
+
# every row above it"*, which is a true statement about a deep page and a FALSE one about a
|
| 1648 |
+
# seven-row traversal. `traversal` is deliberately not in that table, so the strip prints the
|
| 1649 |
+
# cause below, which is what actually happened.
|
| 1650 |
+
# β THE FIRST CLAUSE IS THE ONE THAT REACHES THE STRIP: `firstSentence` cuts at the first full
|
| 1651 |
+
# stop and truncates past 120 characters, so the mechanism is stated before the count.
|
| 1652 |
+
notes.append({
|
| 1653 |
+
"subject": "related", "effect": "traversal",
|
| 1654 |
+
"cause": f"these rows are reached through '{mid_key}', so every page resolves that "
|
| 1655 |
+
f"database first. This record matched {len(values):,} of its records, and this "
|
| 1656 |
+
f"database is then narrowed to the rows those reach",
|
| 1657 |
+
"recommendation": f"open '{mid_key}' on its own if you are paging through a large set, or "
|
| 1658 |
+
f"filter this database beside the relation to ask a smaller question"})
|
| 1659 |
+
return values
|
| 1660 |
+
|
| 1661 |
+
|
| 1662 |
def _related_pin(table_key, session, spec, base_where, wall_params, cur, related):
|
| 1663 |
"""`(sql, params, notes)` for C6's pinned read, or `(None, [], [])` when nothing is pinned.
|
| 1664 |
|
|
|
|
| 1684 |
rather than a literal `id`: `ut_odoo_order_lines` is join-shaped and its identity is `sol.id`,
|
| 1685 |
so a bare `id` would be ambiguous across `sale_order_line` and `sale_order`. It is the same
|
| 1686 |
expression this route already trusts as `tiebreak_sql` and as the fallback ORDER BY.
|
| 1687 |
+
|
| 1688 |
+
ββ W54-T40 / INSTRUCTION 22 / R12 β **A `via` MAY NOW BE A PATH, AND THE PATH IS SERVED.**
|
| 1689 |
+
The owner's second quoted error was this function's own `bad_relation` sentence, and it fired
|
| 1690 |
+
on 18 of the 25 rail tabs of `customer_data`: R12 says the client pins a traversal by naming
|
| 1691 |
+
each edge, so a two-hop tab sends `via` as the ARRAY `["invoices","order_link"]`, and the
|
| 1692 |
+
guard below accepted only the one-hop bag. MEASURED 2026-09-06, 6 of 25 tabs answered 200 and
|
| 1693 |
+
18 answered 400 on the first click.
|
| 1694 |
+
|
| 1695 |
+
ββ ACCEPTING THE ARRAY IS HALF A FIX AND WOULD HAVE MOVED THE ERROR RATHER THAN CLOSED IT.
|
| 1696 |
+
`relations.pick` matches `via.direction` against `DIRECTIONS`, and a two-hop entry's direction
|
| 1697 |
+
is the literal `path`, deliberately outside that tuple so nothing serves half a traversal. So
|
| 1698 |
+
a path resolves through `relations.pick_path` against the DEPTH-AWARE listing, and the read is
|
| 1699 |
+
then answered in TWO steps: hop 1 resolves the intermediate database's own rows to the values
|
| 1700 |
+
hop 2 joins on, and hop 2 pins this database by them. Sending the object form alone answered
|
| 1701 |
+
`400 unknown_relation` and changed nothing the reader could see.
|
| 1702 |
+
|
| 1703 |
+
β EVERY HOP IS STILL PERMISSION CHECKED, AND AT PIN TIME, NOT ONLY AT LISTING TIME (R13). The
|
| 1704 |
+
intermediate is resolved through `_compiled_read`, i.e. THE SAME compiler this door uses for
|
| 1705 |
+
an ordinary read, so its grant, its row wall and its hidden-field closure all apply before a
|
| 1706 |
+
single id crosses into this table's predicate. A second, laxer read of the intermediate would
|
| 1707 |
+
be exactly the permission wall with a hole in it that `related_entries` exists to prevent.
|
| 1708 |
+
β AND AN INTERMEDIATE THIS DOOR CANNOT READ IS A **REPORTED LIMIT**, never a silent empty:
|
| 1709 |
+
`product_data` is a registry module with no read-through binding, so the one enumerated path
|
| 1710 |
+
that passes through it refuses by name with a cause and a recommendation.
|
| 1711 |
"""
|
| 1712 |
import core.relations as relations
|
| 1713 |
|
|
|
|
| 1723 |
source = str(related.get("table") or "")
|
| 1724 |
record = related.get("record")
|
| 1725 |
via = related.get("via")
|
| 1726 |
+
# ββ W54-T40 β `via` IS EITHER ONE EDGE'S BAG OR A PATH OF EDGE KEYS, and `_via_path` is the
|
| 1727 |
+
# one place that decides which. It answers None for the bag, which is what keeps the guard
|
| 1728 |
+
# below spelling the SAME refusal for a genuinely incomplete pin.
|
| 1729 |
+
path = _via_path(via)
|
| 1730 |
+
if not source or record in (None, "") or (path is None and not isinstance(via, dict)):
|
| 1731 |
raise err(400, "bad_relation",
|
| 1732 |
"a pinned read needs the record's database, the record id and the relation to "
|
| 1733 |
+
"follow, as {table, record, via}, where `via` is one relation or the array of "
|
| 1734 |
+
"edge keys naming each hop. Ask GET /api/v1/grid/" + (source or "{table}")
|
| 1735 |
+ "/related for the relations this account may follow")
|
| 1736 |
|
| 1737 |
+
from routes_grid import _may_open, related_entries, related_path_entries
|
| 1738 |
|
| 1739 |
if not _may_open(session, source):
|
| 1740 |
# β THE CAUSE IS NAMED AS A PAIR, ON PURPOSE. `_may_open` is fail-closed and answers False
|
|
|
|
| 1750 |
# β RESOLVED AGAINST THE **SCOPED** LISTING, which is what makes "an edge you cannot be
|
| 1751 |
# offered is an edge you cannot pin" structural rather than remembered. `related_entries` is
|
| 1752 |
# the same function `GET /grid/{table}/related` answers with; there is no second resolution.
|
| 1753 |
+
# β W54-T40 β AND A PATH RESOLVES AGAINST THE DEPTH-AWARE LISTING, WHICH IS THE SAME RULE ONE
|
| 1754 |
+
# LEVEL DEEPER: `related_path_entries` is what `GET /grid/{table}/related?depth=2` answers
|
| 1755 |
+
# with, so a traversal this account is not offered is a traversal it cannot pin either.
|
| 1756 |
+
# β THE DEPTH ASKED FOR IS THE LENGTH OF THE PATH, never a flat 2. A one-element path costs
|
| 1757 |
+
# the depth-1 enumeration it needs and not the depth-2 one, which on `customer_data` is the
|
| 1758 |
+
# difference between roughly half a second and roughly two.
|
| 1759 |
+
if path is None:
|
| 1760 |
+
entries = related_entries(session, source)
|
| 1761 |
+
entry = relations.pick(entries, via)
|
| 1762 |
+
else:
|
| 1763 |
+
if len(path) > relations.MAX_DEPTH:
|
| 1764 |
+
raise err(400, "over_depth", relations.over_depth_refusal(source, path))
|
| 1765 |
+
entries = related_path_entries(session, source, len(path))
|
| 1766 |
+
entry = relations.pick_path(entries, path)
|
| 1767 |
if entry is None:
|
| 1768 |
raise err(400, "unknown_relation", relations.unknown_via_refusal(source, via))
|
| 1769 |
entry = dict(entry, __source__=source)
|
|
|
|
| 1777 |
if not entry.get("served", True):
|
| 1778 |
raise err(409, "relation_not_served", relations.unserved_target_refusal(entry))
|
| 1779 |
|
| 1780 |
+
# ββ W54-T40 β THE **LAST** HOP IS WHAT JOINS THIS DATABASE, and on a two-hop entry that is
|
| 1781 |
+
# not `entry`. A composite carries `via = {direction: 'path', key, path}` and NO `on`, no
|
| 1782 |
+
# `from` and no `where`: `relations._two_hop_entry` refuses to flatten the two hops' predicates
|
| 1783 |
+
# onto the pair, because one of them may carry a predicate the other does not (the open-invoice
|
| 1784 |
+
# bridge is exactly that edge). So the legs are resolved, each from its OWN table's scoped
|
| 1785 |
+
# listing, and the last one is what this block below reads.
|
| 1786 |
+
notes = []
|
| 1787 |
+
first, mid_key, last = entry, "", entry
|
| 1788 |
+
if len(entry.get("path") or ()) > 1:
|
| 1789 |
+
first, mid_key, last = _related_path_legs(session, source, entry, entries)
|
| 1790 |
+
|
| 1791 |
+
on = str((last.get("via") or {}).get("on") or "")
|
| 1792 |
# β `spec["cols"]`, NOT the caller's narrowed `cols`. The join column is a JOIN, not a value
|
| 1793 |
# this response returns: a relation must keep working when an administrator has hidden the id
|
| 1794 |
# column it runs over, and no cell of it is ever projected. The hidden-field closure still
|
| 1795 |
# governs everything that reaches the wire, one layer up.
|
| 1796 |
+
# ββ W54-T40 β AND THE ROW IDENTITY IS NOT ONE OF THOSE COLUMNS. `relations` defaults an edge
|
| 1797 |
+
# with no declared `on` to `pid`, which is the wire's name for the row identity and is never a
|
| 1798 |
+
# key of a mirror spec's `cols` (measured across all eight bound grains on 2026-09-06: not one
|
| 1799 |
+
# carries it). Every such edge therefore refused with "has no live expression for 'pid'" while
|
| 1800 |
+
# the expression was in hand the whole time, as `spec["id"]` - the same per-table identity this
|
| 1801 |
+
# route already uses for the pin itself, for the tiebreak and for the fallback ORDER BY, and
|
| 1802 |
+
# deliberately not a bare `id`, which is ambiguous on a join-shaped grain.
|
| 1803 |
+
if on == relations.IDENTITY_COL:
|
| 1804 |
+
binding = (spec["id"], int)
|
| 1805 |
+
else:
|
| 1806 |
+
binding = (spec.get("cols") or {}).get(on)
|
| 1807 |
if not binding:
|
| 1808 |
raise err(409, "relation_not_served",
|
| 1809 |
f"'{table_key}' has no live expression for '{on}', which is the column this "
|
|
|
|
| 1811 |
f"this database directly, or ask for '{on}' to be added to its live connection")
|
| 1812 |
on_expr, on_cast = binding[0], binding[1]
|
| 1813 |
|
| 1814 |
+
if mid_key:
|
| 1815 |
+
# β HOP 1, ANSWERED BY THE INTERMEDIATE DATABASE ITSELF, UNDER ITS OWN WALL. See
|
| 1816 |
+
# `_related_hop_values`. An empty answer is an ANSWER (this record reaches nothing through
|
| 1817 |
+
# that database) and compiles to `1=0` two blocks down, never to "no pin".
|
| 1818 |
+
values = _related_hop_values(session, source, record, first, mid_key, last, notes)
|
| 1819 |
+
else:
|
| 1820 |
+
value = _related_source_value(session, entry, record)
|
| 1821 |
+
if value in (None, ""):
|
| 1822 |
+
raise err(400, "unknown_relation",
|
| 1823 |
+
relations.unresolvable_source_refusal(source, entry))
|
| 1824 |
+
values = [value]
|
| 1825 |
+
cast = []
|
| 1826 |
+
for one in values:
|
| 1827 |
+
try:
|
| 1828 |
+
cast.append(on_cast(one))
|
| 1829 |
+
except Exception: # noqa: BLE001
|
| 1830 |
+
cast.append(str(one))
|
| 1831 |
|
| 1832 |
# ββ the member ids, in ONE SQL over the bridge column (the ticket's `how:`) ββββββββββββββββ
|
| 1833 |
# β NOT THROUGH `datastore.window`: that clamps at `WINDOW_MAX` (5,000) rows, so a customer
|
|
|
|
| 1837 |
# β THE WALL RIDES ALONG. Resolving ids under `base_where` means the id SET a scoped reader can
|
| 1838 |
# produce is already narrowed to rows they may see, so the pin cannot be used to learn how many
|
| 1839 |
# rows exist beyond their boundary.
|
| 1840 |
+
# β W54-T40 β `= ?` FOR ONE VALUE AND `IN (...)` FOR MANY, and the one-value spelling is kept
|
| 1841 |
+
# BYTE FOR BYTE so a one-hop pin compiles exactly the SQL it compiled before this ticket. The
|
| 1842 |
+
# many-value arm is only ever reached by the second hop of a traversal.
|
| 1843 |
frm_body = spec["from_sql"] if spec.get("from_sql") else spec["table"]
|
| 1844 |
+
ids = []
|
| 1845 |
+
if cast:
|
| 1846 |
+
parts = [p for p in (base_where, last.get("where")) if p]
|
| 1847 |
+
parts.append(f"{on_expr} = ?" if len(cast) == 1
|
| 1848 |
+
else f"{on_expr} IN ({','.join('?' for _ in cast)})")
|
| 1849 |
+
pred = " AND ".join(f"({p})" for p in parts)
|
| 1850 |
+
ids = [int(r[0]) for r in cur.execute(
|
| 1851 |
+
f'SELECT DISTINCT {spec["id"]} FROM {frm_body} WHERE {pred}',
|
| 1852 |
+
list(wall_params) + list(cast)).fetchall() if r and r[0] is not None]
|
| 1853 |
|
|
|
|
| 1854 |
# β STANDING RULE 1'S SECOND SENTENCE, ON A COST RATHER THAN ON A CAP. Nothing is limited
|
| 1855 |
# here; the reader is told that this particular relation is answered by reading the source
|
| 1856 |
# database once per page, because it is keyed on a column rather than on the record id.
|
| 1857 |
+
if str((first.get("via") or {}).get("from") or "") != relations.IDENTITY_COL:
|
| 1858 |
notes.append({
|
| 1859 |
"subject": "related", "effect": "slow",
|
| 1860 |
+
"cause": f"this relation is keyed on the '{first['via']['from']}' column of "
|
| 1861 |
f"'{source}' rather than on its record id, so every page of these rows is "
|
| 1862 |
f"resolved by reading that database first",
|
| 1863 |
"recommendation": "read this database on its own and filter it on "
|
api/routes_sheet.py
CHANGED
|
@@ -98,7 +98,7 @@ def _mirror(session: Session):
|
|
| 98 |
import routes_odoo_tables as rot
|
| 99 |
import odoo_relational as rel
|
| 100 |
|
| 101 |
-
def _for(table_key, *, metric_window=None):
|
| 102 |
fields = None
|
| 103 |
for _bucket, key, _label, mk_fields in rel.TABLES:
|
| 104 |
if key == table_key:
|
|
@@ -131,14 +131,37 @@ def _mirror(session: Session):
|
|
| 131 |
# shape; the cache hangs off the SESSION because that object is built fresh by
|
| 132 |
# `require_session` on every request and dies with it, so nothing can outlive its own
|
| 133 |
# cursor or leak across users. The temp table it names lives in that same cursor.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
memo = getattr(session, "_sheet_mirrors", None)
|
| 135 |
if memo is None:
|
| 136 |
memo = {}
|
| 137 |
session._sheet_mirrors = memo
|
| 138 |
slot = (table_key, json.dumps(metric_window, sort_keys=True, default=str))
|
| 139 |
-
if
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
spec = rot._source_for(cur, table_key)
|
| 143 |
if spec is None:
|
| 144 |
raise err(409, "not_read_through",
|
|
@@ -177,17 +200,34 @@ def _registry_assembly(session: Session, table_key: str):
|
|
| 177 |
field-name correction acks belong to the `/workspace` refresh that exists to show them to the
|
| 178 |
person who made the edit, and a bound cell resolving its scope must not eat them.
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
β AN UNEXPECTED FAILURE REFUSES LOUDLY AND DOES NOT DEGRADE TO THE STATIC CONTRACT. Falling
|
| 181 |
back would answer the cell out of 37 columns while the person is looking at 47, which is the
|
| 182 |
defect this function exists to end, and it would do it with a 200.
|
| 183 |
"""
|
| 184 |
import core.perm_scope as perm_scope
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
try:
|
| 186 |
if table_key == "product_data":
|
| 187 |
from routes_products import product_assembly
|
| 188 |
-
|
|
|
|
|
|
|
| 189 |
from routes_customers import grid_assembly
|
| 190 |
-
|
|
|
|
| 191 |
except perm_scope.Denied:
|
| 192 |
raise err(403, "database_unreadable", f"You cannot read {table_key}.")
|
| 193 |
except HTTPException:
|
|
@@ -207,7 +247,7 @@ def _registry_assembly(session: Session, table_key: str):
|
|
| 207 |
"shown rather than shown from an older set of columns. Try again in a moment.")
|
| 208 |
|
| 209 |
|
| 210 |
-
def _registry_mirror(session: Session, cur, table_key: str, metric_window):
|
| 211 |
"""`(cursor, spec, columns)` for one compiled registry grid, at the cell's own period.
|
| 212 |
|
| 213 |
ββ R7's SECOND HALF LIVES HERE: *"must also be bounded by date time lookup"*. `g["derived"]`
|
|
@@ -226,6 +266,17 @@ def _registry_mirror(session: Session, cur, table_key: str, metric_window):
|
|
| 226 |
`column_values` entirely when `may_metrics` is off, so a column with no value anywhere in
|
| 227 |
`g["derived"]` is one the capability wall has already answered for. Re-resolving it here would
|
| 228 |
be a second answer to that question, from the one door that never asked it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
"""
|
| 230 |
import aios_grid
|
| 231 |
import odoo_relational as rel
|
|
@@ -237,13 +288,17 @@ def _registry_mirror(session: Session, cur, table_key: str, metric_window):
|
|
| 237 |
derived, bounded, limits = _metric_derived(session, table_key, g, metric_window)
|
| 238 |
rows = aios_grid.rows_from_pool(g["rows_src"], fields, (g.get("ws") or {}).get("overlays"),
|
| 239 |
derived=derived)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
# β THE TYPES ARE NORMALISED FOR THE MIRROR ONLY. See `modules/sheet.py::mirror_field_type`:
|
| 241 |
# `metric`, `rating` and a numeric `rollup` are in neither `_REGISTRY_COL_TYPE` nor
|
| 242 |
# `filter_sql.NUMERIC_TYPES`, so without this they land as VARCHAR and compare as strings.
|
| 243 |
# β THE SAME LIST GOES TO BOTH CALLS, deliberately. `registry_grid_spec` picks the SQL type and
|
| 244 |
# `_filter_columns` picks the compiler's type; handing them two different lists is how a column
|
| 245 |
# ends up stored as one thing and compared as another.
|
| 246 |
-
spec_fields = sheet_mod.mirror_fields(
|
| 247 |
spec = rel.registry_grid_spec(cur, table_key, spec_fields, rows)
|
| 248 |
# ββ THE MATERIALISED TABLE IS GIVEN THE WINDOW'S OWN NAME, AND WITHOUT THIS THE MEMO ABOVE
|
| 249 |
# SERVES ONE WINDOW'S ROWS UNDER ANOTHER WINDOW'S ANSWER (found by W53-T14, live).
|
|
@@ -262,8 +317,13 @@ def _registry_mirror(session: Session, cur, table_key: str, metric_window):
|
|
| 262 |
# to an assembly that costs 20 to 130 seconds, so it is not a cost worth conditioning on.
|
| 263 |
# β ALWAYS, INCLUDING THE `None` WINDOW: the unqualified name is REPLACED by every later
|
| 264 |
# build, so leaving the no-period case pointing at it is exactly the case measured above.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
slot = hashlib.sha1(
|
| 266 |
-
json.dumps(metric_window,
|
|
|
|
| 267 |
at_window = f'{spec["table"]}__at_{slot}'
|
| 268 |
cur.execute(f'CREATE OR REPLACE TEMP TABLE "{at_window}" AS '
|
| 269 |
f'SELECT * FROM "{spec["table"]}"')
|
|
@@ -1707,6 +1767,10 @@ def _resolve_binding(session: Session, raw_binding, *, today=None, view_memo=Non
|
|
| 1707 |
3. the ROW wall, fail-closed, refusing 409 when it names a column the mirror cannot answer;
|
| 1708 |
4. the binding's own scope, whose unanswerable columns are REPORTED rather than dropped.
|
| 1709 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1710 |
ββ W53-T13 / R7 β THE PERIOD IS RESOLVED BEFORE THE MIRROR IS OPENED, because it decides what
|
| 1711 |
the Metric columns of that mirror MEAN. `modules/sheet.py::period_window` turns the cell's
|
| 1712 |
`{unit, start}` into the custom window `harness/windows.py` speaks, and `_registry_mirror`
|
|
@@ -1729,7 +1793,28 @@ def _resolve_binding(session: Session, raw_binding, *, today=None, view_memo=Non
|
|
| 1729 |
|
| 1730 |
database = _require_database(session, binding["database"])
|
| 1731 |
window = sheet_mod.period_window(binding.get("period"))
|
| 1732 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1733 |
|
| 1734 |
# β THE COLUMN IS CHECKED BEFORE THE SQL IS BUILT (W53-T13). Now that every tenant column is a
|
| 1735 |
# real column of the materialised table, a `sum` over a text column reaches DuckDB as a binder
|
|
@@ -1742,9 +1827,6 @@ def _resolve_binding(session: Session, raw_binding, *, today=None, view_memo=Non
|
|
| 1742 |
raise err(409, agg_refusal.code, agg_refusal.message)
|
| 1743 |
|
| 1744 |
# ββ the ROW wall, fail-closed ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1745 |
-
wall_tree = ((perm_scope.entry(session.user, database) or {}).get("filter")
|
| 1746 |
-
if perm_scope.row_scope_applies(session.user, database) else None)
|
| 1747 |
-
wall_nodes, wall_conj = _fe_parts(wall_tree)
|
| 1748 |
if wall_nodes:
|
| 1749 |
unknown = sorted(sheet_mod.filter_columns_named(wall_nodes) - set(cols))
|
| 1750 |
if unknown:
|
|
@@ -1759,12 +1841,9 @@ def _resolve_binding(session: Session, raw_binding, *, today=None, view_memo=Non
|
|
| 1759 |
"you on a column this database carries")
|
| 1760 |
|
| 1761 |
# ββ the binding's own scope ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1762 |
-
|
| 1763 |
-
|
| 1764 |
-
|
| 1765 |
-
scope.get("view_name", ""), memo=view_memo)
|
| 1766 |
-
else:
|
| 1767 |
-
scope_nodes, scope_conj = _fe_parts(scope.get("filter"))
|
| 1768 |
|
| 1769 |
# β NOTHING IS DONE HERE ABOUT `needs_excluded`. `_source_for` has already resolved it into the
|
| 1770 |
# spec's column expressions; applying it a second time would double-count the exclusion and
|
|
@@ -1834,6 +1913,129 @@ def preview_cell(workbook_id: str, addr: str, body: dict = Body(default=None),
|
|
| 1834 |
"limits": out["limits"]}
|
| 1835 |
|
| 1836 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1837 |
@router.get("/sheets/{workbook_id}/cells/{addr}/drill")
|
| 1838 |
def drill_cell(workbook_id: str, addr: str, session: Session = Depends(require_session)):
|
| 1839 |
"""`{database, view_id?, filter?, record_ids, count}` for `LinkGridModal` (R6, R13, R17).
|
|
@@ -1876,13 +2078,12 @@ def drill_cell(workbook_id: str, addr: str, session: Session = Depends(require_s
|
|
| 1876 |
raise err(400, exc.code, exc.message)
|
| 1877 |
|
| 1878 |
database = _require_database(session, binding["database"])
|
| 1879 |
-
# β THE SAME PERIOD THE NUMBER WAS COMPUTED AT (W53-T13). The drill probes `COUNT(*)` and never
|
| 1880 |
-
# reads the bound column, but its FILTER may name a Metric column, and a mirror opened at a
|
| 1881 |
-
# different window would answer that condition against different values. The popup would then
|
| 1882 |
-
# list rows the cell's own number never counted.
|
| 1883 |
-
cur, spec, cols = _mirror(session)(
|
| 1884 |
-
database, metric_window=sheet_mod.period_window(binding.get("period")))
|
| 1885 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1886 |
wall_tree = ((perm_scope.entry(session.user, database) or {}).get("filter")
|
| 1887 |
if perm_scope.row_scope_applies(session.user, database) else None)
|
| 1888 |
wall_nodes, wall_conj = _fe_parts(wall_tree)
|
|
@@ -1894,6 +2095,19 @@ def drill_cell(workbook_id: str, addr: str, session: Session = Depends(require_s
|
|
| 1894 |
else:
|
| 1895 |
scope_nodes, scope_conj = _fe_parts(scope.get("filter"))
|
| 1896 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1897 |
count_sql, count_params, limits = sheet_mod.build_aggregate_query(
|
| 1898 |
spec, {"aggregate": {"fn": "count"}}, cols, scope_nodes=scope_nodes,
|
| 1899 |
scope_conj=scope_conj, wall_nodes=wall_nodes, wall_conj=wall_conj)
|
|
@@ -1997,9 +2211,13 @@ def resolve_bindings(workbook_id: str, body: dict = Body(default=None),
|
|
| 1997 |
ββ THE BATCH PAYS FOR ITS ASSEMBLY ONCE, WHICH IS MOST OF THE REASON THIS DOOR TAKES A LIST
|
| 1998 |
AT ALL. A bound cell on a compiled registry grid (`customer_data`, `product_data`) costs a
|
| 1999 |
full workspace assembly - measured at 20 to 130 seconds on this box after W53-T13 - so N cells
|
| 2000 |
-
resolved one request each would cost N of them.
|
|
|
|
|
|
|
| 2001 |
- `session._sheet_mirrors`, keyed `(table_key, metric_window)` inside `_mirror`, so every
|
| 2002 |
-
cell on one database at one period shares one
|
|
|
|
|
|
|
| 2003 |
the Session, which `require_session` builds fresh per request and drops with it.
|
| 2004 |
- `view_memo`, keyed by `view_id`, so a saved-view scope is looked up once for the batch.
|
| 2005 |
β AND IDENTICAL BINDINGS RESOLVE ONCE. Two cells carrying the same database, aggregate, scope
|
|
|
|
| 98 |
import routes_odoo_tables as rot
|
| 99 |
import odoo_relational as rel
|
| 100 |
|
| 101 |
+
def _for(table_key, *, metric_window=None, needed=None):
|
| 102 |
fields = None
|
| 103 |
for _bucket, key, _label, mk_fields in rel.TABLES:
|
| 104 |
if key == table_key:
|
|
|
|
| 131 |
# shape; the cache hangs off the SESSION because that object is built fresh by
|
| 132 |
# `require_session` on every request and dies with it, so nothing can outlive its own
|
| 133 |
# cursor or leak across users. The temp table it names lives in that same cursor.
|
| 134 |
+
#
|
| 135 |
+
# ββ W54-T36 β AND ONLY THE COLUMNS THE CELL ACTUALLY READS ARE MATERIALISED.
|
| 136 |
+
# MEASURED on tenant #0's `customer_data` (3,673 records, 47 columns), warm, through
|
| 137 |
+
# the real `drill_cell`: 8,437 ms total, of which `odoo_relational.registry_grid_spec`
|
| 138 |
+
# is 6,137 ms. That step turns every row into a tuple of 47 Python values and
|
| 139 |
+
# `executemany`s it, so its cost is per COLUMN, and a drill reads none of them: it
|
| 140 |
+
# counts records and lists ids. `needed` is the honest set (the aggregate's column,
|
| 141 |
+
# plus every column the cell's filter and the row wall name); `None` still means the
|
| 142 |
+
# whole grid, so a caller that has not worked out its set loses nothing.
|
| 143 |
+
#
|
| 144 |
+
# β THE MEMO WIDENS, IT NEVER NARROWS, and that is what keeps `refresh_sheet` safe.
|
| 145 |
+
# A slot already built for a wider set answers a narrower request unchanged; a request
|
| 146 |
+
# naming a column the slot does not carry rebuilds at the UNION, so a workbook whose
|
| 147 |
+
# cells read different columns converges instead of rebuilding per cell. A `None`
|
| 148 |
+
# entry means every column is present and is reusable by anything.
|
| 149 |
memo = getattr(session, "_sheet_mirrors", None)
|
| 150 |
if memo is None:
|
| 151 |
memo = {}
|
| 152 |
session._sheet_mirrors = memo
|
| 153 |
slot = (table_key, json.dumps(metric_window, sort_keys=True, default=str))
|
| 154 |
+
want = None if needed is None else {str(k) for k in needed}
|
| 155 |
+
entry = memo.get(slot)
|
| 156 |
+
if entry is not None:
|
| 157 |
+
built, made = entry
|
| 158 |
+
if built is None or (want is not None and want <= built):
|
| 159 |
+
return made
|
| 160 |
+
if want is not None:
|
| 161 |
+
want = set(want) | built
|
| 162 |
+
made = _registry_mirror(session, cur, table_key, metric_window, needed=want)
|
| 163 |
+
memo[slot] = (None if want is None else set(want), made)
|
| 164 |
+
return made
|
| 165 |
spec = rot._source_for(cur, table_key)
|
| 166 |
if spec is None:
|
| 167 |
raise err(409, "not_read_through",
|
|
|
|
| 200 |
field-name correction acks belong to the `/workspace` refresh that exists to show them to the
|
| 201 |
person who made the edit, and a bound cell resolving its scope must not eat them.
|
| 202 |
|
| 203 |
+
ββ W54-T36 β ONE ASSEMBLY PER DATABASE PER REQUEST, memoised on the SESSION exactly as
|
| 204 |
+
`_mirror` memoises the mirror and for the same lifetime reason: `require_session` builds that
|
| 205 |
+
object per request and it dies with the request, so nothing here outlives its own cursor or
|
| 206 |
+
reaches another account. MEASURED on tenant #0's `customer_data`, warm: 2,145 ms a call. It
|
| 207 |
+
already ran once per (database, window); it now also survives a mirror rebuilt at a wider
|
| 208 |
+
column set, and every caller BELOW reuses it. `_offered_view` reaches for `grid_assembly` and
|
| 209 |
+
`product_assembly` on its own and is a separate cost; see its own note.
|
| 210 |
+
|
| 211 |
β AN UNEXPECTED FAILURE REFUSES LOUDLY AND DOES NOT DEGRADE TO THE STATIC CONTRACT. Falling
|
| 212 |
back would answer the cell out of 37 columns while the person is looking at 47, which is the
|
| 213 |
defect this function exists to end, and it would do it with a 200.
|
| 214 |
"""
|
| 215 |
import core.perm_scope as perm_scope
|
| 216 |
+
memo = getattr(session, "_sheet_assemblies", None)
|
| 217 |
+
if memo is None:
|
| 218 |
+
memo = {}
|
| 219 |
+
session._sheet_assemblies = memo
|
| 220 |
+
if table_key in memo:
|
| 221 |
+
return memo[table_key]
|
| 222 |
try:
|
| 223 |
if table_key == "product_data":
|
| 224 |
from routes_products import product_assembly
|
| 225 |
+
memo[table_key] = product_assembly(session, scope="product",
|
| 226 |
+
consume_corrections=False)
|
| 227 |
+
return memo[table_key]
|
| 228 |
from routes_customers import grid_assembly
|
| 229 |
+
memo[table_key] = grid_assembly(session, scope="customer", consume_corrections=False)
|
| 230 |
+
return memo[table_key]
|
| 231 |
except perm_scope.Denied:
|
| 232 |
raise err(403, "database_unreadable", f"You cannot read {table_key}.")
|
| 233 |
except HTTPException:
|
|
|
|
| 247 |
"shown rather than shown from an older set of columns. Try again in a moment.")
|
| 248 |
|
| 249 |
|
| 250 |
+
def _registry_mirror(session: Session, cur, table_key: str, metric_window, needed=None):
|
| 251 |
"""`(cursor, spec, columns)` for one compiled registry grid, at the cell's own period.
|
| 252 |
|
| 253 |
ββ R7's SECOND HALF LIVES HERE: *"must also be bounded by date time lookup"*. `g["derived"]`
|
|
|
|
| 266 |
`column_values` entirely when `may_metrics` is off, so a column with no value anywhere in
|
| 267 |
`g["derived"]` is one the capability wall has already answered for. Re-resolving it here would
|
| 268 |
be a second answer to that question, from the one door that never asked it.
|
| 269 |
+
|
| 270 |
+
ββ W54-T36 β `needed` IS THE COLUMN SET THIS CELL CAN POSSIBLY READ, AND `None` IS EVERY
|
| 271 |
+
COLUMN. It narrows what gets MATERIALISED, never what gets assembled: `g` is the same scoped
|
| 272 |
+
assembly, `rows` are the same scoped rows, and `spec["fields"]` below is still the FULL list
|
| 273 |
+
so a refusal can name a column the mirror did not carry.
|
| 274 |
+
|
| 275 |
+
ββ IT IS INTERSECTED WITH THE ASSEMBLY'S OWN FIELDS AND MUST STAY THAT WAY. `cols` is what
|
| 276 |
+
`_resolve_binding` subtracts a row wall's columns from to decide whether the wall can be
|
| 277 |
+
applied at all, and that check is FAIL CLOSED (409 `scope_not_applicable`). Materialising a
|
| 278 |
+
column just because a filter named it would invent an empty column for a name this database
|
| 279 |
+
does not have, and the wall would then compile against nothing and quietly stop restricting.
|
| 280 |
"""
|
| 281 |
import aios_grid
|
| 282 |
import odoo_relational as rel
|
|
|
|
| 288 |
derived, bounded, limits = _metric_derived(session, table_key, g, metric_window)
|
| 289 |
rows = aios_grid.rows_from_pool(g["rows_src"], fields, (g.get("ws") or {}).get("overlays"),
|
| 290 |
derived=derived)
|
| 291 |
+
# The columns this cell can read, in the assembly's own order. `registry_grid_spec` forces
|
| 292 |
+
# `pid` in on its own, because `build_ids_query` needs `spec["id"]` to be a real column.
|
| 293 |
+
kept = (fields if needed is None
|
| 294 |
+
else [f for f in fields if str(f.get("key") or "") in needed])
|
| 295 |
# β THE TYPES ARE NORMALISED FOR THE MIRROR ONLY. See `modules/sheet.py::mirror_field_type`:
|
| 296 |
# `metric`, `rating` and a numeric `rollup` are in neither `_REGISTRY_COL_TYPE` nor
|
| 297 |
# `filter_sql.NUMERIC_TYPES`, so without this they land as VARCHAR and compare as strings.
|
| 298 |
# β THE SAME LIST GOES TO BOTH CALLS, deliberately. `registry_grid_spec` picks the SQL type and
|
| 299 |
# `_filter_columns` picks the compiler's type; handing them two different lists is how a column
|
| 300 |
# ends up stored as one thing and compared as another.
|
| 301 |
+
spec_fields = sheet_mod.mirror_fields(kept)
|
| 302 |
spec = rel.registry_grid_spec(cur, table_key, spec_fields, rows)
|
| 303 |
# ββ THE MATERIALISED TABLE IS GIVEN THE WINDOW'S OWN NAME, AND WITHOUT THIS THE MEMO ABOVE
|
| 304 |
# SERVES ONE WINDOW'S ROWS UNDER ANOTHER WINDOW'S ANSWER (found by W53-T14, live).
|
|
|
|
| 317 |
# to an assembly that costs 20 to 130 seconds, so it is not a cost worth conditioning on.
|
| 318 |
# β ALWAYS, INCLUDING THE `None` WINDOW: the unqualified name is REPLACED by every later
|
| 319 |
# build, so leaving the no-period case pointing at it is exactly the case measured above.
|
| 320 |
+
# ββ W54-T36 β THE COLUMN SET IS PART OF THAT NAME FOR THE SAME REASON THE WINDOW IS. Two
|
| 321 |
+
# cells on one database at one window may now be materialised over DIFFERENT columns, and a
|
| 322 |
+
# narrower later build would otherwise replace a wider earlier one under a spec the memo is
|
| 323 |
+
# still holding, so a query would address a column its own table no longer has.
|
| 324 |
slot = hashlib.sha1(
|
| 325 |
+
json.dumps([metric_window, None if needed is None else sorted(needed)],
|
| 326 |
+
sort_keys=True, default=str).encode("utf-8")).hexdigest()[:12]
|
| 327 |
at_window = f'{spec["table"]}__at_{slot}'
|
| 328 |
cur.execute(f'CREATE OR REPLACE TEMP TABLE "{at_window}" AS '
|
| 329 |
f'SELECT * FROM "{spec["table"]}"')
|
|
|
|
| 1767 |
3. the ROW wall, fail-closed, refusing 409 when it names a column the mirror cannot answer;
|
| 1768 |
4. the binding's own scope, whose unanswerable columns are REPORTED rather than dropped.
|
| 1769 |
|
| 1770 |
+
β W54-T36 β THE WALL AND THE SCOPE ARE NOW READ BEFORE STEP 2 SO THE MIRROR KNOWS WHICH
|
| 1771 |
+
COLUMNS TO MATERIALISE. Steps 3 and 4 still happen where they did: the wall is still checked
|
| 1772 |
+
against `cols` after the mirror exists, and it still refuses fail closed.
|
| 1773 |
+
|
| 1774 |
ββ W53-T13 / R7 β THE PERIOD IS RESOLVED BEFORE THE MIRROR IS OPENED, because it decides what
|
| 1775 |
the Metric columns of that mirror MEAN. `modules/sheet.py::period_window` turns the cell's
|
| 1776 |
`{unit, start}` into the custom window `harness/windows.py` speaks, and `_registry_mirror`
|
|
|
|
| 1793 |
|
| 1794 |
database = _require_database(session, binding["database"])
|
| 1795 |
window = sheet_mod.period_window(binding.get("period"))
|
| 1796 |
+
|
| 1797 |
+
# ββ W54-T36 β THE WALL AND THE SCOPE ARE READ BEFORE THE MIRROR IS OPENED, so the mirror can
|
| 1798 |
+
# be built over the columns this cell can possibly read instead of over the whole database.
|
| 1799 |
+
# Neither read touches the mirror: the wall comes from `perm_scope` and the scope from the
|
| 1800 |
+
# stored view document, which is why the order can move at all.
|
| 1801 |
+
# β WHAT MUST NOT MOVE IS THE WALL'S OWN CHECK. It subtracts the wall's columns from `cols`
|
| 1802 |
+
# and refuses 409 when one is missing, so it still runs AFTER the mirror exists, below.
|
| 1803 |
+
wall_tree = ((perm_scope.entry(session.user, database) or {}).get("filter")
|
| 1804 |
+
if perm_scope.row_scope_applies(session.user, database) else None)
|
| 1805 |
+
wall_nodes, wall_conj = _fe_parts(wall_tree)
|
| 1806 |
+
scope = binding["scope"]
|
| 1807 |
+
if scope.get("view_id"):
|
| 1808 |
+
scope_nodes, scope_conj = _view_filter(session, database, scope["view_id"],
|
| 1809 |
+
scope.get("view_name", ""), memo=view_memo)
|
| 1810 |
+
else:
|
| 1811 |
+
scope_nodes, scope_conj = _fe_parts(scope.get("filter"))
|
| 1812 |
+
needed = (sheet_mod.filter_columns_named(scope_nodes)
|
| 1813 |
+
| sheet_mod.filter_columns_named(wall_nodes))
|
| 1814 |
+
if binding["aggregate"].get("field"):
|
| 1815 |
+
needed.add(str(binding["aggregate"]["field"]))
|
| 1816 |
+
|
| 1817 |
+
cur, spec, cols = _mirror(session)(database, metric_window=window, needed=needed)
|
| 1818 |
|
| 1819 |
# β THE COLUMN IS CHECKED BEFORE THE SQL IS BUILT (W53-T13). Now that every tenant column is a
|
| 1820 |
# real column of the materialised table, a `sum` over a text column reaches DuckDB as a binder
|
|
|
|
| 1827 |
raise err(409, agg_refusal.code, agg_refusal.message)
|
| 1828 |
|
| 1829 |
# ββ the ROW wall, fail-closed ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
|
|
|
|
|
|
| 1830 |
if wall_nodes:
|
| 1831 |
unknown = sorted(sheet_mod.filter_columns_named(wall_nodes) - set(cols))
|
| 1832 |
if unknown:
|
|
|
|
| 1841 |
"you on a column this database carries")
|
| 1842 |
|
| 1843 |
# ββ the binding's own scope ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1844 |
+
# β W54-T36 β READ ABOVE, WITH THE WALL, because the mirror is now built over the columns the
|
| 1845 |
+
# two of them name. The contract's ORDER is unchanged: the wall is still applied and still
|
| 1846 |
+
# checked against `cols` before the scope reaches the compiler.
|
|
|
|
|
|
|
|
|
|
| 1847 |
|
| 1848 |
# β NOTHING IS DONE HERE ABOUT `needs_excluded`. `_source_for` has already resolved it into the
|
| 1849 |
# spec's column expressions; applying it a second time would double-count the exclusion and
|
|
|
|
| 1913 |
"limits": out["limits"]}
|
| 1914 |
|
| 1915 |
|
| 1916 |
+
@router.post("/sheets/{workbook_id}/cells/{addr}/compute")
|
| 1917 |
+
def compute_cell(workbook_id: str, addr: str, body: dict = Body(default=None),
|
| 1918 |
+
session: Session = Depends(require_session)):
|
| 1919 |
+
"""W54-T32 (instruction 9): recompute ONE stored bound cell and persist just that cell.
|
| 1920 |
+
|
| 1921 |
+
ββ THE WHOLE OF THE TICKET IS THAT `refresh_sheet` WAS THE ONLY DOOR THAT COMPUTED. Saving a
|
| 1922 |
+
binding wrote a `stale` cell and nothing ever resolved it, so the shimmer that means "a number
|
| 1923 |
+
is coming" ran until somebody pressed Refresh. Refresh answers by recomputing EVERY bound cell
|
| 1924 |
+
and every formula in the workbook, which is why it is slow and why the save path must not call
|
| 1925 |
+
it: one cell over `ut_odoo_orders` measured 55 to 90 ms through `preview`, against a whole
|
| 1926 |
+
workbook pass plus a full document write.
|
| 1927 |
+
|
| 1928 |
+
β IT IS A WRITE DOOR, so `_require_editor` runs FIRST, exactly as it does on `refresh_sheet`
|
| 1929 |
+
and for the same C5 reason: this ends in a store write, and a viewer's numbers must never land
|
| 1930 |
+
in the owner's document. A viewer's own re-resolve still happens in memory on the READ path.
|
| 1931 |
+
|
| 1932 |
+
ββ THE STORED `binding` IS NEVER REWRITTEN HERE, AND THAT IS D-674's HALF OF THIS TICKET.
|
| 1933 |
+
Only `state`, `value`, `display`, `refreshed_at` and `refusal` are touched on a COPY of the
|
| 1934 |
+
cell; the binding object is carried through verbatim. So a binding that arrived without a
|
| 1935 |
+
`period` cannot acquire one by being computed, whatever a later editor does with the panel.
|
| 1936 |
+
|
| 1937 |
+
ββ AND IT FILLS THE ONE SCOPE-CACHE SLOT IT JUST COMPUTED, WHICH IS THE TRAP IN THIS FILE.
|
| 1938 |
+
`_reresolved_for_reader` serves a non-owner from `core.sheets.cached_scope_value`, keyed
|
| 1939 |
+
`(database, wall, binding scope)`; persisting a new number and leaving the old slot behind
|
| 1940 |
+
would make the very next GET serve the number this door was called to replace. There is no
|
| 1941 |
+
per-cell clear, and `clear_scope_cache` belongs to `refresh_sheet` alone under R3, so the
|
| 1942 |
+
surgical answer is `fill_scope_cache` on exactly the slot this caller is entitled to, which is
|
| 1943 |
+
the same call and the same key `_reresolved_for_reader` makes after its own resolve.
|
| 1944 |
+
|
| 1945 |
+
β NO FORMULA PASS RUNS HERE, DELIBERATELY. `_recomputed_tab_cells` recomputes the WHOLE
|
| 1946 |
+
workbook's formulas, which the prototype measured at 2.9 s as a FLOOR for the owner's 11,300
|
| 1947 |
+
formulas: fifty times the cost of the one number this door exists to deliver. The client
|
| 1948 |
+
evaluates its own formulas as the value lands (`sheetState.ts`), the ordinary cell PATCH
|
| 1949 |
+
already runs the server-side pass on the very next commit, and Refresh still runs it for
|
| 1950 |
+
everyone. A formula's STORED value therefore stays as last computed until one of those, which
|
| 1951 |
+
is what a stale bound cell already did before this ticket.
|
| 1952 |
+
|
| 1953 |
+
β `rev` BUMPS, BECAUSE THIS PERSISTS. It goes back in the answer and the client adopts it, or
|
| 1954 |
+
its next PATCH would carry a revision the server has already moved past.
|
| 1955 |
+
"""
|
| 1956 |
+
from core import sheets
|
| 1957 |
+
|
| 1958 |
+
try:
|
| 1959 |
+
book = sheets.get_workbook(_store(session), workbook_id)
|
| 1960 |
+
_require_editor(session, book)
|
| 1961 |
+
except sheets.SheetRefusal as exc:
|
| 1962 |
+
raise _refuse(exc)
|
| 1963 |
+
|
| 1964 |
+
key = str(addr or "").replace("$", "").upper()
|
| 1965 |
+
#: β THE TAB IS NAMED BY THE CALLER WHEN IT KNOWS ONE, and looked up by address when it does
|
| 1966 |
+
#: not, which is `drill_cell`'s behaviour. Two tabs may legally hold the same address, so a
|
| 1967 |
+
#: client that has a tab in hand should say which, or the first one wins.
|
| 1968 |
+
ref = str((body or {}).get("tab") or "").strip()
|
| 1969 |
+
tab, cell = None, None
|
| 1970 |
+
if ref:
|
| 1971 |
+
try:
|
| 1972 |
+
tab = sheets.find_tab(book, ref)
|
| 1973 |
+
except sheets.SheetRefusal as exc:
|
| 1974 |
+
raise _refuse(exc)
|
| 1975 |
+
cell = (tab.get("cells") or {}).get(key)
|
| 1976 |
+
else:
|
| 1977 |
+
for candidate in book.get("sheets") or ():
|
| 1978 |
+
if key in (candidate.get("cells") or {}):
|
| 1979 |
+
tab, cell = candidate, candidate["cells"][key]
|
| 1980 |
+
break
|
| 1981 |
+
if not isinstance(cell, dict):
|
| 1982 |
+
raise err(404, "cell_missing", f"Cell {key} is not filled in.")
|
| 1983 |
+
if cell.get("kind") != "bound":
|
| 1984 |
+
raise err(409, "cell_not_bound", f"Cell {key} is not bound to a database.")
|
| 1985 |
+
|
| 1986 |
+
tab_ref = str((tab or {}).get("id") or (tab or {}).get("name") or "")
|
| 1987 |
+
binding = cell.get("binding") or {}
|
| 1988 |
+
stamp = _now_iso()
|
| 1989 |
+
saved = dict(cell)
|
| 1990 |
+
limits, resolved = [], None
|
| 1991 |
+
try:
|
| 1992 |
+
resolved = _resolve_binding(session, binding)
|
| 1993 |
+
except HTTPException as exc:
|
| 1994 |
+
#: The same per-cell refusal shape `refresh_sheet` writes, so a cell refused by this door
|
| 1995 |
+
#: and a cell refused by that one read identically. It is PERSISTED rather than raised:
|
| 1996 |
+
#: a cell left `stale` would shimmer forever, and the reason belongs on the cell.
|
| 1997 |
+
detail = getattr(exc, "detail", None) or {}
|
| 1998 |
+
info = detail.get("error") if isinstance(detail, dict) else None
|
| 1999 |
+
saved["state"] = "refused"
|
| 2000 |
+
saved["value"] = None
|
| 2001 |
+
saved["display"] = ""
|
| 2002 |
+
saved["refusal"] = {
|
| 2003 |
+
"code": (info or {}).get("code", "sheet_unresolved"),
|
| 2004 |
+
"message": (info or {}).get("message", "This cell could not be refreshed."),
|
| 2005 |
+
}
|
| 2006 |
+
else:
|
| 2007 |
+
limits = resolved["limits"]
|
| 2008 |
+
saved["state"] = "fresh"
|
| 2009 |
+
saved["value"] = resolved["value"]
|
| 2010 |
+
saved["display"] = "" if resolved["value"] is None else str(resolved["value"])
|
| 2011 |
+
saved["refreshed_at"] = stamp
|
| 2012 |
+
saved.pop("refusal", None)
|
| 2013 |
+
|
| 2014 |
+
try:
|
| 2015 |
+
landed = sheets.patch_cells(_store(session), workbook_id, tab_ref, {key: saved})
|
| 2016 |
+
except sheets.SheetRefusal as exc:
|
| 2017 |
+
raise _refuse(exc)
|
| 2018 |
+
|
| 2019 |
+
if resolved is not None:
|
| 2020 |
+
#: Best effort, exactly as `_reresolved_for_reader` fills its own slot: a cache write that
|
| 2021 |
+
#: fails costs a future recompute and never a wrong number.
|
| 2022 |
+
try:
|
| 2023 |
+
sheets.fill_scope_cache(_store(session), workbook_id, tab_ref + "!" + key,
|
| 2024 |
+
_binding_scope_key(session,
|
| 2025 |
+
str(binding.get("database") or ""),
|
| 2026 |
+
binding),
|
| 2027 |
+
resolved["value"], stamp)
|
| 2028 |
+
except Exception: # noqa: BLE001
|
| 2029 |
+
pass
|
| 2030 |
+
|
| 2031 |
+
wire = dict(saved)
|
| 2032 |
+
#: β `limits` RIDES THE ANSWER AND IS NOT STORED, because `core.sheets.clean_cell` carries no
|
| 2033 |
+
#: such key: it describes THIS resolve's truncation, not the cell.
|
| 2034 |
+
if limits:
|
| 2035 |
+
wire["limits"] = limits
|
| 2036 |
+
return {"cell": wire, "rev": landed.get("rev"), "tab": tab_ref, "addr": key}
|
| 2037 |
+
|
| 2038 |
+
|
| 2039 |
@router.get("/sheets/{workbook_id}/cells/{addr}/drill")
|
| 2040 |
def drill_cell(workbook_id: str, addr: str, session: Session = Depends(require_session)):
|
| 2041 |
"""`{database, view_id?, filter?, record_ids, count}` for `LinkGridModal` (R6, R13, R17).
|
|
|
|
| 2078 |
raise err(400, exc.code, exc.message)
|
| 2079 |
|
| 2080 |
database = _require_database(session, binding["database"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2081 |
|
| 2082 |
+
# ββ W54-T36 β THE WALL AND THE SCOPE ARE READ FIRST, AND THE MIRROR IS BUILT OVER WHAT THEY
|
| 2083 |
+
# NAME. The drill probes `COUNT(*)` and lists ids, so on a cell whose scope is a plain view or
|
| 2084 |
+
# an empty filter the honest column set is EMPTY and only the id column is materialised.
|
| 2085 |
+
# MEASURED on tenant #0's `customer_data` (3,673 records, 47 columns), warm, through this
|
| 2086 |
+
# route: 8,437 ms, of which 6,137 ms was materialising columns no query here reads.
|
| 2087 |
wall_tree = ((perm_scope.entry(session.user, database) or {}).get("filter")
|
| 2088 |
if perm_scope.row_scope_applies(session.user, database) else None)
|
| 2089 |
wall_nodes, wall_conj = _fe_parts(wall_tree)
|
|
|
|
| 2095 |
else:
|
| 2096 |
scope_nodes, scope_conj = _fe_parts(scope.get("filter"))
|
| 2097 |
|
| 2098 |
+
# β THE SAME PERIOD THE NUMBER WAS COMPUTED AT (W53-T13). The drill probes `COUNT(*)` and never
|
| 2099 |
+
# reads the bound column, but its FILTER may name a Metric column, and a mirror opened at a
|
| 2100 |
+
# different window would answer that condition against different values. The popup would then
|
| 2101 |
+
# list rows the cell's own number never counted.
|
| 2102 |
+
# β W54-T36 MEASURED WHAT THAT WINDOW COSTS, because the cheaper mirror was the obvious guess:
|
| 2103 |
+
# `_metric_derived` at a month window is 27 ms of an 8,437 ms drill on `customer_data`. So the
|
| 2104 |
+
# window is kept UNCONDITIONALLY, exactly as W53-T13 wrote it, and the saving is taken from
|
| 2105 |
+
# the column set instead, where the time actually is.
|
| 2106 |
+
cur, spec, cols = _mirror(session)(
|
| 2107 |
+
database, metric_window=sheet_mod.period_window(binding.get("period")),
|
| 2108 |
+
needed=(sheet_mod.filter_columns_named(scope_nodes)
|
| 2109 |
+
| sheet_mod.filter_columns_named(wall_nodes)))
|
| 2110 |
+
|
| 2111 |
count_sql, count_params, limits = sheet_mod.build_aggregate_query(
|
| 2112 |
spec, {"aggregate": {"fn": "count"}}, cols, scope_nodes=scope_nodes,
|
| 2113 |
scope_conj=scope_conj, wall_nodes=wall_nodes, wall_conj=wall_conj)
|
|
|
|
| 2211 |
ββ THE BATCH PAYS FOR ITS ASSEMBLY ONCE, WHICH IS MOST OF THE REASON THIS DOOR TAKES A LIST
|
| 2212 |
AT ALL. A bound cell on a compiled registry grid (`customer_data`, `product_data`) costs a
|
| 2213 |
full workspace assembly - measured at 20 to 130 seconds on this box after W53-T13 - so N cells
|
| 2214 |
+
resolved one request each would cost N of them. Three memos make one request pay once:
|
| 2215 |
+
- `session._sheet_assemblies`, keyed by `table_key` inside `_registry_assembly` (W54-T36),
|
| 2216 |
+
so the assembly itself is built once per database however many mirrors are cut from it.
|
| 2217 |
- `session._sheet_mirrors`, keyed `(table_key, metric_window)` inside `_mirror`, so every
|
| 2218 |
+
cell on one database at one period shares one temp table. W54-T36 also gave each slot the
|
| 2219 |
+
COLUMN SET it was materialised over: a narrower cell reuses a wider slot, and a cell
|
| 2220 |
+
naming a column the slot lacks rebuilds at the union rather than per cell. Both hang off
|
| 2221 |
the Session, which `require_session` builds fresh per request and drops with it.
|
| 2222 |
- `view_memo`, keyed by `view_id`, so a saved-view scope is looked up once for the batch.
|
| 2223 |
β AND IDENTICAL BINDINGS RESOLVE ONCE. Two cells carrying the same database, aggregate, scope
|
platform/core/keychain.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
|
| 3 |
An admin stores a data source's secrets (Royal's Odoo API key today; any tenant's sources
|
| 4 |
tomorrow) encrypted at rest in the TENANT's store bucket. The runtime posture is R3's
|
| 5 |
-
"live with env fallback": the connector layer asks `odoo_creds(rt)` FIRST and falls back to
|
| 6 |
the process environment (tenant #0's `.env` / Space secrets), so Royal keeps working with an
|
| 7 |
empty keychain and a new tenant needs no code to bring keys. The FULL cutover (env retired)
|
| 8 |
is staged for a later wave β R3, verbatim.
|
|
@@ -14,7 +14,7 @@ decrypts and writes are refused β fail closed, never a plaintext fallback.
|
|
| 14 |
|
| 15 |
SHAPE (bucket `keychain`, per-tenant via the runtime handle):
|
| 16 |
|
| 17 |
-
{entries: {id: {id, label, type, enc, preview, created, createdBy}}}
|
| 18 |
|
| 19 |
`enc` = Fernet token over the JSON fields dict. `preview` = a masked hint ("Β·Β·Β·Β·1234")
|
| 20 |
computed ONCE at write from the entry's most secret-looking field β the ONLY part of a
|
|
@@ -92,27 +92,129 @@ def _bucket(rt):
|
|
| 92 |
return rt.get(KEY) or {}
|
| 93 |
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
def list_entries(rt):
|
| 96 |
-
"""Metadata ONLY β never a decrypted field, never `enc` itself.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
out = []
|
|
|
|
| 98 |
for eid, e in sorted((_bucket(rt).get('entries') or {}).items()):
|
| 99 |
if not isinstance(e, dict):
|
| 100 |
continue
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
'preview': e.get('preview') or '',
|
| 104 |
'created': e.get('created') or '',
|
| 105 |
'createdBy': e.get('createdBy') or ''})
|
| 106 |
return out
|
| 107 |
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
def add_entry(rt, label, etype, fields, username):
|
| 110 |
"""Encrypt + store. Returns the metadata row, or raises ValueError on shape problems and
|
| 111 |
-
KeychainLocked when there is no key (a secret must never be stored in the clear).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
label = ' '.join(str(label or '').split())[:80]
|
| 113 |
etype = str(etype or '').strip().lower()
|
| 114 |
-
if not label:
|
| 115 |
-
raise ValueError('give the key a label')
|
| 116 |
if etype not in ENTRY_TYPES:
|
| 117 |
raise ValueError(f"type must be one of {', '.join(sorted(ENTRY_TYPES))}")
|
| 118 |
if not isinstance(fields, dict) or not fields:
|
|
@@ -128,7 +230,11 @@ def add_entry(rt, label, etype, fields, username):
|
|
| 128 |
secretish = next((clean[k] for k in _PREVIEW_FIELDS if clean.get(k)), '')
|
| 129 |
preview = ('Β·Β·Β·Β·' + secretish[-4:]) if len(secretish) >= 4 else ('Β·Β·Β·Β·' if secretish else '')
|
| 130 |
eid = f'k_{_secrets.token_hex(6)}'
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
'preview': preview,
|
| 133 |
'created': _dt.datetime.now().strftime('%Y-%m-%dT%H:%M:%S'),
|
| 134 |
'createdBy': str(username or '')}
|
|
@@ -141,10 +247,42 @@ def add_entry(rt, label, etype, fields, username):
|
|
| 141 |
return cur
|
| 142 |
|
| 143 |
rt.update(KEY, _up, flush='sync')
|
| 144 |
-
return {'id': eid, '
|
|
|
|
| 145 |
'created': row['created'], 'createdBy': row['createdBy']}
|
| 146 |
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
def delete_entry(rt, entry_id):
|
| 149 |
def _drop(cur):
|
| 150 |
(cur.get('entries') or {}).pop(str(entry_id), None)
|
|
@@ -174,12 +312,19 @@ def read_fields(rt, entry_id):
|
|
| 174 |
|
| 175 |
|
| 176 |
def first_entry_of_type(rt, etype):
|
| 177 |
-
"""
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
"""
|
| 184 |
return next((e for e in list_entries(rt) if e.get('type') == str(etype or '')), None)
|
| 185 |
|
|
@@ -188,9 +333,11 @@ def ensure_entry_of_type(rt, etype, label, fields, username):
|
|
| 188 |
"""Create ONE entry of `etype` only if the tenant has none. `(row, why)`; `row` is None on skip.
|
| 189 |
|
| 190 |
β W35-T45 / R11 β the primitive tenant #0's env-to-keychain migration is built from, and the
|
| 191 |
-
reason it lives here is that only this module knows what "already has one" means
|
| 192 |
-
|
| 193 |
-
|
|
|
|
|
|
|
| 194 |
|
| 195 |
β IDEMPOTENT BY TYPE, NOT BY A FLAG. A migration that keys idempotency on a marker it writes
|
| 196 |
itself is one lost marker away from running twice ([[a-migration-that-runs-on-the-next-write]]);
|
|
@@ -219,13 +366,24 @@ def ensure_entry_of_type(rt, etype, label, fields, username):
|
|
| 219 |
return None, f'{type(exc).__name__}: {exc}'
|
| 220 |
|
| 221 |
|
| 222 |
-
def odoo_creds(rt):
|
| 223 |
-
"""R3's resolver seam: the
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
| 227 |
|
| 228 |
-
def meta_creds(rt):
|
| 229 |
"""W31 (R2): the FIRST `meta_ads` entry's fields, else None β the Meta connector's resolver.
|
| 230 |
|
| 231 |
ββ W49-T13 / D-202 β IT HAS A PRODUCTION CALLER NOW, AND THAT WAS THE WHOLE DEFECT.
|
|
@@ -246,11 +404,15 @@ def meta_creds(rt):
|
|
| 246 |
is no equivalent for Meta: `META_ADS_ACCESS_TOKEN` is the OWNER's measurement token (R8), and
|
| 247 |
handing it to a tenant whose admin has not stored one is precisely the leak the R3 rule
|
| 248 |
exists to prevent. A tenant with no entry gets None, and the connector says so.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
"""
|
| 250 |
-
return
|
| 251 |
|
| 252 |
|
| 253 |
-
def amazon_creds(rt):
|
| 254 |
"""W52: the FIRST `amazon_sp` entry's fields, else None β the Amazon connector's resolver.
|
| 255 |
|
| 256 |
β THE SAME SHAPE AND THE SAME IMPLEMENTATION AS `odoo_creds` / `meta_creds`, deliberately.
|
|
@@ -266,8 +428,14 @@ def amazon_creds(rt):
|
|
| 266 |
β AND IT RETURNS THE WHOLE FIELD SET, not one secret: an Amazon credential is five values
|
| 267 |
(`client_id`, `client_secret`, `refresh_token`, `seller_id`, `marketplace_id`) and the client
|
| 268 |
needs three of them just to mint an access token.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
"""
|
| 270 |
-
return
|
| 271 |
|
| 272 |
|
| 273 |
#: ββ WAVE 32 (R4 / contract C1) β THE SCOPE SIDE-BUCKET, READ HERE, WRITTEN NOWHERE IN THIS FILE.
|
|
@@ -284,8 +452,9 @@ def amazon_creds(rt):
|
|
| 284 |
SCOPE_KEY = 'keychain_scopes'
|
| 285 |
|
| 286 |
#: The credential types a WHOLE WORKSPACE reads through, which therefore cannot be personal.
|
| 287 |
-
#: β THE ELEVATION THIS PREVENTS, in B's words: `odoo_creds`/`meta_creds` resolve to *
|
| 288 |
-
#:
|
|
|
|
| 289 |
#: what every measure column is answered from. So a member storing a personal Odoo key would not get
|
| 290 |
#: "their own Odoo": they would silently become the credential the entire workspace's databases are
|
| 291 |
#: built from. **A credential elevation wearing a scope picker.**
|
|
@@ -310,9 +479,114 @@ def _personal_ids(rt):
|
|
| 310 |
if isinstance(v, dict) and str(v.get('scope') or '') == 'personal')
|
| 311 |
|
| 312 |
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
β A MISSING RUNTIME ANSWERS None RATHER THAN RAISING, AND THE GUARD IS HERE ON PURPOSE. Every
|
| 318 |
caller's contract is already "the tenant's credential, or None", and `None` means exactly
|
|
@@ -321,7 +595,7 @@ def _first_creds(rt, etype):
|
|
| 321 |
implementation did not keep. Found by `verify_amazon` asserting the contract rather than the
|
| 322 |
behaviour. β FIXED HERE AND NOT IN ONE RESOLVER, because this module's own rule is that
|
| 323 |
"which stored credential serves this connector" has ONE implementation: patching `amazon_creds`
|
| 324 |
-
alone would have created the second normalizer
|
| 325 |
|
| 326 |
ββ WAVE 32 (R4/C1) β A PERSONAL ENTRY OF A TENANT-WIDE TYPE IS SKIPPED, NOT SERVED.
|
| 327 |
`routes_keychain` REFUSES to create one, and that closes the door from the only side B owns;
|
|
@@ -335,14 +609,31 @@ def _first_creds(rt, etype):
|
|
| 335 |
into an outage for a workspace that has a perfectly good business entry two rows down.
|
| 336 |
β AND THE SKIP IS SCOPED TO `TENANT_WIDE_TYPES`. A personal entry of any OTHER type is a normal
|
| 337 |
personal credential and this resolver is not how it is reached.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
"""
|
| 339 |
if rt is None:
|
| 340 |
return None
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
if
|
| 344 |
-
return
|
| 345 |
-
return
|
| 346 |
|
| 347 |
|
| 348 |
# ---------------------------------------------------------------------------------------------
|
|
|
|
| 2 |
|
| 3 |
An admin stores a data source's secrets (Royal's Odoo API key today; any tenant's sources
|
| 4 |
tomorrow) encrypted at rest in the TENANT's store bucket. The runtime posture is R3's
|
| 5 |
+
"live with env fallback": the connector layer asks `odoo_creds(rt, connection_id)` FIRST and falls back to
|
| 6 |
the process environment (tenant #0's `.env` / Space secrets), so Royal keeps working with an
|
| 7 |
empty keychain and a new tenant needs no code to bring keys. The FULL cutover (env retired)
|
| 8 |
is staged for a later wave β R3, verbatim.
|
|
|
|
| 14 |
|
| 15 |
SHAPE (bucket `keychain`, per-tenant via the runtime handle):
|
| 16 |
|
| 17 |
+
{entries: {id: {id, connection_id, slot, label, type, enc, preview, created, createdBy}}}
|
| 18 |
|
| 19 |
`enc` = Fernet token over the JSON fields dict. `preview` = a masked hint ("Β·Β·Β·Β·1234")
|
| 20 |
computed ONCE at write from the entry's most secret-looking field β the ONLY part of a
|
|
|
|
| 92 |
return rt.get(KEY) or {}
|
| 93 |
|
| 94 |
|
| 95 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 96 |
+
# ββ W54-T44 / OWNER RULING R4 / CONTRACT C4 β A CONNECTION HAS AN IDENTITY.
|
| 97 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 98 |
+
#
|
| 99 |
+
# R4, verbatim: *"If a tenant is an agency that helps with clients that each have Odoo, then the
|
| 100 |
+
# connector for Odoo can be many depending on the API. This is why its critical."* So MANY
|
| 101 |
+
# connections of ONE kind coexist, and each one has to be addressable on its own.
|
| 102 |
+
#
|
| 103 |
+
# β THE STORAGE ALREADY ALLOWED THIS AND THE READER DID NOT. `add_entry` has always minted a
|
| 104 |
+
# fresh `k_<hex>` per call with no uniqueness constraint, so a second `odoo` entry was already
|
| 105 |
+
# storable β it was simply never READ (every resolver takes the first of its type). This block
|
| 106 |
+
# adds the two facts a reader needs in order to tell two connections of one kind apart:
|
| 107 |
+
#
|
| 108 |
+
# `connection_id` the entry's own id, stamped EXPLICITLY rather than left implicit. It is
|
| 109 |
+
# stable, unique, never reused and never re-derived by sorting.
|
| 110 |
+
# `slot` an IMMUTABLE per-(tenant, type) ordinal, minted HIGH-WATER, which is what
|
| 111 |
+
# makes the default label `Odoo 1` / `Odoo 2` stable and what a namespaced
|
| 112 |
+
# table can be keyed on. Deleting a connection must never let a later one
|
| 113 |
+
# reuse a retired ordinal, or two different connections would answer to one
|
| 114 |
+
# address at two different times.
|
| 115 |
+
#
|
| 116 |
+
# β THE READ DEFAULTS ARE READ DEFAULTS AND NEVER A MIGRATION, the same posture `SCOPE_KEY`
|
| 117 |
+
# takes below. Rows written before this wave carry neither field: they read back as
|
| 118 |
+
# `connection_id = id` and as their 1-based position among entries of their type in the existing
|
| 119 |
+
# insertion-id sort. Materialising that on the next read would rewrite a tenant's encrypted
|
| 120 |
+
# store to record something already derivable ([[a-migration-that-runs-on-the-next-write]]) β
|
| 121 |
+
# and this store's rows are Fernet tokens, so a rewrite is the one operation that can lose a
|
| 122 |
+
# credential. Nothing here decrypts anything.
|
| 123 |
+
|
| 124 |
+
#: type -> the human word the default label is built from. `generic` has no product name behind
|
| 125 |
+
#: it, so it says what it is rather than inventing one.
|
| 126 |
+
_KIND_LABELS = {'odoo': 'Odoo', 'meta_ads': 'Meta Ads', 'amazon_sp': 'Amazon',
|
| 127 |
+
'stripe': 'Stripe', 'shopify': 'Shopify', 'generic': 'Connection'}
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def kind_label(etype):
|
| 131 |
+
"""The human word for a connection type, for a default label. Never blank."""
|
| 132 |
+
return _KIND_LABELS.get(str(etype or '').strip().lower()) or 'Connection'
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def connection_id_of(entry, entry_id):
|
| 136 |
+
"""A stored row's stable connection id β its own `connection_id`, else its entry id.
|
| 137 |
+
|
| 138 |
+
β A NAMED FUNCTION RATHER THAN AN INLINE `or`, so that the identity has ONE derivation a gate
|
| 139 |
+
can break in memory: the negative control for "two connections stay two" needs somewhere to
|
| 140 |
+
collapse them.
|
| 141 |
+
"""
|
| 142 |
+
return str((entry or {}).get('connection_id') or entry_id)
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def slot_of(entry, ordinal):
|
| 146 |
+
"""A stored row's slot β its own `slot` when it has one, else the read default `ordinal`.
|
| 147 |
+
|
| 148 |
+
β `ordinal` is the caller's 1-based position among entries of the SAME type, in the same
|
| 149 |
+
insertion-id sort every resolver already uses. A stored slot always wins, which is what makes
|
| 150 |
+
the field immutable once written.
|
| 151 |
+
"""
|
| 152 |
+
try:
|
| 153 |
+
n = int((entry or {}).get('slot') or 0)
|
| 154 |
+
except (TypeError, ValueError):
|
| 155 |
+
n = 0
|
| 156 |
+
return n if n >= 1 else int(ordinal)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
def list_entries(rt):
|
| 160 |
+
"""Metadata ONLY β never a decrypted field, never `enc` itself.
|
| 161 |
+
|
| 162 |
+
Every row carries `connection_id` and `slot` (W54-T44 / C4). Rows may GAIN keys here and must
|
| 163 |
+
never LOSE one: `verify_api` asserts the listing has no `enc` / `url` / `api_key` / `fields`,
|
| 164 |
+
and several callers read these rows by key.
|
| 165 |
+
"""
|
| 166 |
out = []
|
| 167 |
+
seen = {}
|
| 168 |
for eid, e in sorted((_bucket(rt).get('entries') or {}).items()):
|
| 169 |
if not isinstance(e, dict):
|
| 170 |
continue
|
| 171 |
+
etype = e.get('type') or 'generic'
|
| 172 |
+
seen[etype] = ordinal = seen.get(etype, 0) + 1
|
| 173 |
+
out.append({'id': eid,
|
| 174 |
+
'connection_id': connection_id_of(e, eid),
|
| 175 |
+
'slot': slot_of(e, ordinal),
|
| 176 |
+
'label': e.get('label') or eid,
|
| 177 |
+
'type': etype,
|
| 178 |
'preview': e.get('preview') or '',
|
| 179 |
'created': e.get('created') or '',
|
| 180 |
'createdBy': e.get('createdBy') or ''})
|
| 181 |
return out
|
| 182 |
|
| 183 |
|
| 184 |
+
def next_slot(rt, etype):
|
| 185 |
+
"""The slot a NEW connection of `etype` takes: one above the highest this tenant has ever
|
| 186 |
+
shown for that type. Never decrypts anything.
|
| 187 |
+
|
| 188 |
+
β HIGH-WATER, NOT A COUNT. `len(entries of this type) + 1` would hand a retired ordinal to a
|
| 189 |
+
new connection the moment one is deleted β two different credentials answering to `Odoo 2`,
|
| 190 |
+
a month apart, with every table W54-T46 namespaces on that ordinal pointing at the wrong one.
|
| 191 |
+
β It reads through `list_entries`, so a row written before this wave counts at its READ
|
| 192 |
+
DEFAULT rather than at zero: a tenant with two un-stamped Odoo entries gets 3, not 1.
|
| 193 |
+
"""
|
| 194 |
+
etype = str(etype or '').strip().lower()
|
| 195 |
+
top = 0
|
| 196 |
+
for row in list_entries(rt):
|
| 197 |
+
if row.get('type') == etype:
|
| 198 |
+
try:
|
| 199 |
+
top = max(top, int(row.get('slot') or 0))
|
| 200 |
+
except (TypeError, ValueError):
|
| 201 |
+
continue
|
| 202 |
+
return top + 1
|
| 203 |
+
|
| 204 |
+
|
| 205 |
def add_entry(rt, label, etype, fields, username):
|
| 206 |
"""Encrypt + store. Returns the metadata row, or raises ValueError on shape problems and
|
| 207 |
+
KeychainLocked when there is no key (a secret must never be stored in the clear).
|
| 208 |
+
|
| 209 |
+
β W54-T44 / C4 β the row is stamped with its `connection_id` and its `slot`, and a caller
|
| 210 |
+
that supplies NO label gets the default the slot names: the tenant's first Odoo connection is
|
| 211 |
+
`Odoo 1`, the second `Odoo 2`. An explicitly supplied label always wins, and the label stays
|
| 212 |
+
the user's to change afterwards (`rename_entry`).
|
| 213 |
+
β THE TYPE IS VALIDATED FIRST NOW, because the default label is built from it: a blank label
|
| 214 |
+
on an unknown type must still be told about the type, which is the fixable half.
|
| 215 |
+
"""
|
| 216 |
label = ' '.join(str(label or '').split())[:80]
|
| 217 |
etype = str(etype or '').strip().lower()
|
|
|
|
|
|
|
| 218 |
if etype not in ENTRY_TYPES:
|
| 219 |
raise ValueError(f"type must be one of {', '.join(sorted(ENTRY_TYPES))}")
|
| 220 |
if not isinstance(fields, dict) or not fields:
|
|
|
|
| 230 |
secretish = next((clean[k] for k in _PREVIEW_FIELDS if clean.get(k)), '')
|
| 231 |
preview = ('Β·Β·Β·Β·' + secretish[-4:]) if len(secretish) >= 4 else ('Β·Β·Β·Β·' if secretish else '')
|
| 232 |
eid = f'k_{_secrets.token_hex(6)}'
|
| 233 |
+
slot = next_slot(rt, etype)
|
| 234 |
+
if not label:
|
| 235 |
+
label = f'{kind_label(etype)} {slot}'
|
| 236 |
+
row = {'id': eid, 'connection_id': eid, 'slot': slot,
|
| 237 |
+
'label': label, 'type': etype, 'enc': token.decode('ascii'),
|
| 238 |
'preview': preview,
|
| 239 |
'created': _dt.datetime.now().strftime('%Y-%m-%dT%H:%M:%S'),
|
| 240 |
'createdBy': str(username or '')}
|
|
|
|
| 247 |
return cur
|
| 248 |
|
| 249 |
rt.update(KEY, _up, flush='sync')
|
| 250 |
+
return {'id': eid, 'connection_id': eid, 'slot': slot,
|
| 251 |
+
'label': label, 'type': etype, 'preview': preview,
|
| 252 |
'created': row['created'], 'createdBy': row['createdBy']}
|
| 253 |
|
| 254 |
|
| 255 |
+
def rename_entry(rt, entry_id, label):
|
| 256 |
+
"""Give ONE connection a new name. Returns its metadata row, or None when there is no such
|
| 257 |
+
entry. Raises ValueError on a blank name.
|
| 258 |
+
|
| 259 |
+
β THE LABEL AND NOTHING ELSE. `enc`, `connection_id`, `slot`, `preview`, `created` and
|
| 260 |
+
`createdBy` are left exactly as they were, and no other row is touched β that is the whole
|
| 261 |
+
contract of a rename under R4, where two connections of one kind sit side by side and
|
| 262 |
+
renaming one must not disturb the other.
|
| 263 |
+
β AND IT DECRYPTS NOTHING. A stored secret is never re-openable and a rename has no business
|
| 264 |
+
asking for the key: this works on a LOCKED keychain, where re-encrypting a row to change a
|
| 265 |
+
display string would refuse (or, worse, rewrite a Fernet token to alter a label).
|
| 266 |
+
"""
|
| 267 |
+
label = ' '.join(str(label or '').split())[:80]
|
| 268 |
+
if not label:
|
| 269 |
+
raise ValueError('give this connection a name')
|
| 270 |
+
eid = str(entry_id)
|
| 271 |
+
found = []
|
| 272 |
+
|
| 273 |
+
def _up(cur):
|
| 274 |
+
row = (cur.get('entries') or {}).get(eid)
|
| 275 |
+
if isinstance(row, dict):
|
| 276 |
+
row['label'] = label
|
| 277 |
+
found.append(True)
|
| 278 |
+
return cur
|
| 279 |
+
|
| 280 |
+
rt.update(KEY, _up, flush='sync')
|
| 281 |
+
if not found:
|
| 282 |
+
return None
|
| 283 |
+
return next((e for e in list_entries(rt) if e['id'] == eid), None)
|
| 284 |
+
|
| 285 |
+
|
| 286 |
def delete_entry(rt, entry_id):
|
| 287 |
def _drop(cur):
|
| 288 |
(cur.get('entries') or {}).pop(str(entry_id), None)
|
|
|
|
| 312 |
|
| 313 |
|
| 314 |
def first_entry_of_type(rt, etype):
|
| 315 |
+
"""DOES THIS TENANT HAVE ANY ENTRY OF `etype` AT ALL? The first such metadata row, or None.
|
| 316 |
+
Never decrypts anything.
|
| 317 |
+
|
| 318 |
+
ββ W54-T45 β THIS IS AN EXISTENCE QUESTION AND NOTHING ELSE, AND THE NAME IS THE ONLY THING
|
| 319 |
+
LEFT THAT SUGGESTS OTHERWISE. It used to be the identity twin of `_first_creds`: "which entry
|
| 320 |
+
serves" and "does one exist" were the same walk, which is exactly the coupling contract C4
|
| 321 |
+
exists to break. Under R4 a tenant may hold MANY Odoo connections, so "the first one" is no
|
| 322 |
+
longer an answer to "which credential serves this connector" β that question is now
|
| 323 |
+
`default_connection_id` / `_creds_for`, which resolve on a `connection_id` and order on the
|
| 324 |
+
immutable `slot`. β Do not route any credential path back through here.
|
| 325 |
+
What survives is the migration/idempotency question `ensure_entry_of_type` asks below, and
|
| 326 |
+
`verify_api` asks in three places as a "nothing was written" probe: both of those genuinely
|
| 327 |
+
mean *is there one*, not *which one*.
|
| 328 |
"""
|
| 329 |
return next((e for e in list_entries(rt) if e.get('type') == str(etype or '')), None)
|
| 330 |
|
|
|
|
| 333 |
"""Create ONE entry of `etype` only if the tenant has none. `(row, why)`; `row` is None on skip.
|
| 334 |
|
| 335 |
β W35-T45 / R11 β the primitive tenant #0's env-to-keychain migration is built from, and the
|
| 336 |
+
reason it lives here is that only this module knows what "already has one" means.
|
| 337 |
+
β W54-T45 SOFTENED WHAT IS AT STAKE WITHOUT CHANGING THIS FUNCTION. A second entry of a type
|
| 338 |
+
is no longer invisible: under R4 it is a second CONNECTION with its own `connection_id`, and
|
| 339 |
+
every resolver can address it. What this still prevents is a MIGRATION running twice and
|
| 340 |
+
quietly minting `Odoo 2` out of the same environment variables `Odoo 1` came from.
|
| 341 |
|
| 342 |
β IDEMPOTENT BY TYPE, NOT BY A FLAG. A migration that keys idempotency on a marker it writes
|
| 343 |
itself is one lost marker away from running twice ([[a-migration-that-runs-on-the-next-write]]);
|
|
|
|
| 366 |
return None, f'{type(exc).__name__}: {exc}'
|
| 367 |
|
| 368 |
|
| 369 |
+
def odoo_creds(rt, connection_id=None):
|
| 370 |
+
"""R3's resolver seam: the fields of the odoo connection NAMED by `connection_id`, else None.
|
| 371 |
+
|
| 372 |
+
ββ W54-T45 / R4 / C4 β IT TAKES A CONNECTION NOW, AND THAT IS THE WHOLE TICKET. An agency
|
| 373 |
+
tenant holds one Odoo connection per client, so "the tenant's Odoo credential" is not a
|
| 374 |
+
question with one answer any more. `connection_id` names WHICH one; a `connection_id` that
|
| 375 |
+
names no entry of this type resolves to None and never to a sibling.
|
| 376 |
+
β NO ID MEANS THE DESIGNATED DEFAULT (`default_connection_id`), which is the lowest-`slot`
|
| 377 |
+
connection of the type. Every existing one-argument call site therefore keeps working and now
|
| 378 |
+
means exactly that, rather than "whichever row happened to sort first".
|
| 379 |
+
β None here still means "not configured", and the CALLER decides what that entails:
|
| 380 |
+
`harness/runtime.py::odoo_source` falls back to tenant #0's compiled environment only when no
|
| 381 |
+
connection was NAMED.
|
| 382 |
+
"""
|
| 383 |
+
return _creds_for(rt, 'odoo', connection_id)
|
| 384 |
|
| 385 |
|
| 386 |
+
def meta_creds(rt, connection_id=None):
|
| 387 |
"""W31 (R2): the FIRST `meta_ads` entry's fields, else None β the Meta connector's resolver.
|
| 388 |
|
| 389 |
ββ W49-T13 / D-202 β IT HAS A PRODUCTION CALLER NOW, AND THAT WAS THE WHOLE DEFECT.
|
|
|
|
| 404 |
is no equivalent for Meta: `META_ADS_ACCESS_TOKEN` is the OWNER's measurement token (R8), and
|
| 405 |
handing it to a tenant whose admin has not stored one is precisely the leak the R3 rule
|
| 406 |
exists to prevent. A tenant with no entry gets None, and the connector says so.
|
| 407 |
+
|
| 408 |
+
β W54-T45 / R4 β `connection_id` NAMES WHICH Meta connection, and no id means the tenant's
|
| 409 |
+
DESIGNATED DEFAULT (the lowest-`slot` `meta_ads` connection), not "whichever row sorts first".
|
| 410 |
+
An id that names no `meta_ads` entry resolves to None, never to a sibling.
|
| 411 |
"""
|
| 412 |
+
return _creds_for(rt, 'meta_ads', connection_id)
|
| 413 |
|
| 414 |
|
| 415 |
+
def amazon_creds(rt, connection_id=None):
|
| 416 |
"""W52: the FIRST `amazon_sp` entry's fields, else None β the Amazon connector's resolver.
|
| 417 |
|
| 418 |
β THE SAME SHAPE AND THE SAME IMPLEMENTATION AS `odoo_creds` / `meta_creds`, deliberately.
|
|
|
|
| 428 |
β AND IT RETURNS THE WHOLE FIELD SET, not one secret: an Amazon credential is five values
|
| 429 |
(`client_id`, `client_secret`, `refresh_token`, `seller_id`, `marketplace_id`) and the client
|
| 430 |
needs three of them just to mint an access token.
|
| 431 |
+
|
| 432 |
+
β W54-T45 / R4 β `connection_id` NAMES WHICH Amazon connection, and no id means the tenant's
|
| 433 |
+
DESIGNATED DEFAULT (the lowest-`slot` `amazon_sp` connection), not "whichever row sorts
|
| 434 |
+
first". An id that names no `amazon_sp` entry resolves to None, never to a sibling.
|
| 435 |
+
β `amazon_creds(None)` β a MISSING RUNTIME, not a missing id β still answers None rather than
|
| 436 |
+
raising; `verify_amazon` asserts exactly that, and the guard lives in `_creds_for`.
|
| 437 |
"""
|
| 438 |
+
return _creds_for(rt, 'amazon_sp', connection_id)
|
| 439 |
|
| 440 |
|
| 441 |
#: ββ WAVE 32 (R4 / contract C1) β THE SCOPE SIDE-BUCKET, READ HERE, WRITTEN NOWHERE IN THIS FILE.
|
|
|
|
| 452 |
SCOPE_KEY = 'keychain_scopes'
|
| 453 |
|
| 454 |
#: The credential types a WHOLE WORKSPACE reads through, which therefore cannot be personal.
|
| 455 |
+
#: β THE ELEVATION THIS PREVENTS, in B's words: `odoo_creds`/`meta_creds` resolve to *a connection
|
| 456 |
+
#: of that type for the TENANT* (W54-T45: the one a caller NAMES, or the tenant's designated
|
| 457 |
+
#: default when none is named) β that is what spawns every `ut_odoo_*` / `ut_meta_*` grid and
|
| 458 |
#: what every measure column is answered from. So a member storing a personal Odoo key would not get
|
| 459 |
#: "their own Odoo": they would silently become the credential the entire workspace's databases are
|
| 460 |
#: built from. **A credential elevation wearing a scope picker.**
|
|
|
|
| 479 |
if isinstance(v, dict) and str(v.get('scope') or '') == 'personal')
|
| 480 |
|
| 481 |
|
| 482 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 483 |
+
# ββ W54-T45 / R4 / CONTRACT C4 β EVERY READER NAMES WHICH CONNECTION IT WANTS.
|
| 484 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 485 |
+
#
|
| 486 |
+
# What stood here was `_first_creds(rt, etype)`, and one line of it β "return the first entry of
|
| 487 |
+
# this type" β was the whole ceiling on R4. Storage already held many connections of one kind
|
| 488 |
+
# (W54-T44 gave each of them an id and a slot); every READER collapsed them back to one. An
|
| 489 |
+
# agency with two clients on Odoo could store both credentials, see both rows, rename both, and
|
| 490 |
+
# be served the first one for every question either client asked. That is not a missing feature,
|
| 491 |
+
# it is R7's isolation rule failing silently: one client's numbers answering another's screen.
|
| 492 |
+
#
|
| 493 |
+
# β THE HELPER IS NOT NAMED "FIRST" ANY MORE, ON PURPOSE. A shared body called `_first_creds` is
|
| 494 |
+
# how the defect would grow back one connector at a time: the next resolver copies the name and
|
| 495 |
+
# inherits the rule. `_creds_for` asks the question the contract asks β *which stored credential
|
| 496 |
+
# serves this connector, for this connection?*
|
| 497 |
+
#
|
| 498 |
+
# β RESOLVE ON IDS, ORDER ON SLOTS, and the distinction is MEASURED, not stylistic: a pre-wave
|
| 499 |
+
# row's read-default `slot` MOVES when a sibling of its type is deleted (2 -> 1) while its
|
| 500 |
+
# `connection_id` does not. So `connection_id` is the ADDRESS a caller passes and holds, and
|
| 501 |
+
# `slot` is only how the tenant's DESIGNATED DEFAULT is picked and how connections are ordered
|
| 502 |
+
# on a screen. A caller that stored a slot as an address would eventually address another
|
| 503 |
+
# client's credential.
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def default_connection_id(rt, etype):
|
| 507 |
+
"""THE TENANT'S DESIGNATED DEFAULT connection of `etype` β its `connection_id`, or None.
|
| 508 |
+
Never decrypts anything.
|
| 509 |
+
|
| 510 |
+
ββ A DESIGNATED DEFAULT PINNED BY AN IMMUTABLE ORDINAL, NOT "WHICHEVER ROW HAPPENS TO SORT
|
| 511 |
+
FIRST", AND THAT DISTINCTION IS THE POINT OF THIS WHOLE TICKET. The rule is the LOWEST `slot`
|
| 512 |
+
β the per-(tenant, type) ordinal `add_entry` mints high-water and never rewrites β with ties
|
| 513 |
+
broken by the existing insertion-id order so the answer is total and stable. "First of its
|
| 514 |
+
type" was an accident of dict ordering that a delete, a re-key or a store rewrite could move
|
| 515 |
+
under a caller's feet; the lowest slot is a decision the tenant made when it added its first
|
| 516 |
+
connection.
|
| 517 |
+
β Personal entries of a tenant-wide type are skipped exactly as `_creds_for` skips them, so
|
| 518 |
+
the default and the credential can never disagree about which connection serves.
|
| 519 |
+
β AND IT IS A DEFAULT, NEVER A FALLBACK. It answers "no id was named"; it is not consulted
|
| 520 |
+
when an id WAS named and failed to resolve, because serving a sibling to a caller that asked
|
| 521 |
+
for a specific client is the leak R7 forbids.
|
| 522 |
+
"""
|
| 523 |
+
if rt is None:
|
| 524 |
+
return None
|
| 525 |
+
etype = str(etype or '').strip().lower()
|
| 526 |
+
skip = _personal_ids(rt) if etype in TENANT_WIDE_TYPES else frozenset()
|
| 527 |
+
best = None
|
| 528 |
+
for pos, row in enumerate(list_entries(rt)):
|
| 529 |
+
if row['type'] != etype or str(row['id']) in skip:
|
| 530 |
+
continue
|
| 531 |
+
rank = (int(row['slot']), pos)
|
| 532 |
+
if best is None or rank < best[0]:
|
| 533 |
+
best = (rank, str(row['connection_id']))
|
| 534 |
+
return best[1] if best is not None else None
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
def _row_for(rt, connection_id, etype=None):
|
| 538 |
+
"""The metadata row `connection_id` addresses, or None. Never decrypts anything.
|
| 539 |
+
|
| 540 |
+
Matches on the row's `connection_id` and, for rows written before W54-T44, on its entry id β
|
| 541 |
+
which `connection_id_of` makes the same value anyway. When `etype` is asserted, a row of a
|
| 542 |
+
DIFFERENT type is None rather than a match: an id is only an address within the connector
|
| 543 |
+
that was asked for.
|
| 544 |
+
β A personal entry of a tenant-wide type is None here too, even when named EXPLICITLY. The
|
| 545 |
+
wave-32 skip is a credential-elevation guard, not a tie-breaker, and letting an explicit id
|
| 546 |
+
walk past it would reopen the door from the one side that stayed shut.
|
| 547 |
+
"""
|
| 548 |
+
if rt is None:
|
| 549 |
+
return None
|
| 550 |
+
want = str(connection_id or '')
|
| 551 |
+
if not want:
|
| 552 |
+
return None
|
| 553 |
+
etype = str(etype or '').strip().lower()
|
| 554 |
+
for row in list_entries(rt):
|
| 555 |
+
if str(row['connection_id']) != want and str(row['id']) != want:
|
| 556 |
+
continue
|
| 557 |
+
rtype = str(row['type'] or '')
|
| 558 |
+
if etype and rtype != etype:
|
| 559 |
+
return None
|
| 560 |
+
if rtype in TENANT_WIDE_TYPES and str(row['id']) in _personal_ids(rt):
|
| 561 |
+
return None
|
| 562 |
+
return row
|
| 563 |
+
return None
|
| 564 |
+
|
| 565 |
+
|
| 566 |
+
def resolve_connection_id(rt, etype, connection_id=None):
|
| 567 |
+
"""WHICH connection of `etype` would serve β an IDENTITY, decrypting nothing. None when
|
| 568 |
+
nothing would.
|
| 569 |
+
|
| 570 |
+
β IT EXISTS SO THERE IS GENUINELY ONE RESOLVER. `harness/runtime.py::odoo_flag_key` needs the
|
| 571 |
+
identity of the serving connection without opening it (a pause flag must still resolve on a
|
| 572 |
+
LOCKED keychain), and its docstring has always claimed to be that one resolver while carrying
|
| 573 |
+
an inline first-entry walk of its own. This is the walk it now calls instead.
|
| 574 |
+
β The answer is a `connection_id`, which for every stored row equals that row's entry id
|
| 575 |
+
(`add_entry` stamps them the same and `connection_id_of` defaults the older rows to it), so
|
| 576 |
+
the pause flags written against the old resolution keep resolving.
|
| 577 |
+
"""
|
| 578 |
+
if connection_id is None:
|
| 579 |
+
return default_connection_id(rt, etype)
|
| 580 |
+
row = _row_for(rt, connection_id, etype)
|
| 581 |
+
return str(row['connection_id']) if row else None
|
| 582 |
+
|
| 583 |
+
|
| 584 |
+
def connection_creds(rt, connection_id, etype=None):
|
| 585 |
+
"""THE fields of the ONE connection `connection_id` addresses, decrypted β or None.
|
| 586 |
+
|
| 587 |
+
ββ W54-T45 / C4 β the reader the contract asks for: *"`keychain.odoo_creds` and every other
|
| 588 |
+
first-entry reader must take a `connection_id`."* Two connections of one kind therefore return
|
| 589 |
+
two different credential sets for two different ids, which is the agency case R4 names.
|
| 590 |
|
| 591 |
β A MISSING RUNTIME ANSWERS None RATHER THAN RAISING, AND THE GUARD IS HERE ON PURPOSE. Every
|
| 592 |
caller's contract is already "the tenant's credential, or None", and `None` means exactly
|
|
|
|
| 595 |
implementation did not keep. Found by `verify_amazon` asserting the contract rather than the
|
| 596 |
behaviour. β FIXED HERE AND NOT IN ONE RESOLVER, because this module's own rule is that
|
| 597 |
"which stored credential serves this connector" has ONE implementation: patching `amazon_creds`
|
| 598 |
+
alone would have created the second normalizer this file warns about.
|
| 599 |
|
| 600 |
ββ WAVE 32 (R4/C1) β A PERSONAL ENTRY OF A TENANT-WIDE TYPE IS SKIPPED, NOT SERVED.
|
| 601 |
`routes_keychain` REFUSES to create one, and that closes the door from the only side B owns;
|
|
|
|
| 609 |
into an outage for a workspace that has a perfectly good business entry two rows down.
|
| 610 |
β AND THE SKIP IS SCOPED TO `TENANT_WIDE_TYPES`. A personal entry of any OTHER type is a normal
|
| 611 |
personal credential and this resolver is not how it is reached.
|
| 612 |
+
β A LOCKED KEYCHAIN STILL RAISES `KeychainLocked`, from `read_fields`. "No key on this
|
| 613 |
+
deployment" is an operator fact and silently empty creds would read as "not configured".
|
| 614 |
+
"""
|
| 615 |
+
row = _row_for(rt, connection_id, etype)
|
| 616 |
+
return read_fields(rt, row['id']) if row else None
|
| 617 |
+
|
| 618 |
+
|
| 619 |
+
def _creds_for(rt, etype, connection_id=None):
|
| 620 |
+
"""THE ONE INTERNAL HELPER behind `odoo_creds` / `meta_creds` / `amazon_creds`: the fields of
|
| 621 |
+
the `etype` connection named by `connection_id`, or of the tenant's designated default when
|
| 622 |
+
no id is named. None when nothing serves.
|
| 623 |
+
|
| 624 |
+
β IT REPLACES `_first_creds`, NAME INCLUDED. "Which stored credential serves this connector"
|
| 625 |
+
has ONE implementation in this module, and the old one answered a question C4 forbids.
|
| 626 |
+
β A NAMED CONNECTION THAT DOES NOT RESOLVE IS None, FULL STOP β never the default, never a
|
| 627 |
+
sibling, and (at the caller) never the environment. Falling back after an explicit ask is how
|
| 628 |
+
one client's Odoo comes to answer another client's question under R7's strict isolation.
|
| 629 |
"""
|
| 630 |
if rt is None:
|
| 631 |
return None
|
| 632 |
+
if connection_id is None:
|
| 633 |
+
connection_id = default_connection_id(rt, etype)
|
| 634 |
+
if connection_id is None:
|
| 635 |
+
return None
|
| 636 |
+
return connection_creds(rt, connection_id, etype)
|
| 637 |
|
| 638 |
|
| 639 |
# ---------------------------------------------------------------------------------------------
|
platform/core/perm_scope.py
CHANGED
|
@@ -1980,3 +1980,321 @@ def pivot_scope(user, source, target, st=None, path=None):
|
|
| 1980 |
return PivotScope(user, src, tgt, walk,
|
| 1981 |
source_scope=derive_pool_scope(user, src),
|
| 1982 |
target_scope=derive_pool_scope(user, tgt))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1980 |
return PivotScope(user, src, tgt, walk,
|
| 1981 |
source_scope=derive_pool_scope(user, src),
|
| 1982 |
target_scope=derive_pool_scope(user, tgt))
|
| 1983 |
+
|
| 1984 |
+
|
| 1985 |
+
# ββ C4 / R4: THE CONNECTOR AXIS β WHO MAY CREATE A CONNECTION (wave 54, W54-T47) ββββββββββββββ
|
| 1986 |
+
#: The per-tenant bucket one administrator's decision lives in: `{username: [<entry type>, β¦]}`.
|
| 1987 |
+
#:
|
| 1988 |
+
#: ββ AN ABSENT ROW AND "NO GRANT" ARE THE SAME THING, AND THAT IS WHY THIS IS A READ DEFAULT
|
| 1989 |
+
#: RATHER THAN A MIGRATION. `routes_keychain.SCOPE_KEY` carries the identical posture one layer up
|
| 1990 |
+
#: (*"a business entry writes no row β it IS the default"*), and the reason is
|
| 1991 |
+
#: [[a-migration-that-runs-on-the-next-write]]: materialising an empty grant for every account in
|
| 1992 |
+
#: every tenant would rewrite the store on the next read, for a fact nobody decided.
|
| 1993 |
+
CONNECTOR_GRANT_KEY = 'connector_grants'
|
| 1994 |
+
|
| 1995 |
+
|
| 1996 |
+
def connector_grants(username, st=None):
|
| 1997 |
+
"""The connector kinds `username` has been granted, lower-cased, as a frozenset.
|
| 1998 |
+
|
| 1999 |
+
β THE ANSWER TO AN UNREADABLE STORE IS THE EMPTY SET, AND HERE THAT IS THE SAFE DIRECTION
|
| 2000 |
+
RATHER THAN THE UNSAFE ONE β the opposite of `user_generated_fields`, which must answer `None`.
|
| 2001 |
+
That function's answer is PRUNED AGAINST, so a degraded read would delete a live rule; this one
|
| 2002 |
+
only ever WIDENS what a member may do (see `may_add_connection`), so a degraded read leaves the
|
| 2003 |
+
member with exactly the rights they had before this ticket existed. Under-granting is visible
|
| 2004 |
+
and reportable; over-granting is a credential elevation.
|
| 2005 |
+
"""
|
| 2006 |
+
if st is None:
|
| 2007 |
+
return frozenset()
|
| 2008 |
+
uname = str(username or '').strip().lower()
|
| 2009 |
+
if not uname:
|
| 2010 |
+
return frozenset()
|
| 2011 |
+
try:
|
| 2012 |
+
rows = st.get(CONNECTOR_GRANT_KEY) or {}
|
| 2013 |
+
except Exception: # noqa: BLE001
|
| 2014 |
+
return frozenset()
|
| 2015 |
+
if not isinstance(rows, dict):
|
| 2016 |
+
return frozenset()
|
| 2017 |
+
got = rows.get(uname)
|
| 2018 |
+
if not isinstance(got, (list, tuple, set, frozenset)):
|
| 2019 |
+
return frozenset()
|
| 2020 |
+
return frozenset(str(k).strip().lower() for k in got if str(k or '').strip())
|
| 2021 |
+
|
| 2022 |
+
|
| 2023 |
+
def may_add_connection(user, etype, st=None):
|
| 2024 |
+
"""May this account create a WORKSPACE-WIDE connection of kind `etype`? (W54-T47 / R4 / C4.)
|
| 2025 |
+
|
| 2026 |
+
ββ THE THIRD GRANT AXIS. Owner, verbatim: *"Under Settings, an Admin should grant a user
|
| 2027 |
+
access to add connectors, so access becomes Database / Module / Connector. This allows many
|
| 2028 |
+
connectors per tenant β¦ depending on the admin's configuration per user."* Database and Module
|
| 2029 |
+
are the two groups `PermsEditor.tsx` already renders off `perms`; this is the third, and it is
|
| 2030 |
+
a per-KIND answer rather than a single boolean because R4's agency tenant is the whole case:
|
| 2031 |
+
one member may be the person who wires up Shopify and not the person who wires up Odoo.
|
| 2032 |
+
|
| 2033 |
+
ββ ABSENCE WIDENS NOTHING AND REVOKES NOTHING, AND THAT IS THE MOST IMPORTANT PROPERTY OF
|
| 2034 |
+
THIS FUNCTION. No grant was STORABLE before this ticket, so every account in every tenant
|
| 2035 |
+
carries none β reading that absence as DENY at the connection door would revoke personal
|
| 2036 |
+
connections for everybody on the day this shipped, with nobody having decided anything. That
|
| 2037 |
+
is `may_metrics`' argument one file over, in the same words, and the resolution is the same:
|
| 2038 |
+
this predicate is consulted ONLY on the path that was already refused
|
| 2039 |
+
(`routes_keychain.add_key`'s `scope == "business" and not session.admin` leg), so a member with
|
| 2040 |
+
no grant meets byte-identical behaviour β 403 `not_admin` on a business-wide create, 400
|
| 2041 |
+
`scope_not_available` on a tenant-wide personal one, and their own personal connection of an
|
| 2042 |
+
ordinary type still succeeds. An explicit grant is the ONLY thing this adds, and all it can do
|
| 2043 |
+
is admit.
|
| 2044 |
+
|
| 2045 |
+
β AN ADMIN IS ALWAYS TRUE, before the store is touched β break-glass, as every predicate in
|
| 2046 |
+
this file opens, and it is what keeps a tenant whose grant bucket cannot be read from losing
|
| 2047 |
+
its own administrator's ability to connect anything.
|
| 2048 |
+
|
| 2049 |
+
β `st` IS THE TENANT HANDLE AND OMITTING IT DENIES A NON-ADMIN. The grant is per TENANT, so a
|
| 2050 |
+
caller that cannot lend a handle is asking about no workspace in particular; answering from the
|
| 2051 |
+
process-default store is the D-612 shape (`nav_may_open`'s leg 3), and there the wrong answer
|
| 2052 |
+
was reachable in BOTH directions. Here the handle-less answer is the pre-ticket one, so a door
|
| 2053 |
+
that has not learned to thread `st` refuses rather than admitting somebody else's grant.
|
| 2054 |
+
|
| 2055 |
+
β IT IS NOT A SECOND SPELLING OF ELIGIBILITY. `routes_keychain.allowed_scopes` answers what the
|
| 2056 |
+
SOURCE permits (Odoo is workspace-wide by construction); this answers who may act on it. Both
|
| 2057 |
+
must hold, and a tenant-wide type refused to a personal scope stays refused for everybody,
|
| 2058 |
+
grant or no grant.
|
| 2059 |
+
"""
|
| 2060 |
+
if perms.is_admin(user):
|
| 2061 |
+
return True
|
| 2062 |
+
kind = str(etype or '').strip().lower()
|
| 2063 |
+
if not kind:
|
| 2064 |
+
return False
|
| 2065 |
+
return kind in connector_grants((user or {}).get('username'), st=st)
|
| 2066 |
+
|
| 2067 |
+
|
| 2068 |
+
# ββ C4 / R7: THE CONNECTION AXIS β ONE READ, ONE CONNECTION (wave 54, W54-T49) βββββββββββββββββ
|
| 2069 |
+
#: ββ RULING R7, verbatim: *"Multi-connection isolation is STRICT, on the Business Unit pattern.
|
| 2070 |
+
#: Every Odoo-reading module gains a connection selector; picking one client shows only that
|
| 2071 |
+
#: client's numbers. β There is no 'All' option that blends two clients."*
|
| 2072 |
+
#:
|
| 2073 |
+
#: ββ AND THE FAILURE THIS SECTION EXISTS TO PREVENT IS ON THE **VALUES** AXIS, WHICH IS WHY IT
|
| 2074 |
+
#: LOOKS FINE. Wave 51's tenancy defect ran for a whole wave with a correct-looking row LIST while
|
| 2075 |
+
#: `rev`, `ly`, `ltm`, `aov` and `est_missed` were silently two clients' numbers added together β
|
| 2076 |
+
#: `_PUSHDOWN_OPS`' own note above is that incident's record. A connection scope is therefore not
|
| 2077 |
+
#: a post-filter over rows: it decides WHICH TABLE is read at all, before a row exists to filter.
|
| 2078 |
+
#:
|
| 2079 |
+
#: β THE PRECEDENT IS `derive_pool_scope`, NOT A PICKER. `pages.py::bu_control` builds a BU
|
| 2080 |
+
#: control from `perms.allowed_bu_labels`, but `pages.py::_BUILDERS` is `{}` on purpose and
|
| 2081 |
+
#: `verify_api` asserts that emptiness, so that assembly is unreachable in production. The live BU
|
| 2082 |
+
#: pattern is the per-request DERIVATION twenty lines up, and this is its shape one axis over.
|
| 2083 |
+
#:
|
| 2084 |
+
#: β IT TAKES NO PRINCIPAL, DELIBERATELY, AND THAT IS NOT AN OVERSIGHT TO TIDY. WHICH connection
|
| 2085 |
+
#: serves is a property of the workspace and of the request, never of the reader: there is no
|
| 2086 |
+
#: per-user connection grant in this product (`may_add_connection` governs who may CREATE one, a
|
| 2087 |
+
#: different question), so a `user` parameter here would read as a wall this function does not
|
| 2088 |
+
#: have. The reader's wall is `may_read` on the table key the scope resolves to, and it composes
|
| 2089 |
+
#: AFTER this one, unchanged.
|
| 2090 |
+
|
| 2091 |
+
#: What a LEGACY (bare) table key's owner is called when the workspace has no stored connection at
|
| 2092 |
+
#: all to name β every tenant before this wave, tenant #0 included.
|
| 2093 |
+
#:
|
| 2094 |
+
#: β RESTATED FROM `odoo_relational.DEFAULT_CONNECTION` RATHER THAN IMPORTED, because `core` never
|
| 2095 |
+
#: imports up (`platform/ARCHITECTURE.md`). It is the same restatement `_FORMULA_REF` at the top of
|
| 2096 |
+
#: this file makes, with the same guard: `verify_scopes` asserts the two spell the same word, so a
|
| 2097 |
+
#: rename in the API layer cannot leave this copy behind [[constant-two-features-share]].
|
| 2098 |
+
DEFAULT_CONNECTION = 'default'
|
| 2099 |
+
|
| 2100 |
+
#: The connector kind a scope answers for when a caller names none. `odoo` is the only kind that
|
| 2101 |
+
#: spawns per-connection tables today (W54-T46); the parameter exists so the second one needs no
|
| 2102 |
+
#: second function.
|
| 2103 |
+
DEFAULT_CONNECTION_TYPE = 'odoo'
|
| 2104 |
+
|
| 2105 |
+
|
| 2106 |
+
class UnknownConnection(LookupError):
|
| 2107 |
+
"""A NAMED connection does not resolve in this workspace.
|
| 2108 |
+
|
| 2109 |
+
ββ RAISED, NEVER FALLEN BACK FROM, and that asymmetry IS R7. `keychain.default_connection_id`
|
| 2110 |
+
answers *"no id was named"*; it is not consulted when an id WAS named and failed to resolve,
|
| 2111 |
+
because serving a sibling to a caller that asked for a specific client is exactly the leak this
|
| 2112 |
+
contract forbids. `odoo_relational.connection_namespace` and `runtime.odoo_source` already hold
|
| 2113 |
+
that posture, and this is the third place it has to hold or the first two are decoration.
|
| 2114 |
+
"""
|
| 2115 |
+
|
| 2116 |
+
|
| 2117 |
+
class ConnectionScope:
|
| 2118 |
+
"""ββ CONTRACT C4 / R7 β the ONE connection a read is scoped to. Blending is UNREPRESENTABLE.
|
| 2119 |
+
|
| 2120 |
+
Built by `connection_scope()` and by nothing else worth building: it holds a SINGLE
|
| 2121 |
+
`connection_id` string, there is no member that can hold two, and the constructor refuses
|
| 2122 |
+
anything that is not one non-empty id. So "read both clients" is not a value this type can
|
| 2123 |
+
carry β it is not a flag that happens to be off, which is the difference between a rule and a
|
| 2124 |
+
default. A list, an empty string and the word "all" all arrive here as a refusal.
|
| 2125 |
+
|
| 2126 |
+
β IT HOLDS THE TYPE TOO, so an odoo scope can never be handed to a meta_ads reader as though
|
| 2127 |
+
an id were an address across connectors. `keychain._row_for` makes the same statement one layer
|
| 2128 |
+
down (*"an id is only an address within the connector that was asked for"*).
|
| 2129 |
+
"""
|
| 2130 |
+
__slots__ = ('connection_id', 'etype')
|
| 2131 |
+
|
| 2132 |
+
def __init__(self, connection_id, etype=DEFAULT_CONNECTION_TYPE):
|
| 2133 |
+
cid = connection_id.strip() if isinstance(connection_id, str) else ''
|
| 2134 |
+
if not cid:
|
| 2135 |
+
raise UnknownConnection(
|
| 2136 |
+
'a connection scope is exactly one connection. Name a single connection, or '
|
| 2137 |
+
'name none and the workspace default serves.')
|
| 2138 |
+
self.connection_id = cid
|
| 2139 |
+
self.etype = str(etype or DEFAULT_CONNECTION_TYPE).strip().lower()
|
| 2140 |
+
|
| 2141 |
+
def __repr__(self):
|
| 2142 |
+
return f'ConnectionScope({self.connection_id!r}, {self.etype!r})'
|
| 2143 |
+
|
| 2144 |
+
def owner_of(self, table_key, rt=None):
|
| 2145 |
+
"""WHICH connection owns `table_key`, through the registered owner. `None` for a key no
|
| 2146 |
+
connector claims.
|
| 2147 |
+
|
| 2148 |
+
β NO REGISTRAR IS `Unresolvable`, NOT `False`. The question "whose table is this" is
|
| 2149 |
+
answered in the API layer (`odoo_relational.connection_for_table_key`) and `core` never
|
| 2150 |
+
imports up, so a process that never registered one cannot answer it β and a wall that
|
| 2151 |
+
cannot be evaluated must say so with its cause and a recommendation rather than quietly
|
| 2152 |
+
admitting or quietly refusing. That is standing rule 1's second sentence, and it is the
|
| 2153 |
+
same shape `_read_user_table` uses when no mirror reader is registered.
|
| 2154 |
+
"""
|
| 2155 |
+
key = str(table_key or '').strip()
|
| 2156 |
+
if _CONNECTION_OWNER is None:
|
| 2157 |
+
raise Unresolvable(
|
| 2158 |
+
subject='connection', effect='unresolvable',
|
| 2159 |
+
cause=(f"'{key}' cannot be attributed to a connection in this process because no "
|
| 2160 |
+
f'connection owner is registered'),
|
| 2161 |
+
recommendation=('call `perm_scope.register_connection_owner(...)` from the app '
|
| 2162 |
+
'layer before scoping a read, or read through the API'))
|
| 2163 |
+
owner = _CONNECTION_OWNER(key, rt)
|
| 2164 |
+
return str(owner) if owner else None
|
| 2165 |
+
|
| 2166 |
+
def covers(self, table_key, rt=None):
|
| 2167 |
+
"""Does `table_key` belong to THIS connection?
|
| 2168 |
+
|
| 2169 |
+
β FAIL CLOSED. An unanswerable question is a NO here, never a pass: a key no connector
|
| 2170 |
+
claims, an owner that cannot be resolved and a missing registrar all answer False, because
|
| 2171 |
+
the only thing "I do not know whose this is" can safely mean under R7 is "not yours".
|
| 2172 |
+
"""
|
| 2173 |
+
try:
|
| 2174 |
+
return self.owner_of(table_key, rt) == self.connection_id
|
| 2175 |
+
except Exception: # noqa: BLE001
|
| 2176 |
+
return False
|
| 2177 |
+
|
| 2178 |
+
def require(self, table_key, rt=None):
|
| 2179 |
+
"""`table_key` itself, or `Denied` when it belongs to another connection.
|
| 2180 |
+
|
| 2181 |
+
β THE WALL, AND IT IS ONE SENTENCE ON REFUSAL (DESIGN section 4). `covers` is the
|
| 2182 |
+
predicate a caller may branch on; this is the door a reader passes through, so that a
|
| 2183 |
+
route which forgets to branch fails CLOSED rather than reading the other client's table.
|
| 2184 |
+
"""
|
| 2185 |
+
key = str(table_key or '').strip()
|
| 2186 |
+
owner = self.owner_of(key, rt)
|
| 2187 |
+
if owner != self.connection_id:
|
| 2188 |
+
raise Denied(f"'{key}' belongs to another connection. Switch the connection selector "
|
| 2189 |
+
f'to the one that owns it.')
|
| 2190 |
+
return key
|
| 2191 |
+
|
| 2192 |
+
|
| 2193 |
+
#: WHO answers "which connection owns this table key", declared by the app layer.
|
| 2194 |
+
#: `reader(table_key, rt) -> connection_id | None`.
|
| 2195 |
+
#:
|
| 2196 |
+
#: β A REGISTRATION SLOT AND NOT AN IMPORT, for the reason `_ROW_SOURCES` and `_MIRROR_READER`
|
| 2197 |
+
#: above are, and `keychain.register_prober` one file over: the inverse lives in
|
| 2198 |
+
#: `aios-web/api/odoo_relational.py` (`connection_for_table_key`), `core` never imports up, and
|
| 2199 |
+
#: `verify_meta` asserts that fence. The app tells this layer rather than being interrogated by it.
|
| 2200 |
+
_CONNECTION_OWNER = None
|
| 2201 |
+
|
| 2202 |
+
|
| 2203 |
+
def register_connection_owner(reader):
|
| 2204 |
+
"""Declare THE reader for "whose table is this" β one reader, because a table has one owner.
|
| 2205 |
+
|
| 2206 |
+
Returns the registrar's own answer, exactly as `register_mirror` does, so the read door and
|
| 2207 |
+
the write door of this fact have one construction site rather than two.
|
| 2208 |
+
"""
|
| 2209 |
+
global _CONNECTION_OWNER
|
| 2210 |
+
_CONNECTION_OWNER = reader
|
| 2211 |
+
return _CONNECTION_OWNER is not None
|
| 2212 |
+
|
| 2213 |
+
|
| 2214 |
+
def connection_scope(rt, etype=DEFAULT_CONNECTION_TYPE, connection_id=None):
|
| 2215 |
+
"""The ONE connection this read is scoped to, as a `ConnectionScope`. R7's derivation.
|
| 2216 |
+
|
| 2217 |
+
ββ ABSENCE CHANGES NOTHING, AND THAT IS THE PROPERTY THAT LETS THIS SHIP. `connection_id=None`
|
| 2218 |
+
means *"no connection was named"* and resolves to the workspace's DESIGNATED DEFAULT β the same
|
| 2219 |
+
connection `keychain._creds_for`, `odoo_relational.connection_namespace` and every pre-ticket
|
| 2220 |
+
reader already served, resolved by the same `keychain.default_connection_id`. A tenant with one
|
| 2221 |
+
connection therefore cannot tell this function exists, which is what every ticket in this lane
|
| 2222 |
+
has preserved for the same reason (W54-T44's read defaults, T46's legacy keys, T47's grant).
|
| 2223 |
+
|
| 2224 |
+
β A NAMED CONNECTION THAT DOES NOT RESOLVE IS `UnknownConnection`, NEVER THE DEFAULT. See that
|
| 2225 |
+
class; the fallback is the leak.
|
| 2226 |
+
|
| 2227 |
+
ββ AND THERE IS NO "ALL". `None` is the only absence this function has, and it pins exactly
|
| 2228 |
+
one connection rather than widening to every connection. An empty string, the word "all", a
|
| 2229 |
+
LIST of ids and any non-string are refused BY CONSTRUCTION rather than by enumeration: only a
|
| 2230 |
+
single non-empty string can address a connection, so the vocabulary cannot express a blend for
|
| 2231 |
+
a future caller to discover. That is the wave-51 lesson in the shape of a type β there the
|
| 2232 |
+
filter vocabulary widened underneath a reader that could not read it, and the numbers merged.
|
| 2233 |
+
|
| 2234 |
+
β `rt=None` WITH A NAMED CONNECTION REFUSES rather than answering from the process-default
|
| 2235 |
+
store, which is D-612's shape (`nav_may_open` leg 3): a caller with no workspace handle is
|
| 2236 |
+
asking about no workspace in particular.
|
| 2237 |
+
"""
|
| 2238 |
+
kc = _keychain()
|
| 2239 |
+
if connection_id is None:
|
| 2240 |
+
cid = kc.default_connection_id(rt, etype) if rt is not None else None
|
| 2241 |
+
# No connection is stored at all: the legacy keys still belong to "whichever connection is
|
| 2242 |
+
# designated default", which is a real answer rather than an absence, and it is the same
|
| 2243 |
+
# sentinel `connection_for_table_key` hands back for exactly this case.
|
| 2244 |
+
return ConnectionScope(cid or DEFAULT_CONNECTION, etype)
|
| 2245 |
+
named = connection_id.strip() if isinstance(connection_id, str) else ''
|
| 2246 |
+
if not named:
|
| 2247 |
+
raise UnknownConnection(
|
| 2248 |
+
'name one connection, or name none and the workspace default serves.')
|
| 2249 |
+
cid = kc.resolve_connection_id(rt, etype, named) if rt is not None else None
|
| 2250 |
+
if not cid:
|
| 2251 |
+
raise UnknownConnection(
|
| 2252 |
+
f"'{named}' does not name a connection in this workspace. Pick a connection in the "
|
| 2253 |
+
f'Connectors panel and read it again.')
|
| 2254 |
+
return ConnectionScope(cid, etype)
|
| 2255 |
+
|
| 2256 |
+
|
| 2257 |
+
def connection_options(rt, etype=DEFAULT_CONNECTION_TYPE):
|
| 2258 |
+
"""The connections a selector may offer, in slot order: `[{'id', 'label'}, ...]`.
|
| 2259 |
+
|
| 2260 |
+
β `allowed_bus()` ONE AXIS OVER, and the ticket asks for it to read like it. The list is what
|
| 2261 |
+
a module's connection selector renders, and the FIRST member is the workspace's designated
|
| 2262 |
+
default, so a client that shows the first row selected shows what a read with no id named would
|
| 2263 |
+
actually serve.
|
| 2264 |
+
|
| 2265 |
+
ββ THERE IS NO "ALL" MEMBER AND THERE IS NO PLACE TO PUT ONE. R7 is explicit that no option
|
| 2266 |
+
may blend two clients, so the option list carries only real connections; a caller that wants
|
| 2267 |
+
"everything" has to ask twice, once per connection, which is exactly what `refresh_all` does.
|
| 2268 |
+
|
| 2269 |
+
β IDENTITY COMES FROM `keychain.resolve_connection_id`, NEVER FROM A SECOND WALK OF THE ROWS.
|
| 2270 |
+
Four first-entry walks were deleted in W54-T45 and a fifth would reopen the ceiling C4 exists
|
| 2271 |
+
to close; the row is read here only for its LABEL and its slot, which no resolver answers. The
|
| 2272 |
+
resolver is also what SKIPS a personal entry of a tenant-wide type, so a credential the readers
|
| 2273 |
+
would never serve cannot appear in a picker as though it would.
|
| 2274 |
+
"""
|
| 2275 |
+
if rt is None:
|
| 2276 |
+
return []
|
| 2277 |
+
kc = _keychain()
|
| 2278 |
+
want = str(etype or DEFAULT_CONNECTION_TYPE).strip().lower()
|
| 2279 |
+
rows, seen = [], set()
|
| 2280 |
+
try:
|
| 2281 |
+
entries = list(kc.list_entries(rt))
|
| 2282 |
+
except Exception: # noqa: BLE001
|
| 2283 |
+
return []
|
| 2284 |
+
for row in entries:
|
| 2285 |
+
if str(row.get('type') or '') != want:
|
| 2286 |
+
continue
|
| 2287 |
+
cid = kc.resolve_connection_id(rt, want,
|
| 2288 |
+
str(row.get('connection_id') or row.get('id') or ''))
|
| 2289 |
+
if not cid or cid in seen:
|
| 2290 |
+
continue
|
| 2291 |
+
seen.add(cid)
|
| 2292 |
+
label = ' '.join(str(row.get('label') or '').split()) or kc.kind_label(want)
|
| 2293 |
+
rows.append((int(row.get('slot') or 0), len(rows), cid, label))
|
| 2294 |
+
rows.sort()
|
| 2295 |
+
return [{'id': cid, 'label': label} for _slot, _pos, cid, label in rows]
|
| 2296 |
+
|
| 2297 |
+
|
| 2298 |
+
def _keychain():
|
| 2299 |
+
import core.keychain as keychain
|
| 2300 |
+
return keychain
|
platform/core/relations.py
CHANGED
|
@@ -59,6 +59,86 @@ booked in this ticket's handoff), ``pin_sql`` delegates to it and this note is d
|
|
| 59 |
#: The three ways a database can be related to another. `via.direction` is always one of these.
|
| 60 |
DIRECTIONS = ('forward', 'reverse', 'bridge')
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
#: The identity column of a module grid, as the wire spells it. `customer_data.pid` IS the Odoo
|
| 63 |
#: `res.partner` id and `ut_odoo_orders.pid` IS the `sale_order` id, so a bridge hanging off `pid`
|
| 64 |
#: needs no second lookup. `product_data.pid` is NOT an Odoo id (it is `crc32(default_code)`),
|
|
@@ -215,7 +295,7 @@ def _entry(key, label, target, direction, field=None, on=None, frm=None, served=
|
|
| 215 |
return out
|
| 216 |
|
| 217 |
|
| 218 |
-
def forward_links(table, fields):
|
| 219 |
"""The FORWARD entries for `table`: every `type: "link"` field on it, in field order.
|
| 220 |
|
| 221 |
`fields` is whatever the caller's permission wall handed back, so a link field this account
|
|
@@ -224,6 +304,10 @@ def forward_links(table, fields):
|
|
| 224 |
|
| 225 |
β TWO LINKS BETWEEN THE SAME PAIR GIVE TWO ENTRIES, and R2 says so in as many words. The entry
|
| 226 |
`key` is the FIELD key, not the target key, which is what keeps them apart on the wire.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
"""
|
| 228 |
out = []
|
| 229 |
for field in (fields or ()):
|
|
@@ -239,10 +323,10 @@ def forward_links(table, fields):
|
|
| 239 |
target=target, direction='forward',
|
| 240 |
field=field.get('key'), on=bag.get('on'),
|
| 241 |
frm=bag.get('from') or IDENTITY_COL))
|
| 242 |
-
return out
|
| 243 |
|
| 244 |
|
| 245 |
-
def reverse_links(table, defs):
|
| 246 |
"""The REVERSE entries for `table`: every OTHER table's link field that points at it.
|
| 247 |
|
| 248 |
`defs` is `{key: definition}` as `core.user_tables.all_defs` returns it, already narrowed to
|
|
@@ -252,6 +336,9 @@ def reverse_links(table, defs):
|
|
| 252 |
β A TABLE'S LINK TO ITSELF IS NOT A REVERSE LINK. It is already a forward one, and emitting
|
| 253 |
both would give the same edge two tabs pointing at the same grid, one of them labelled from
|
| 254 |
the wrong end.
|
|
|
|
|
|
|
|
|
|
| 255 |
"""
|
| 256 |
me = str(table or '')
|
| 257 |
out = []
|
|
@@ -276,15 +363,20 @@ def reverse_links(table, defs):
|
|
| 276 |
# mislabelled `forward` as a negative control for exactly this.
|
| 277 |
on=bag.get('from') or IDENTITY_COL,
|
| 278 |
frm=bag.get('on') or IDENTITY_COL))
|
| 279 |
-
return out
|
|
|
|
| 280 |
|
|
|
|
|
|
|
| 281 |
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
|
|
|
|
|
|
| 288 |
|
| 289 |
|
| 290 |
def edge_identity(entry):
|
|
@@ -301,7 +393,7 @@ def edge_identity(entry):
|
|
| 301 |
str(via.get('from') or ''), str(entry.get('where') or ''))
|
| 302 |
|
| 303 |
|
| 304 |
-
def related(table, fields=None, defs=None):
|
| 305 |
"""THE `/related` ANSWER for one table: forward, then reverse, then bridge.
|
| 306 |
|
| 307 |
`[{key, label, via: {direction, key, field?, on?, from?}, target, served, where?}]`.
|
|
@@ -325,10 +417,11 @@ def related(table, fields=None, defs=None):
|
|
| 325 |
β ON A TENANT WITH NO PRE-SET LINKS the bridge is not a duplicate of anything and is offered
|
| 326 |
unchanged, which is the whole reason the suppression is computed rather than declared.
|
| 327 |
"""
|
| 328 |
-
forward = forward_links(table, fields or ())
|
| 329 |
-
reverse = reverse_links(table, defs or {})
|
| 330 |
seen = {edge_identity(e) for e in forward} | {edge_identity(e) for e in reverse}
|
| 331 |
-
bridges = [b for b in bridge_entries(table
|
|
|
|
| 332 |
return forward + reverse + bridges
|
| 333 |
|
| 334 |
|
|
@@ -734,7 +827,7 @@ def compose_cardinality(a, b):
|
|
| 734 |
return 'many_to_many'
|
| 735 |
|
| 736 |
|
| 737 |
-
def spec_entries(table):
|
| 738 |
"""The CONNECTOR-SPEC edges of `table`, in BOTH directions, in `related()`'s entry shape.
|
| 739 |
|
| 740 |
ββ BOTH DIRECTIONS, AND AN OUTBOUND-ONLY READ CANNOT ANSWER THE QUESTION THIS TICKET ASKS.
|
|
@@ -761,6 +854,13 @@ def spec_entries(table):
|
|
| 761 |
β `served` TAKES `_entry`'s DEFAULT, exactly as the forward and reverse link FIELDS do. Only
|
| 762 |
`BRIDGES` carries a measured `served` today, and inventing one per spec edge here would be a
|
| 763 |
second, unmeasured source for the same judgement.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 764 |
"""
|
| 765 |
spec = _spec()
|
| 766 |
me = str(table or '')
|
|
@@ -786,7 +886,7 @@ def spec_entries(table):
|
|
| 786 |
on=from_col, # the column on the OTHER table
|
| 787 |
frm=to_col, # the column on THIS one
|
| 788 |
cardinality=_INVERSE.get(str(cardinality), 'many_to_many')))
|
| 789 |
-
return out
|
| 790 |
|
| 791 |
|
| 792 |
def _link_field_cardinalities(table, fields, defs):
|
|
@@ -814,7 +914,7 @@ def _link_field_cardinalities(table, fields, defs):
|
|
| 814 |
return out
|
| 815 |
|
| 816 |
|
| 817 |
-
def one_hop(table, fields=None, defs=None):
|
| 818 |
"""EVERYTHING ONE NAMED HOP FROM `table`: `related()` plus the connector spec, deduplicated.
|
| 819 |
|
| 820 |
Every entry carries a `cardinality`, taken from the declaration it came with:
|
|
@@ -831,7 +931,7 @@ def one_hop(table, fields=None, defs=None):
|
|
| 831 |
*"one tab per related table"*. The dedupe is on `edge_identity`, which is target plus both join
|
| 832 |
columns plus the predicate; read its docstring for why `where` is in there.
|
| 833 |
"""
|
| 834 |
-
base = list(related(table, fields, defs))
|
| 835 |
cards = _link_field_cardinalities(table, fields, defs)
|
| 836 |
bridge_cards = {b['key']: _bridge_cardinality(b) for b in BRIDGES}
|
| 837 |
out = []
|
|
@@ -841,7 +941,7 @@ def one_hop(table, fields=None, defs=None):
|
|
| 841 |
entry['cardinality'] = str(got or 'many_to_many')
|
| 842 |
out.append(entry)
|
| 843 |
seen = {edge_identity(e) for e in out}
|
| 844 |
-
for entry in spec_entries(table):
|
| 845 |
if edge_identity(entry) in seen:
|
| 846 |
continue
|
| 847 |
seen.add(edge_identity(entry))
|
|
@@ -880,7 +980,8 @@ def _two_hop_entry(first, second):
|
|
| 880 |
}
|
| 881 |
|
| 882 |
|
| 883 |
-
def related_paths(table, fields=None, defs=None, depth=MAX_DEPTH, may_open=None,
|
|
|
|
| 884 |
"""C3'S `/related` ANSWER: everything reachable from `table` in at most `depth` NAMED hops.
|
| 885 |
|
| 886 |
`[{key, label, via, target, served, where?, cardinality, path, hops}]`, one-hop entries first
|
|
@@ -905,13 +1006,18 @@ def related_paths(table, fields=None, defs=None, depth=MAX_DEPTH, may_open=None,
|
|
| 905 |
|
| 906 |
β A HOP-2 EDGE POINTING BACK AT `table` IS DROPPED. `customer -> orders -> customer` is a round
|
| 907 |
trip, not a relation, and offering it would put a tab on the customers grid labelled Customers.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 908 |
"""
|
| 909 |
if depth not in (1, MAX_DEPTH):
|
| 910 |
raise ValueError(
|
| 911 |
"relation depth is 1 or %d; %r was asked for. The route turns this into a named "
|
| 912 |
"refusal rather than a 500" % (MAX_DEPTH, depth))
|
| 913 |
table = str(table or '')
|
| 914 |
-
hop1 = [e for e in one_hop(table, fields, defs)
|
| 915 |
if may_open is None or may_open(e['target'])]
|
| 916 |
out = []
|
| 917 |
for entry in hop1:
|
|
@@ -925,7 +1031,7 @@ def related_paths(table, fields=None, defs=None, depth=MAX_DEPTH, may_open=None,
|
|
| 925 |
for first in hop1:
|
| 926 |
mid = first['target']
|
| 927 |
mid_fields = fields_for(mid) if fields_for is not None else None
|
| 928 |
-
for second in one_hop(mid, mid_fields, defs):
|
| 929 |
if second['target'] == table:
|
| 930 |
continue
|
| 931 |
if may_open is not None and not may_open(second['target']):
|
|
@@ -1033,7 +1139,7 @@ def over_depth_refusal(table, via):
|
|
| 1033 |
# whether it holds rows for this record. The name, and the fact that the door is shut.
|
| 1034 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββοΏ½οΏ½οΏ½ββββββββββββββββββββββββββββββββββββββββββββ
|
| 1035 |
|
| 1036 |
-
#: β THE THREE R13 ANSWERS, PLUS THE
|
| 1037 |
#: β `unknown_via` KEEPS THE NAME `routes_grid.grid_related` ALREADY RAISES rather than gaining a
|
| 1038 |
#: synonym: a fourth spelling of the same refusal would be a client-visible rename dressed as a
|
| 1039 |
#: feature. `routes_odoo_tables` spells its depth-1 cousin `unknown_relation` and is in another
|
|
@@ -1043,10 +1149,22 @@ REFUSAL_FORBIDDEN_TABLE = 'forbidden_table'
|
|
| 1043 |
REFUSAL_HOP_FILTERED = 'hop_filtered'
|
| 1044 |
REFUSAL_UNKNOWN_VIA = 'unknown_via'
|
| 1045 |
|
| 1046 |
-
#:
|
| 1047 |
-
#:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1048 |
REFUSAL_CODES = (REFUSAL_NO_ROWS, REFUSAL_FORBIDDEN_TABLE, REFUSAL_HOP_FILTERED,
|
| 1049 |
-
REFUSAL_UNKNOWN_VIA)
|
| 1050 |
|
| 1051 |
|
| 1052 |
def _named_path(path):
|
|
@@ -1054,6 +1172,39 @@ def _named_path(path):
|
|
| 1054 |
return ' then '.join(f"'{k}'" for k in (str(p) for p in (path or ())))
|
| 1055 |
|
| 1056 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1057 |
def no_related_rows_refusal(table, path=None):
|
| 1058 |
"""R13's FIRST answer: everything was open, and there is genuinely nothing on the other side.
|
| 1059 |
|
|
@@ -1062,15 +1213,31 @@ def no_related_rows_refusal(table, path=None):
|
|
| 1062 |
of R13, so the empty case is spelled out loud and says in as many words that nothing was
|
| 1063 |
hidden from it.
|
| 1064 |
β NO EM DASH AND NO EN DASH: this string reaches a screen (standing rule 2).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1065 |
"""
|
| 1066 |
named = _named_path(path)
|
| 1067 |
if named:
|
| 1068 |
-
return (f"
|
| 1069 |
f"hop, and it reaches no rows. Nothing was hidden by permission and no hop was "
|
| 1070 |
-
f"filtered
|
| 1071 |
return (f"'{table}' reaches no other database within {MAX_DEPTH} named hops that this account "
|
| 1072 |
f"may open, and nothing was removed by permission on the way. Ask an administrator to "
|
| 1073 |
-
f"link it to another database, or open the database you want on its own")
|
| 1074 |
|
| 1075 |
|
| 1076 |
def forbidden_table_refusal(table, path, blocked, hop=None):
|
|
@@ -1084,14 +1251,92 @@ def forbidden_table_refusal(table, path, blocked, hop=None):
|
|
| 1084 |
could not read at all, so claiming only the first would tell a reader their access was revoked
|
| 1085 |
when the store had merely hiccupped.
|
| 1086 |
β NO EM DASH AND NO EN DASH: this string reaches a screen (standing rule 2).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1087 |
"""
|
| 1088 |
named = _named_path(path) or 'this relation'
|
| 1089 |
where = f" at the hop named '{hop}'" if hop else ''
|
| 1090 |
-
return (f"
|
| 1091 |
f"this account may not open '{blocked}', either because it is not granted to you or "
|
| 1092 |
f"because it could not be read just now. The traversal is refused rather than served "
|
| 1093 |
f"short, so no part of it is silently missing. Ask an administrator for access to "
|
| 1094 |
-
f"'{blocked}', or ask for a relation that does not pass through it")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1095 |
|
| 1096 |
|
| 1097 |
def hop_filtered_refusal(table, path, hop):
|
|
@@ -1103,13 +1348,26 @@ def hop_filtered_refusal(table, path, hop):
|
|
| 1103 |
stay open, so the traversal is neither forbidden nor empty. Served as `[]` it would read as
|
| 1104 |
"this record has nothing here", which is a claim about the business made out of a permission.
|
| 1105 |
β NO EM DASH AND NO EN DASH: this string reaches a screen (standing rule 2).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1106 |
"""
|
| 1107 |
named = _named_path(path) or 'this relation'
|
| 1108 |
-
return (f"
|
| 1109 |
-
f"out for this account. The databases it crosses are open to you
|
| 1110 |
f"this hop is built on is not one you may see, so the hop was removed rather than "
|
| 1111 |
f"answered empty. Ask an administrator for that column, or ask for a relation that "
|
| 1112 |
-
f"does not use it")
|
| 1113 |
|
| 1114 |
|
| 1115 |
def candidate_paths(table, entries, defs=None, fields_for=None):
|
|
@@ -1178,6 +1436,13 @@ def unknown_via_answer(table, keys, candidates):
|
|
| 1178 |
them only into the sentence is what `unknown_via_refusal` used to do, and lane E cannot draw a
|
| 1179 |
retry button out of an English clause.
|
| 1180 |
β NO EM DASH AND NO EN DASH anywhere in `message` (standing rule 2).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1181 |
"""
|
| 1182 |
keys = [str(k) for k in (keys or ())]
|
| 1183 |
cands = list(candidates or ())
|
|
@@ -1198,9 +1463,10 @@ def unknown_via_answer(table, keys, candidates):
|
|
| 1198 |
f"account is offered, then send the 'path' of the one you want, one edge key per "
|
| 1199 |
f"hop")
|
| 1200 |
return {'code': REFUSAL_UNKNOWN_VIA, 'path': keys, 'candidates': cands,
|
| 1201 |
-
'message':
|
| 1202 |
-
|
| 1203 |
-
|
|
|
|
| 1204 |
|
| 1205 |
|
| 1206 |
def _paths_of(entries):
|
|
@@ -1210,8 +1476,12 @@ def _paths_of(entries):
|
|
| 1210 |
|
| 1211 |
def diagnose_path(table, keys, fields=None, defs=None, may_open=None, fields_for=None,
|
| 1212 |
depth=MAX_DEPTH, entries=None, open_entries=None,
|
| 1213 |
-
open_fields=None, open_fields_for=None):
|
| 1214 |
-
"""WHY `pick_path` came back None, as one of
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1215 |
|
| 1216 |
ββ NEVER RAISES AND NEVER RETURNS None. A diagnosis that can itself fail is the fail-open bug
|
| 1217 |
`routes_grid._may_open` warns about: every branch below ends in a real bag carrying a code from
|
|
@@ -1221,6 +1491,13 @@ def diagnose_path(table, keys, fields=None, defs=None, may_open=None, fields_for
|
|
| 1221 |
|
| 1222 |
1. the FILTERED enumeration (`may_open` + the caller's field wall). If `keys` resolves in it,
|
| 1223 |
the path is permitted end to end and reaches nothing: `no_related_rows`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1224 |
2. the UNFILTERED enumeration (no `may_open`, and the widest field list the caller can offer).
|
| 1225 |
If `keys` does not resolve THERE either, the edge genuinely does not exist and no wall was
|
| 1226 |
involved: `unknown_via`, with the candidates, their join columns and the retry strings.
|
|
@@ -1237,8 +1514,10 @@ def diagnose_path(table, keys, fields=None, defs=None, may_open=None, fields_for
|
|
| 1237 |
β `open_fields` / `open_fields_for` MUST BE A SUPERSET of `fields` / `fields_for`, or step 2
|
| 1238 |
can call a wall-removed path unknown. The route builds them as a UNION for exactly that reason;
|
| 1239 |
when they are omitted the diff runs on the table wall alone, which is correct and narrower.
|
| 1240 |
-
β `entries` / `open_entries` ARE AN OPTIMISATION ONLY. The route has
|
| 1241 |
-
|
|
|
|
|
|
|
| 1242 |
"""
|
| 1243 |
keys = [str(k) for k in (keys or ())]
|
| 1244 |
table = str(table or '')
|
|
@@ -1247,7 +1526,19 @@ def diagnose_path(table, keys, fields=None, defs=None, may_open=None, fields_for
|
|
| 1247 |
may_open=may_open, fields_for=fields_for)
|
| 1248 |
if pick_path(entries, keys) is not None:
|
| 1249 |
return {'code': REFUSAL_NO_ROWS, 'path': keys,
|
| 1250 |
-
'message': no_related_rows_refusal(table, keys)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1251 |
if open_entries is None:
|
| 1252 |
open_entries = related_paths(
|
| 1253 |
table, fields=(open_fields if open_fields is not None else fields), defs=defs,
|
|
@@ -1266,21 +1557,25 @@ def diagnose_path(table, keys, fields=None, defs=None, may_open=None, fields_for
|
|
| 1266 |
if blocked and may_open is not None and not may_open(blocked):
|
| 1267 |
return {'code': REFUSAL_FORBIDDEN_TABLE, 'path': keys, 'table': blocked,
|
| 1268 |
'hop': keys[idx],
|
| 1269 |
-
'message': forbidden_table_refusal(table, keys, blocked, keys[idx])
|
|
|
|
| 1270 |
return {'code': REFUSAL_HOP_FILTERED, 'path': keys, 'hop': keys[idx],
|
| 1271 |
-
'message': hop_filtered_refusal(table, keys, keys[idx])
|
|
|
|
| 1272 |
# β EVERY PREFIX SURVIVED AND THE WHOLE DID NOT. Only reachable if two enumerations disagree
|
| 1273 |
# about a path they agree about every prefix of; the last hop is the honest thing to name.
|
| 1274 |
return {'code': REFUSAL_HOP_FILTERED, 'path': keys, 'hop': (keys[-1] if keys else ''),
|
| 1275 |
-
'message': hop_filtered_refusal(table, keys, keys[-1] if keys else '')
|
|
|
|
| 1276 |
|
| 1277 |
|
| 1278 |
def wall_refusals(table, fields=None, defs=None, depth=MAX_DEPTH, may_open=None, fields_for=None,
|
| 1279 |
entries=None, open_entries=None, open_fields=None, open_fields_for=None):
|
| 1280 |
"""THE LISTING ANNOTATION: what the wall removed from this table's enumeration, BY NAME.
|
| 1281 |
|
| 1282 |
-
`[{code, message, path, table?, hop?}]`, a SIBLING of the served list and never a
|
| 1283 |
-
for it.
|
|
|
|
| 1284 |
|
| 1285 |
ββ AN EMPTY LIST IS NEVER AN ACCEPTABLE ANSWER TO A PERMISSION-FILTERED TRAVERSAL, AND THIS
|
| 1286 |
IS THE HALF OF C3 THAT IS EASIEST TO MISS. A 400 on a pin covers the request that named ONE
|
|
@@ -1306,6 +1601,17 @@ def wall_refusals(table, fields=None, defs=None, depth=MAX_DEPTH, may_open=None,
|
|
| 1306 |
table, fields=(open_fields if open_fields is not None else fields), defs=defs,
|
| 1307 |
depth=depth, may_open=None,
|
| 1308 |
fields_for=(open_fields_for if open_fields_for is not None else fields_for))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1309 |
have = _paths_of(entries)
|
| 1310 |
out, seen = [], set()
|
| 1311 |
for entry in open_entries:
|
|
@@ -1314,7 +1620,7 @@ def wall_refusals(table, fields=None, defs=None, depth=MAX_DEPTH, may_open=None,
|
|
| 1314 |
continue
|
| 1315 |
got = diagnose_path(table, path, fields=fields, defs=defs, may_open=may_open,
|
| 1316 |
fields_for=fields_for, depth=depth, entries=entries,
|
| 1317 |
-
open_entries=open_entries)
|
| 1318 |
if got.get('code') == REFUSAL_UNKNOWN_VIA:
|
| 1319 |
continue # cannot happen: `path` came out of `open_entries` itself
|
| 1320 |
ident = (got.get('code'), got.get('table') or '', got.get('hop') or '')
|
|
@@ -1324,5 +1630,6 @@ def wall_refusals(table, fields=None, defs=None, depth=MAX_DEPTH, may_open=None,
|
|
| 1324 |
out.append(got)
|
| 1325 |
if not entries and not out:
|
| 1326 |
out.append({'code': REFUSAL_NO_ROWS, 'path': [],
|
| 1327 |
-
'message': no_related_rows_refusal(table)
|
|
|
|
| 1328 |
return out
|
|
|
|
| 59 |
#: The three ways a database can be related to another. `via.direction` is always one of these.
|
| 60 |
DIRECTIONS = ('forward', 'reverse', 'bridge')
|
| 61 |
|
| 62 |
+
# ===============================================================================================
|
| 63 |
+
# W54-T37 / CONTRACT C5 / INSTRUCTION 22 - A DATABASE THAT IS DECLARED BUT ABSENT.
|
| 64 |
+
#
|
| 65 |
+
# The owner, verbatim: *"a wall of ... this account may not open `ut_odoo_customers` ... THAT
|
| 66 |
+
# DATABASE DOES NOT EXIST."* He is right and the sentence was lying. `ut_odoo_customers` and
|
| 67 |
+
# `ut_odoo_products` were RETIRED: popped from every tenant document on every sync and replaced by
|
| 68 |
+
# the `customer_data` / `product_data` registry modules. The connector spec still DESCRIBES them
|
| 69 |
+
# (a spec describes a shape, it does not assert a table is materialised), so the enumeration below
|
| 70 |
+
# happily minted edges pointing at them, the route wall failed closed on a key it could not find,
|
| 71 |
+
# and the reader was told about a permission problem that does not exist.
|
| 72 |
+
#
|
| 73 |
+
# TWO REPAIRS, IN THIS ORDER, AND THE FIRST IS THE REAL ONE:
|
| 74 |
+
# 1. an edge whose TARGET is retired is NEVER ENUMERATED, in either direction and in BOTH the
|
| 75 |
+
# walled and the unwalled pass. It is not a tab, so it is not a refusal either.
|
| 76 |
+
# 2. a path that names one ANYWAY earns `retired_target`, which says the database is gone. It is
|
| 77 |
+
# a BACKSTOP, and a backstop that fires often means repair 1 has a hole in it.
|
| 78 |
+
#
|
| 79 |
+
# THE LIST LIVES ABOVE, NOT HERE, AND THAT IS THE WHOLE POINT OF THE REGISTRY. `core` never
|
| 80 |
+
# imports up, so it cannot read `odoo_relational.RETIRED_KEYS`; copying the two keys down here
|
| 81 |
+
# would make a second declaration of the same fact, which is the defect class this repo already
|
| 82 |
+
# names [[one-question-two-normalizers]]. The shape is `core.user_tables.register_connected_prefix`
|
| 83 |
+
# verbatim, down to its comment: the engine pushes its list down rather than this module reaching
|
| 84 |
+
# for it. So THIS SET STARTS EMPTY AND STAYS EMPTY until an app-layer registrar runs.
|
| 85 |
+
#
|
| 86 |
+
# A CONSEQUENCE WORTH STATING: in a process where nothing registered anything (a bare platform
|
| 87 |
+
# gate) the filter is a no-op and every edge is enumerated. That is the honest answer there, since
|
| 88 |
+
# such a process has no way to know which tables a deployment retired.
|
| 89 |
+
# ===============================================================================================
|
| 90 |
+
|
| 91 |
+
#: The table keys that are DECLARED somewhere and ABSENT from this deployment: retired, or never
|
| 92 |
+
#: materialised. Empty by construction. See the banner above before adding a literal to it.
|
| 93 |
+
_RETIRED_TABLES = set()
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def register_retired_tables(*keys):
|
| 97 |
+
"""Declare table keys that are described somewhere but do not exist as databases.
|
| 98 |
+
|
| 99 |
+
Takes bare keys, an iterable of keys, or any mix, so a registrar can push a whole tuple down in
|
| 100 |
+
one call. Returns the WHOLE registered set, exactly as `register_connected_prefix` does, so the
|
| 101 |
+
caller can assert what it just joined and the write door answers through the read door.
|
| 102 |
+
|
| 103 |
+
A KEY REGISTERED HERE STOPS BEING AN EDGE TARGET. Nothing else changes: rows, definitions and
|
| 104 |
+
permissions are not this module's business, and a key that is merely unreadable by one account
|
| 105 |
+
is a PERMISSION and belongs to the wall, not here.
|
| 106 |
+
"""
|
| 107 |
+
for key in keys:
|
| 108 |
+
named = [key] if isinstance(key, str) else list(key or ())
|
| 109 |
+
for name in named:
|
| 110 |
+
text = str(name or '').strip()
|
| 111 |
+
if text:
|
| 112 |
+
_RETIRED_TABLES.add(text)
|
| 113 |
+
return retired_tables()
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def retired_tables():
|
| 117 |
+
"""The registered absent-table keys. The ONE list a caller may read to name the same set."""
|
| 118 |
+
return frozenset(_RETIRED_TABLES)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def is_retired_table(key):
|
| 122 |
+
"""Is `key` a database this deployment declares and does not have?"""
|
| 123 |
+
return str(key or '').strip() in _RETIRED_TABLES
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def _live(entries, include_retired=False):
|
| 127 |
+
"""Drop every entry whose TARGET is retired. The one filter, applied by every builder.
|
| 128 |
+
|
| 129 |
+
β IT FILTERS THE **TARGET**, WHICH COVERS BOTH DIRECTIONS WITH ONE RULE. Outbound, the target
|
| 130 |
+
is the parent the spec names (`ut_odoo_orders` -> `ut_odoo_customers`). Inbound, the target is
|
| 131 |
+
the OTHER table, so a retired spec row whose own links point at a live table (the retired
|
| 132 |
+
customers row names `ut_odoo_agents`) produces a reverse entry on the agents grid whose target
|
| 133 |
+
is the retired table. Both are the same test.
|
| 134 |
+
β ENUMERATING **FROM** A RETIRED TABLE IS STILL ALLOWED and is deliberately not this rule: the
|
| 135 |
+
edges of such a table are what a diagnosis walks, and refusing to describe them would replace
|
| 136 |
+
one wrong answer with a shorter one.
|
| 137 |
+
"""
|
| 138 |
+
if include_retired or not _RETIRED_TABLES:
|
| 139 |
+
return list(entries or ())
|
| 140 |
+
return [e for e in (entries or ()) if not is_retired_table(e.get('target'))]
|
| 141 |
+
|
| 142 |
#: The identity column of a module grid, as the wire spells it. `customer_data.pid` IS the Odoo
|
| 143 |
#: `res.partner` id and `ut_odoo_orders.pid` IS the `sale_order` id, so a bridge hanging off `pid`
|
| 144 |
#: needs no second lookup. `product_data.pid` is NOT an Odoo id (it is `crc32(default_code)`),
|
|
|
|
| 295 |
return out
|
| 296 |
|
| 297 |
|
| 298 |
+
def forward_links(table, fields, include_retired=False):
|
| 299 |
"""The FORWARD entries for `table`: every `type: "link"` field on it, in field order.
|
| 300 |
|
| 301 |
`fields` is whatever the caller's permission wall handed back, so a link field this account
|
|
|
|
| 304 |
|
| 305 |
β TWO LINKS BETWEEN THE SAME PAIR GIVE TWO ENTRIES, and R2 says so in as many words. The entry
|
| 306 |
`key` is the FIELD key, not the target key, which is what keeps them apart on the wire.
|
| 307 |
+
|
| 308 |
+
β W54-T37 / C5: a field pointing at a RETIRED table is dropped. A tenant document written
|
| 309 |
+
before a table was retired can still carry such a column, and the tab it would draw opens a
|
| 310 |
+
database this deployment does not have.
|
| 311 |
"""
|
| 312 |
out = []
|
| 313 |
for field in (fields or ()):
|
|
|
|
| 323 |
target=target, direction='forward',
|
| 324 |
field=field.get('key'), on=bag.get('on'),
|
| 325 |
frm=bag.get('from') or IDENTITY_COL))
|
| 326 |
+
return _live(out, include_retired)
|
| 327 |
|
| 328 |
|
| 329 |
+
def reverse_links(table, defs, include_retired=False):
|
| 330 |
"""The REVERSE entries for `table`: every OTHER table's link field that points at it.
|
| 331 |
|
| 332 |
`defs` is `{key: definition}` as `core.user_tables.all_defs` returns it, already narrowed to
|
|
|
|
| 336 |
β A TABLE'S LINK TO ITSELF IS NOT A REVERSE LINK. It is already a forward one, and emitting
|
| 337 |
both would give the same edge two tabs pointing at the same grid, one of them labelled from
|
| 338 |
the wrong end.
|
| 339 |
+
|
| 340 |
+
β W54-T37 / C5: a definition left behind for a RETIRED table is not a reverse link either.
|
| 341 |
+
Its rows are gone, so the tab would open nothing.
|
| 342 |
"""
|
| 343 |
me = str(table or '')
|
| 344 |
out = []
|
|
|
|
| 363 |
# mislabelled `forward` as a negative control for exactly this.
|
| 364 |
on=bag.get('from') or IDENTITY_COL,
|
| 365 |
frm=bag.get('on') or IDENTITY_COL))
|
| 366 |
+
return _live(out, include_retired)
|
| 367 |
+
|
| 368 |
|
| 369 |
+
def bridge_entries(table, include_retired=False):
|
| 370 |
+
"""The BRIDGE entries for `table`, from `BRIDGES` and from nowhere else.
|
| 371 |
|
| 372 |
+
β NO BRIDGE TARGETS A RETIRED TABLE TODAY and the filter is applied anyway, because the day one
|
| 373 |
+
does the alternative is a tab onto a database that is not there. A declared bridge onto an
|
| 374 |
+
absent grain is a DECLARATION BUG, not a served edge, and it should disappear the same way.
|
| 375 |
+
"""
|
| 376 |
+
return _live([_entry(key=b['key'], label=b['label'], target=b['target'], direction='bridge',
|
| 377 |
+
on=b['target_col'], frm=b['source_col'], served=b['served'],
|
| 378 |
+
where=b['where'])
|
| 379 |
+
for b in bridges_from(table)], include_retired)
|
| 380 |
|
| 381 |
|
| 382 |
def edge_identity(entry):
|
|
|
|
| 393 |
str(via.get('from') or ''), str(entry.get('where') or ''))
|
| 394 |
|
| 395 |
|
| 396 |
+
def related(table, fields=None, defs=None, include_retired=False):
|
| 397 |
"""THE `/related` ANSWER for one table: forward, then reverse, then bridge.
|
| 398 |
|
| 399 |
`[{key, label, via: {direction, key, field?, on?, from?}, target, served, where?}]`.
|
|
|
|
| 417 |
β ON A TENANT WITH NO PRE-SET LINKS the bridge is not a duplicate of anything and is offered
|
| 418 |
unchanged, which is the whole reason the suppression is computed rather than declared.
|
| 419 |
"""
|
| 420 |
+
forward = forward_links(table, fields or (), include_retired)
|
| 421 |
+
reverse = reverse_links(table, defs or {}, include_retired)
|
| 422 |
seen = {edge_identity(e) for e in forward} | {edge_identity(e) for e in reverse}
|
| 423 |
+
bridges = [b for b in bridge_entries(table, include_retired)
|
| 424 |
+
if edge_identity(b) not in seen]
|
| 425 |
return forward + reverse + bridges
|
| 426 |
|
| 427 |
|
|
|
|
| 827 |
return 'many_to_many'
|
| 828 |
|
| 829 |
|
| 830 |
+
def spec_entries(table, include_retired=False):
|
| 831 |
"""The CONNECTOR-SPEC edges of `table`, in BOTH directions, in `related()`'s entry shape.
|
| 832 |
|
| 833 |
ββ BOTH DIRECTIONS, AND AN OUTBOUND-ONLY READ CANNOT ANSWER THE QUESTION THIS TICKET ASKS.
|
|
|
|
| 854 |
β `served` TAKES `_entry`'s DEFAULT, exactly as the forward and reverse link FIELDS do. Only
|
| 855 |
`BRIDGES` carries a measured `served` today, and inventing one per spec edge here would be a
|
| 856 |
second, unmeasured source for the same judgement.
|
| 857 |
+
|
| 858 |
+
ββ W54-T37 / C5 / INSTRUCTION 22 - THIS IS WHERE THE OWNER'S REFUSAL WALL WAS MINTED, AND THE
|
| 859 |
+
RETIRED FILTER IS THE PRIMARY REPAIR. Four Odoo specs (invoices, orders, order lines, GL lines)
|
| 860 |
+
declare a link at `ut_odoo_customers` and the line grain declares one at `ut_odoo_products`;
|
| 861 |
+
both keys are RETIRED, so the outbound half offered tabs onto databases that do not exist. The
|
| 862 |
+
inbound half is the mirror image: the retired customers spec row carries its own link at
|
| 863 |
+
`ut_odoo_agents`, so the agents grid was offered a reverse tab back onto the absent table.
|
| 864 |
"""
|
| 865 |
spec = _spec()
|
| 866 |
me = str(table or '')
|
|
|
|
| 886 |
on=from_col, # the column on the OTHER table
|
| 887 |
frm=to_col, # the column on THIS one
|
| 888 |
cardinality=_INVERSE.get(str(cardinality), 'many_to_many')))
|
| 889 |
+
return _live(out, include_retired)
|
| 890 |
|
| 891 |
|
| 892 |
def _link_field_cardinalities(table, fields, defs):
|
|
|
|
| 914 |
return out
|
| 915 |
|
| 916 |
|
| 917 |
+
def one_hop(table, fields=None, defs=None, include_retired=False):
|
| 918 |
"""EVERYTHING ONE NAMED HOP FROM `table`: `related()` plus the connector spec, deduplicated.
|
| 919 |
|
| 920 |
Every entry carries a `cardinality`, taken from the declaration it came with:
|
|
|
|
| 931 |
*"one tab per related table"*. The dedupe is on `edge_identity`, which is target plus both join
|
| 932 |
columns plus the predicate; read its docstring for why `where` is in there.
|
| 933 |
"""
|
| 934 |
+
base = list(related(table, fields, defs, include_retired))
|
| 935 |
cards = _link_field_cardinalities(table, fields, defs)
|
| 936 |
bridge_cards = {b['key']: _bridge_cardinality(b) for b in BRIDGES}
|
| 937 |
out = []
|
|
|
|
| 941 |
entry['cardinality'] = str(got or 'many_to_many')
|
| 942 |
out.append(entry)
|
| 943 |
seen = {edge_identity(e) for e in out}
|
| 944 |
+
for entry in spec_entries(table, include_retired=include_retired):
|
| 945 |
if edge_identity(entry) in seen:
|
| 946 |
continue
|
| 947 |
seen.add(edge_identity(entry))
|
|
|
|
| 980 |
}
|
| 981 |
|
| 982 |
|
| 983 |
+
def related_paths(table, fields=None, defs=None, depth=MAX_DEPTH, may_open=None,
|
| 984 |
+
fields_for=None, include_retired=False):
|
| 985 |
"""C3'S `/related` ANSWER: everything reachable from `table` in at most `depth` NAMED hops.
|
| 986 |
|
| 987 |
`[{key, label, via, target, served, where?, cardinality, path, hops}]`, one-hop entries first
|
|
|
|
| 1006 |
|
| 1007 |
β A HOP-2 EDGE POINTING BACK AT `table` IS DROPPED. `customer -> orders -> customer` is a round
|
| 1008 |
trip, not a relation, and offering it would put a tab on the customers grid labelled Customers.
|
| 1009 |
+
|
| 1010 |
+
ββ `include_retired` IS FOR DIAGNOSIS ONLY AND NOTHING SERVES IT. Left False, no hop lands on
|
| 1011 |
+
a table this deployment declares and does not have; set True, the absent hops come back so a
|
| 1012 |
+
caller can say WHICH one a request named. Both passes of the permission diff leave it False,
|
| 1013 |
+
which is what stops an absent edge being reported as a wall removal.
|
| 1014 |
"""
|
| 1015 |
if depth not in (1, MAX_DEPTH):
|
| 1016 |
raise ValueError(
|
| 1017 |
"relation depth is 1 or %d; %r was asked for. The route turns this into a named "
|
| 1018 |
"refusal rather than a 500" % (MAX_DEPTH, depth))
|
| 1019 |
table = str(table or '')
|
| 1020 |
+
hop1 = [e for e in one_hop(table, fields, defs, include_retired)
|
| 1021 |
if may_open is None or may_open(e['target'])]
|
| 1022 |
out = []
|
| 1023 |
for entry in hop1:
|
|
|
|
| 1031 |
for first in hop1:
|
| 1032 |
mid = first['target']
|
| 1033 |
mid_fields = fields_for(mid) if fields_for is not None else None
|
| 1034 |
+
for second in one_hop(mid, mid_fields, defs, include_retired):
|
| 1035 |
if second['target'] == table:
|
| 1036 |
continue
|
| 1037 |
if may_open is not None and not may_open(second['target']):
|
|
|
|
| 1139 |
# whether it holds rows for this record. The name, and the fact that the door is shut.
|
| 1140 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββοΏ½οΏ½οΏ½ββββββββββββββββββββββββββββββββββββββββββββ
|
| 1141 |
|
| 1142 |
+
#: β THE THREE R13 ANSWERS, PLUS THE ONE THAT IS NOT A PERMISSION ANSWER AT ALL, PLUS C5'S.
|
| 1143 |
#: β `unknown_via` KEEPS THE NAME `routes_grid.grid_related` ALREADY RAISES rather than gaining a
|
| 1144 |
#: synonym: a fourth spelling of the same refusal would be a client-visible rename dressed as a
|
| 1145 |
#: feature. `routes_odoo_tables` spells its depth-1 cousin `unknown_relation` and is in another
|
|
|
|
| 1149 |
REFUSAL_HOP_FILTERED = 'hop_filtered'
|
| 1150 |
REFUSAL_UNKNOWN_VIA = 'unknown_via'
|
| 1151 |
|
| 1152 |
+
#: ββ W54-T37 / C5's FOURTH ANSWER: the edge names a database this deployment does not have.
|
| 1153 |
+
#: β IT IS NOT A PERMISSION ANSWER AND MUST NEVER BE CONFUSED WITH ONE. That confusion IS
|
| 1154 |
+
#: instruction 22: the route wall fails closed on any key it cannot resolve, so an absent table
|
| 1155 |
+
#: came back as `forbidden_table` and the reader was told to ask an administrator for access to a
|
| 1156 |
+
#: database nobody can be granted.
|
| 1157 |
+
REFUSAL_RETIRED_TARGET = 'retired_target'
|
| 1158 |
+
|
| 1159 |
+
#: ββ FIVE ENTRIES, AND C5's *"four wire answers"* IS STILL SATISFIED BY FOUR OF THEM.
|
| 1160 |
+
#: C5 names `no_related_rows`, `forbidden_table`, `hop_filtered` and the new `retired_target`.
|
| 1161 |
+
#: `unknown_via` PREDATES C5 (it is the name `routes_grid.grid_related` has always raised for an
|
| 1162 |
+
#: edge that does not exist at all) and is neither removed nor renamed by it: a fifth spelling of
|
| 1163 |
+
#: an existing refusal would be a client-visible rename dressed as a feature. So the tuple holds
|
| 1164 |
+
#: five and the four C5 names are the ones that are new-or-ruled. A gate reads this rather than
|
| 1165 |
+
#: five literals scattered through two files.
|
| 1166 |
REFUSAL_CODES = (REFUSAL_NO_ROWS, REFUSAL_FORBIDDEN_TABLE, REFUSAL_HOP_FILTERED,
|
| 1167 |
+
REFUSAL_RETIRED_TARGET, REFUSAL_UNKNOWN_VIA)
|
| 1168 |
|
| 1169 |
|
| 1170 |
def _named_path(path):
|
|
|
|
| 1172 |
return ' then '.join(f"'{k}'" for k in (str(p) for p in (path or ())))
|
| 1173 |
|
| 1174 |
|
| 1175 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1176 |
+
# ββ W54-T38 / INSTRUCTION 22 / DESIGN.md SECTION 4 β TWO STRINGS PER REFUSAL: THE SENTENCE AND
|
| 1177 |
+
# THE DIAGNOSIS. THE SPLIT IS AUTHORED HERE BECAUSE THE CLIENT MAY NOT AUTHOR IT.
|
| 1178 |
+
#
|
| 1179 |
+
# The owner pasted one of these refusals back at us, four times over, off one screen. Every word of
|
| 1180 |
+
# it was TRUE after W54-T37 fixed the cause, and it was still the wrong thing to put on a screen:
|
| 1181 |
+
# DESIGN.md section 4 says *"never over-explain"*, and a sixty-word paragraph repeated once per
|
| 1182 |
+
# removed edge is a wall a reader scrolls past to reach the rows they asked for.
|
| 1183 |
+
#
|
| 1184 |
+
# ββ THE FIX IS NOT TO SHORTEN THE DIAGNOSIS. W53-T18 wrote those paragraphs deliberately, so a
|
| 1185 |
+
# traversal is never served short and silent, and deleting them would trade one defect for the one
|
| 1186 |
+
# they were written against. The fix is that the refusal now carries TWO server-authored strings:
|
| 1187 |
+
#
|
| 1188 |
+
# * `message` β ONE SHORT SENTENCE, the thing a reader sees first. It still names whatever R13
|
| 1189 |
+
# and C5 require it to name (the closed table, the filtered hop, the absent database).
|
| 1190 |
+
# * `detail` β the FULL diagnosis, word for word what `message` used to be, for the disclosure
|
| 1191 |
+
# the client puts it behind.
|
| 1192 |
+
#
|
| 1193 |
+
# β WHY THE SERVER SPLITS IT AND NOT THE CLIENT. `RecordDetail.tsx` already carries the rule in as
|
| 1194 |
+
# many words: *"THE SENTENCE IS STILL THE SERVER'S, WHOLE. The code chooses the treatment; it never
|
| 1195 |
+
# rewrites the words, which would fork one wire contract into two opinions."* A client that cut a
|
| 1196 |
+
# paragraph at its first full stop would be authoring copy out of a regular expression, and the day
|
| 1197 |
+
# a sentence gains a comma the summary line changes with nobody having decided it should.
|
| 1198 |
+
#
|
| 1199 |
+
# β `message` STAYS POPULATED AND STAYS FIRST, so every existing reader keeps working: the route's
|
| 1200 |
+
# `_refusal_error` copies it into the X2 envelope, and a client that has never heard of `detail`
|
| 1201 |
+
# shows the short sentence and loses only the explanation.
|
| 1202 |
+
# β NO EM DASH AND NO EN DASH IN EITHER STRING (standing rule 2). Both reach a screen, and D-653
|
| 1203 |
+
# records that no gate scans a Python string for them, so this is checked by eye and by the
|
| 1204 |
+
# snippet in this ticket's handoff.
|
| 1205 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1206 |
+
|
| 1207 |
+
|
| 1208 |
def no_related_rows_refusal(table, path=None):
|
| 1209 |
"""R13's FIRST answer: everything was open, and there is genuinely nothing on the other side.
|
| 1210 |
|
|
|
|
| 1213 |
of R13, so the empty case is spelled out loud and says in as many words that nothing was
|
| 1214 |
hidden from it.
|
| 1215 |
β NO EM DASH AND NO EN DASH: this string reaches a screen (standing rule 2).
|
| 1216 |
+
β W54-T38: THE SENTENCE, and only the sentence. `no_related_rows_detail` carries what this
|
| 1217 |
+
used to say in full. Read the banner above `_named_path` before shortening either of them.
|
| 1218 |
+
"""
|
| 1219 |
+
named = _named_path(path)
|
| 1220 |
+
if named:
|
| 1221 |
+
return f"Nothing is linked through {named} on '{table}'."
|
| 1222 |
+
return f"'{table}' is not linked to any database this account can open."
|
| 1223 |
+
|
| 1224 |
+
|
| 1225 |
+
def no_related_rows_detail(table, path=None):
|
| 1226 |
+
"""The DIAGNOSIS behind `no_related_rows_refusal`, for the client's disclosure.
|
| 1227 |
+
|
| 1228 |
+
β WORD FOR WORD WHAT THE SENTENCE USED TO BE. Nothing was cut: an empty side that says only
|
| 1229 |
+
"nothing is linked" leaves a reader unable to tell it from a wall, which is the whole of R13,
|
| 1230 |
+
so the paragraph that rules that out still exists and is one click away.
|
| 1231 |
+
β NO EM DASH AND NO EN DASH: this string reaches a screen (standing rule 2).
|
| 1232 |
"""
|
| 1233 |
named = _named_path(path)
|
| 1234 |
if named:
|
| 1235 |
+
return (f"The relation reached by {named} on '{table}' is open to this account at every "
|
| 1236 |
f"hop, and it reaches no rows. Nothing was hidden by permission and no hop was "
|
| 1237 |
+
f"filtered, so there is simply nothing on the other side of it.")
|
| 1238 |
return (f"'{table}' reaches no other database within {MAX_DEPTH} named hops that this account "
|
| 1239 |
f"may open, and nothing was removed by permission on the way. Ask an administrator to "
|
| 1240 |
+
f"link it to another database, or open the database you want on its own.")
|
| 1241 |
|
| 1242 |
|
| 1243 |
def forbidden_table_refusal(table, path, blocked, hop=None):
|
|
|
|
| 1251 |
could not read at all, so claiming only the first would tell a reader their access was revoked
|
| 1252 |
when the store had merely hiccupped.
|
| 1253 |
β NO EM DASH AND NO EN DASH: this string reaches a screen (standing rule 2).
|
| 1254 |
+
β W54-T38: THE SENTENCE, and only the sentence. It still NAMES the blocked table, because
|
| 1255 |
+
R13's disclosure is the one thing that may not move behind a disclosure: a reader who cannot
|
| 1256 |
+
see which door is shut has been handed the empty list again. `forbidden_table_detail` carries
|
| 1257 |
+
the pair of causes, the path and the recommendation.
|
| 1258 |
+
β NO DIGITS AND NO PATH IN THIS ONE. `verify_odoo_relational` asserts that this sentence
|
| 1259 |
+
discloses the table's NAME and nothing else about it, digits included, so the hop keys and the
|
| 1260 |
+
path (which may carry either) stay in the detail where the same leg does not reach.
|
| 1261 |
+
"""
|
| 1262 |
+
return (f"This relation passes through '{blocked}', and this account may not open it.")
|
| 1263 |
+
|
| 1264 |
+
|
| 1265 |
+
def forbidden_table_detail(table, path, blocked, hop=None):
|
| 1266 |
+
"""The DIAGNOSIS behind `forbidden_table_refusal`, for the client's disclosure.
|
| 1267 |
+
|
| 1268 |
+
β THE CAUSE IS STILL NAMED AS A PAIR, the posture `routes_odoo_tables._related_pin` takes: the
|
| 1269 |
+
wall is fail-closed and answers False both for a genuine refusal and for a database it could
|
| 1270 |
+
not read at all, so claiming only the first would tell a reader their access was revoked when
|
| 1271 |
+
the store had merely hiccupped.
|
| 1272 |
+
β NO EM DASH AND NO EN DASH: this string reaches a screen (standing rule 2).
|
| 1273 |
"""
|
| 1274 |
named = _named_path(path) or 'this relation'
|
| 1275 |
where = f" at the hop named '{hop}'" if hop else ''
|
| 1276 |
+
return (f"The relation reached by {named} on '{table}' passes through '{blocked}'{where}, and "
|
| 1277 |
f"this account may not open '{blocked}', either because it is not granted to you or "
|
| 1278 |
f"because it could not be read just now. The traversal is refused rather than served "
|
| 1279 |
f"short, so no part of it is silently missing. Ask an administrator for access to "
|
| 1280 |
+
f"'{blocked}', or ask for a relation that does not pass through it.")
|
| 1281 |
+
|
| 1282 |
+
|
| 1283 |
+
def retired_target_refusal(table, path, missing):
|
| 1284 |
+
"""C5's FOURTH answer: the relation opens a database this workspace does not have any more.
|
| 1285 |
+
|
| 1286 |
+
ββ IT SAYS THE TRUE CAUSE AND NAMES NO PERMISSION. Instruction 22 is a wall of *"this account
|
| 1287 |
+
may not open `ut_odoo_customers`"* about a table that was retired, so this sentence may not say
|
| 1288 |
+
"not granted to you" and may not send the reader to an administrator for access: there is no
|
| 1289 |
+
access to grant. It names the database and says it is gone.
|
| 1290 |
+
β SHORT, ON PURPOSE. One sentence. The long diagnosis belongs behind a disclosure, not in a
|
| 1291 |
+
second wall.
|
| 1292 |
+
β W54-T38 FINISHED THAT SENTENCE'S OWN NOTE. T37 wrote "short, on purpose" and then shipped a
|
| 1293 |
+
sentence carrying the path and an API pointer, because there was nowhere else to put them yet.
|
| 1294 |
+
There is now: `retired_target_detail`.
|
| 1295 |
+
β NO EM DASH AND NO EN DASH: this string reaches a screen (standing rule 2).
|
| 1296 |
+
"""
|
| 1297 |
+
return f"'{missing}' is no longer part of this workspace."
|
| 1298 |
+
|
| 1299 |
+
|
| 1300 |
+
def retired_target_detail(table, path, missing):
|
| 1301 |
+
"""The DIAGNOSIS behind `retired_target_refusal`, for the client's disclosure.
|
| 1302 |
+
|
| 1303 |
+
ββ IT NAMES NO PERMISSION EITHER, and that rule does not weaken one level down. Instruction
|
| 1304 |
+
22 is a reader being sent to an administrator for access to a database nobody can grant; the
|
| 1305 |
+
same sentence hidden behind a caret would still be that.
|
| 1306 |
+
β NO EM DASH AND NO EN DASH: this string reaches a screen (standing rule 2).
|
| 1307 |
+
"""
|
| 1308 |
+
named = _named_path(path) or 'this relation'
|
| 1309 |
+
return (f"The relation reached by {named} on '{table}' opens '{missing}', which this "
|
| 1310 |
+
f"deployment does not have any more. It was retired and its rows are gone, so there "
|
| 1311 |
+
f"is nothing to show here and nothing to ask anyone for. Ask GET /api/v1/grid/{table}"
|
| 1312 |
+
f"/related for the relations '{table}' still has.")
|
| 1313 |
+
|
| 1314 |
+
|
| 1315 |
+
def first_retired_on_path(table, keys, fields=None, defs=None, depth=MAX_DEPTH, fields_for=None,
|
| 1316 |
+
retired_entries=None):
|
| 1317 |
+
"""`(absent_target, hop_key)` for the FIRST hop of `keys` that opens a retired table.
|
| 1318 |
+
|
| 1319 |
+
`('', '')` when the path names none, which is every ordinary path: the enumeration already
|
| 1320 |
+
dropped these edges, so this walk is the BACKSTOP and answering nothing is its normal day.
|
| 1321 |
+
|
| 1322 |
+
β IT COSTS NOTHING WHERE NOTHING IS REGISTERED. A process with an empty registry cannot have
|
| 1323 |
+
an absent target, so it returns before enumerating anything at all.
|
| 1324 |
+
β THE PREFIX WALK IS WHY AN INTERMEDIATE IS COVERED WITHOUT A SPECIAL CASE, exactly as the
|
| 1325 |
+
permission diff below covers it: the intermediate of a two-hop path is the target of its
|
| 1326 |
+
one-hop prefix, so a retired intermediate is found at `idx` 0 and named there.
|
| 1327 |
+
"""
|
| 1328 |
+
keys = [str(k) for k in (keys or ())]
|
| 1329 |
+
if not keys or not _RETIRED_TABLES:
|
| 1330 |
+
return ('', '')
|
| 1331 |
+
if retired_entries is None:
|
| 1332 |
+
retired_entries = related_paths(table, fields=fields, defs=defs, depth=depth,
|
| 1333 |
+
may_open=None, fields_for=fields_for,
|
| 1334 |
+
include_retired=True)
|
| 1335 |
+
for idx in range(len(keys)):
|
| 1336 |
+
step = pick_path(retired_entries, keys[:idx + 1])
|
| 1337 |
+
if step is not None and is_retired_table(step.get('target')):
|
| 1338 |
+
return (str(step.get('target')), keys[idx])
|
| 1339 |
+
return ('', '')
|
| 1340 |
|
| 1341 |
|
| 1342 |
def hop_filtered_refusal(table, path, hop):
|
|
|
|
| 1348 |
stay open, so the traversal is neither forbidden nor empty. Served as `[]` it would read as
|
| 1349 |
"this record has nothing here", which is a claim about the business made out of a permission.
|
| 1350 |
β NO EM DASH AND NO EN DASH: this string reaches a screen (standing rule 2).
|
| 1351 |
+
β W54-T38: THE SENTENCE, and only the sentence. It still NAMES the hop for the same reason
|
| 1352 |
+
the forbidden sentence still names the table. `hop_filtered_detail` carries the rest.
|
| 1353 |
+
"""
|
| 1354 |
+
return f"The hop named '{hop}' was filtered out for this account."
|
| 1355 |
+
|
| 1356 |
+
|
| 1357 |
+
def hop_filtered_detail(table, path, hop):
|
| 1358 |
+
"""The DIAGNOSIS behind `hop_filtered_refusal`, for the client's disclosure.
|
| 1359 |
+
|
| 1360 |
+
β IT IS THE ONE THAT MOST NEEDS ITS PARAGRAPH KEPT: "the databases are open to you and the
|
| 1361 |
+
link column is not" is not a thing a reader can guess from a short sentence, and served as an
|
| 1362 |
+
empty grid it would read as a claim about the business.
|
| 1363 |
+
β NO EM DASH AND NO EN DASH: this string reaches a screen (standing rule 2).
|
| 1364 |
"""
|
| 1365 |
named = _named_path(path) or 'this relation'
|
| 1366 |
+
return (f"The hop named '{hop}' of the relation reached by {named} on '{table}' was filtered "
|
| 1367 |
+
f"out for this account. The databases it crosses are open to you. The link column "
|
| 1368 |
f"this hop is built on is not one you may see, so the hop was removed rather than "
|
| 1369 |
f"answered empty. Ask an administrator for that column, or ask for a relation that "
|
| 1370 |
+
f"does not use it.")
|
| 1371 |
|
| 1372 |
|
| 1373 |
def candidate_paths(table, entries, defs=None, fields_for=None):
|
|
|
|
| 1436 |
them only into the sentence is what `unknown_via_refusal` used to do, and lane E cannot draw a
|
| 1437 |
retry button out of an English clause.
|
| 1438 |
β NO EM DASH AND NO EN DASH anywhere in `message` (standing rule 2).
|
| 1439 |
+
|
| 1440 |
+
ββ W54-T38 β AND THIS IS THE LONGEST WALL OF THE FIVE. Measured before this ticket: 1,921
|
| 1441 |
+
characters on `customer_data`, because the enumeration of every candidate with its join
|
| 1442 |
+
columns and retry string is inside the sentence. It splits like the other four: a short
|
| 1443 |
+
`message`, and the whole of what it used to say in `detail`. β THE `candidates` ARRAY IS
|
| 1444 |
+
UNTOUCHED and is still the answer a client renders; the prose was never the machine-readable
|
| 1445 |
+
half and C3 says so.
|
| 1446 |
"""
|
| 1447 |
keys = [str(k) for k in (keys or ())]
|
| 1448 |
cands = list(candidates or ())
|
|
|
|
| 1463 |
f"account is offered, then send the 'path' of the one you want, one edge key per "
|
| 1464 |
f"hop")
|
| 1465 |
return {'code': REFUSAL_UNKNOWN_VIA, 'path': keys, 'candidates': cands,
|
| 1466 |
+
'message': f"'{table}' offers no relation reached by {named} to this account.",
|
| 1467 |
+
'detail': (f"'{table}' offers no relation reached by {named} to this account, and "
|
| 1468 |
+
f"nothing was removed by permission on the way, so this is an edge that "
|
| 1469 |
+
f"does not exist rather than one you may not see." + tail)}
|
| 1470 |
|
| 1471 |
|
| 1472 |
def _paths_of(entries):
|
|
|
|
| 1476 |
|
| 1477 |
def diagnose_path(table, keys, fields=None, defs=None, may_open=None, fields_for=None,
|
| 1478 |
depth=MAX_DEPTH, entries=None, open_entries=None,
|
| 1479 |
+
open_fields=None, open_fields_for=None, retired_entries=None):
|
| 1480 |
+
"""WHY `pick_path` came back None, as one of the named answers.
|
| 1481 |
+
|
| 1482 |
+
`{code, message, detail, table?, hop?}`. β W54-T38 β `message` is ONE SHORT SENTENCE and
|
| 1483 |
+
`detail` is the full diagnosis it used to be; see the banner above `no_related_rows_refusal`
|
| 1484 |
+
for why the split is authored here rather than cut out of a paragraph by the client.
|
| 1485 |
|
| 1486 |
ββ NEVER RAISES AND NEVER RETURNS None. A diagnosis that can itself fail is the fail-open bug
|
| 1487 |
`routes_grid._may_open` warns about: every branch below ends in a real bag carrying a code from
|
|
|
|
| 1491 |
|
| 1492 |
1. the FILTERED enumeration (`may_open` + the caller's field wall). If `keys` resolves in it,
|
| 1493 |
the path is permitted end to end and reaches nothing: `no_related_rows`.
|
| 1494 |
+
1b. ββ W54-T37 / C5 - DOES ANY HOP OPEN A DATABASE THIS DEPLOYMENT DOES NOT HAVE? Then
|
| 1495 |
+
`retired_target`, NAMING it. THIS STEP IS ABOVE BOTH OF THE ONES BELOW AND THE ORDER IS
|
| 1496 |
+
THE TICKET: an absent table is absent from both enumerations, so step 2 would have called
|
| 1497 |
+
it an edge that never existed, and the ROUTE's fail-closed wall (which answers False for
|
| 1498 |
+
a key it cannot resolve) would have made step 3 call it a permission. Instruction 22 is
|
| 1499 |
+
the second of those two wrong answers, printed at a reader who was told to ask for access
|
| 1500 |
+
to a database nobody can grant.
|
| 1501 |
2. the UNFILTERED enumeration (no `may_open`, and the widest field list the caller can offer).
|
| 1502 |
If `keys` does not resolve THERE either, the edge genuinely does not exist and no wall was
|
| 1503 |
involved: `unknown_via`, with the candidates, their join columns and the retry strings.
|
|
|
|
| 1514 |
β `open_fields` / `open_fields_for` MUST BE A SUPERSET of `fields` / `fields_for`, or step 2
|
| 1515 |
can call a wall-removed path unknown. The route builds them as a UNION for exactly that reason;
|
| 1516 |
when they are omitted the diff runs on the table wall alone, which is correct and narrower.
|
| 1517 |
+
β `entries` / `open_entries` / `retired_entries` ARE AN OPTIMISATION ONLY. The route has
|
| 1518 |
+
already paid for the first two; a gate hands none and gets the same answer computed from
|
| 1519 |
+
scratch. The third is the absent-target pass, which is skipped outright where no table is
|
| 1520 |
+
registered as absent.
|
| 1521 |
"""
|
| 1522 |
keys = [str(k) for k in (keys or ())]
|
| 1523 |
table = str(table or '')
|
|
|
|
| 1526 |
may_open=may_open, fields_for=fields_for)
|
| 1527 |
if pick_path(entries, keys) is not None:
|
| 1528 |
return {'code': REFUSAL_NO_ROWS, 'path': keys,
|
| 1529 |
+
'message': no_related_rows_refusal(table, keys),
|
| 1530 |
+
'detail': no_related_rows_detail(table, keys)}
|
| 1531 |
+
# ββ BEFORE THE TWO PERMISSION ANSWERS AND BEFORE `unknown_via`. See step 1b above: a table
|
| 1532 |
+
# that is not there is not a permission and not a typo, and saying either was the defect.
|
| 1533 |
+
missing, missing_hop = first_retired_on_path(
|
| 1534 |
+
table, keys, fields=(open_fields if open_fields is not None else fields), defs=defs,
|
| 1535 |
+
depth=depth, fields_for=(open_fields_for if open_fields_for is not None else fields_for),
|
| 1536 |
+
retired_entries=retired_entries)
|
| 1537 |
+
if missing:
|
| 1538 |
+
return {'code': REFUSAL_RETIRED_TARGET, 'path': keys, 'table': missing,
|
| 1539 |
+
'hop': missing_hop,
|
| 1540 |
+
'message': retired_target_refusal(table, keys, missing),
|
| 1541 |
+
'detail': retired_target_detail(table, keys, missing)}
|
| 1542 |
if open_entries is None:
|
| 1543 |
open_entries = related_paths(
|
| 1544 |
table, fields=(open_fields if open_fields is not None else fields), defs=defs,
|
|
|
|
| 1557 |
if blocked and may_open is not None and not may_open(blocked):
|
| 1558 |
return {'code': REFUSAL_FORBIDDEN_TABLE, 'path': keys, 'table': blocked,
|
| 1559 |
'hop': keys[idx],
|
| 1560 |
+
'message': forbidden_table_refusal(table, keys, blocked, keys[idx]),
|
| 1561 |
+
'detail': forbidden_table_detail(table, keys, blocked, keys[idx])}
|
| 1562 |
return {'code': REFUSAL_HOP_FILTERED, 'path': keys, 'hop': keys[idx],
|
| 1563 |
+
'message': hop_filtered_refusal(table, keys, keys[idx]),
|
| 1564 |
+
'detail': hop_filtered_detail(table, keys, keys[idx])}
|
| 1565 |
# β EVERY PREFIX SURVIVED AND THE WHOLE DID NOT. Only reachable if two enumerations disagree
|
| 1566 |
# about a path they agree about every prefix of; the last hop is the honest thing to name.
|
| 1567 |
return {'code': REFUSAL_HOP_FILTERED, 'path': keys, 'hop': (keys[-1] if keys else ''),
|
| 1568 |
+
'message': hop_filtered_refusal(table, keys, keys[-1] if keys else ''),
|
| 1569 |
+
'detail': hop_filtered_detail(table, keys, keys[-1] if keys else '')}
|
| 1570 |
|
| 1571 |
|
| 1572 |
def wall_refusals(table, fields=None, defs=None, depth=MAX_DEPTH, may_open=None, fields_for=None,
|
| 1573 |
entries=None, open_entries=None, open_fields=None, open_fields_for=None):
|
| 1574 |
"""THE LISTING ANNOTATION: what the wall removed from this table's enumeration, BY NAME.
|
| 1575 |
|
| 1576 |
+
`[{code, message, detail, path, table?, hop?}]`, a SIBLING of the served list and never a
|
| 1577 |
+
replacement for it. β W54-T38 β `message` is the short sentence, `detail` the diagnosis behind
|
| 1578 |
+
the client's disclosure.
|
| 1579 |
|
| 1580 |
ββ AN EMPTY LIST IS NEVER AN ACCEPTABLE ANSWER TO A PERMISSION-FILTERED TRAVERSAL, AND THIS
|
| 1581 |
IS THE HALF OF C3 THAT IS EASIEST TO MISS. A 400 on a pin covers the request that named ONE
|
|
|
|
| 1601 |
table, fields=(open_fields if open_fields is not None else fields), defs=defs,
|
| 1602 |
depth=depth, may_open=None,
|
| 1603 |
fields_for=(open_fields_for if open_fields_for is not None else fields_for))
|
| 1604 |
+
# β ONE absent-target pass for the WHOLE listing, not one per removed path. Every path below
|
| 1605 |
+
# comes out of `open_entries`, which never carries an absent target, so this walk is expected
|
| 1606 |
+
# to find nothing; computing it per path would pay for a full enumeration per refusal to learn
|
| 1607 |
+
# that. β Skipped entirely where nothing is registered as absent.
|
| 1608 |
+
retired_entries = None
|
| 1609 |
+
if _RETIRED_TABLES:
|
| 1610 |
+
retired_entries = related_paths(
|
| 1611 |
+
table, fields=(open_fields if open_fields is not None else fields), defs=defs,
|
| 1612 |
+
depth=depth, may_open=None,
|
| 1613 |
+
fields_for=(open_fields_for if open_fields_for is not None else fields_for),
|
| 1614 |
+
include_retired=True)
|
| 1615 |
have = _paths_of(entries)
|
| 1616 |
out, seen = [], set()
|
| 1617 |
for entry in open_entries:
|
|
|
|
| 1620 |
continue
|
| 1621 |
got = diagnose_path(table, path, fields=fields, defs=defs, may_open=may_open,
|
| 1622 |
fields_for=fields_for, depth=depth, entries=entries,
|
| 1623 |
+
open_entries=open_entries, retired_entries=retired_entries)
|
| 1624 |
if got.get('code') == REFUSAL_UNKNOWN_VIA:
|
| 1625 |
continue # cannot happen: `path` came out of `open_entries` itself
|
| 1626 |
ident = (got.get('code'), got.get('table') or '', got.get('hop') or '')
|
|
|
|
| 1630 |
out.append(got)
|
| 1631 |
if not entries and not out:
|
| 1632 |
out.append({'code': REFUSAL_NO_ROWS, 'path': [],
|
| 1633 |
+
'message': no_related_rows_refusal(table),
|
| 1634 |
+
'detail': no_related_rows_detail(table)})
|
| 1635 |
return out
|
platform/core/sheets.py
CHANGED
|
@@ -98,6 +98,24 @@ CELL_ALIGNS = ("left", "center", "right")
|
|
| 98 |
CELL_VALIGNS = ("top", "middle", "bottom")
|
| 99 |
CELL_SIZES = ("s", "m", "l", "xl")
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
#: The style keys A1 and C2 name. Anything else is DROPPED, in silence and on purpose; see
|
| 102 |
#: `_clean_style` for why that is not the same decision as an unknown `format.kind`.
|
| 103 |
_STYLE_MARKS = ("bold", "italic", "underline")
|
|
@@ -107,6 +125,28 @@ _BORDER_SIDES = ("top", "right", "bottom", "left")
|
|
| 107 |
#: outlives every layout change, exactly as a stored hex outlives a palette.
|
| 108 |
_MAX_INDENT = 8
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
#: C2's custom format code. β THE CAPS ARE PART OF THE VOCABULARY, not a guess: a format code is
|
| 111 |
#: interpreted by the client's formatter, so an unbounded one is an unbounded parse, and Excel's
|
| 112 |
#: own grammar holds at most four sections (positive; negative; zero; text).
|
|
@@ -123,13 +163,57 @@ _MAX_VALIDATION_ENTRY = 200
|
|
| 123 |
SHEET_RULE_OPS = ("gt", "lt", "gte", "lte", "eq", "neq", "between", "contains", "empty",
|
| 124 |
"notEmpty")
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
#: The style keys a conditional format rule may repaint. A rule is a PAINT, never a format: it
|
| 127 |
#: cannot change how a number reads, so it carries no `format`.
|
| 128 |
_RULE_STYLE_MARKS = ("bold",)
|
| 129 |
_RULE_STYLE_COLOURS = ("fill", "color")
|
| 130 |
|
| 131 |
-
#:
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
_MAX_RULES = 100
|
| 135 |
_MAX_HIDDEN = 5000
|
|
@@ -152,8 +236,8 @@ _MAX_DECIMALS = 10
|
|
| 152 |
#: column letters and seven row digits, and `a1.ts` agrees with it; 702 is the last TWO letter
|
| 153 |
#: column (ZZ) and 100000 rows is what glide's virtualised scroller stays comfortable inside. A
|
| 154 |
#: sheet at the ceiling is still far above `_MAX_CELLS_PER_SHEET`, so content runs out first.
|
| 155 |
-
DEFAULT_SHEET_COLS =
|
| 156 |
-
DEFAULT_SHEET_ROWS =
|
| 157 |
DEFAULT_COL_WIDTH = 120
|
| 158 |
MIN_SHEET_COLS = 1
|
| 159 |
MIN_SHEET_ROWS = 1
|
|
@@ -453,9 +537,38 @@ def _clean_style(raw):
|
|
| 453 |
if steps:
|
| 454 |
out["indent"] = steps
|
| 455 |
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
|
| 460 |
fmt = _clean_format(raw.get("format"))
|
| 461 |
if fmt:
|
|
@@ -499,6 +612,56 @@ def _clean_validation(raw):
|
|
| 499 |
return {"list": out} if out else None
|
| 500 |
|
| 501 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
def clean_cell(raw, addr=""):
|
| 503 |
"""Normalize ONE cell, or raise `SheetRefusal` with a named code.
|
| 504 |
|
|
@@ -541,6 +704,15 @@ def clean_cell(raw, addr=""):
|
|
| 541 |
validation = _clean_validation(raw.get("validation"))
|
| 542 |
if validation:
|
| 543 |
cell["validation"] = validation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 544 |
return cell
|
| 545 |
|
| 546 |
if raw.get("text") is not None:
|
|
@@ -567,6 +739,21 @@ def clean_cell(raw, addr=""):
|
|
| 567 |
if raw.get("refreshed_at") is not None:
|
| 568 |
cell["refreshed_at"] = _text(raw.get("refreshed_at"), 120)
|
| 569 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 570 |
#: C2: the in-cell list. Normalized before the style so a refusing style still reports first.
|
| 571 |
validation = _clean_validation(raw.get("validation"))
|
| 572 |
if validation:
|
|
@@ -734,15 +921,43 @@ def _clean_rule_style(raw):
|
|
| 734 |
return out
|
| 735 |
|
| 736 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 737 |
def _clean_rules(raw):
|
| 738 |
"""C2's conditional format rules for one tab, at most `_MAX_RULES` of them.
|
| 739 |
|
| 740 |
β AN OP OUTSIDE `SHEET_RULE_OPS` IS REFUSED BY NAME, for `_clean_format`'s reason: a rule
|
| 741 |
whose operator nothing can evaluate never fires, so dropping it would leave a person looking
|
| 742 |
-
at a sheet they believe is painted by a rule that is not there.
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 746 |
"""
|
| 747 |
if raw is None:
|
| 748 |
return []
|
|
@@ -757,11 +972,23 @@ def _clean_rules(raw):
|
|
| 757 |
raise SheetRefusal(
|
| 758 |
"sheet_rule_op_unknown",
|
| 759 |
"A sheet rule condition must be one of " + ", ".join(SHEET_RULE_OPS) + ".")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 760 |
rect = _clean_range(row.get("range"))
|
| 761 |
if rect is None:
|
| 762 |
continue
|
| 763 |
rule = {"id": _text(row.get("id"), _MAX_ID) or uuid.uuid4().hex[:12],
|
| 764 |
"range": rect, "op": op, "style": _clean_rule_style(row.get("style"))}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 765 |
#: β `empty` and `notEmpty` take NO operand, and carrying one would store a rule whose
|
| 766 |
#: text says it compares against something it can never read.
|
| 767 |
if op not in ("empty", "notEmpty"):
|
|
@@ -851,8 +1078,15 @@ def _clean_sheet(raw, index=0):
|
|
| 851 |
|
| 852 |
β EVERY KEY THIS FUNCTION DOES NOT NAME IS DROPPED, and that is worth knowing before adding
|
| 853 |
one: the return below is a fresh dict, not an amended copy of `raw`. A2's four geometry keys
|
| 854 |
-
and C2's five strata are named
|
| 855 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 856 |
"""
|
| 857 |
if not isinstance(raw, dict):
|
| 858 |
raise SheetRefusal("sheet_not_an_object", "A sheet must be an object.")
|
|
@@ -868,28 +1102,34 @@ def _clean_sheet(raw, index=0):
|
|
| 868 |
#: silently un-described.
|
| 869 |
sheet = {"id": sid, "name": name, "cols": cols, "rows": rows,
|
| 870 |
"cells": _clean_cells(raw.get("cells"), sheet_name=name)}
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 893 |
return sheet
|
| 894 |
|
| 895 |
|
|
|
|
| 98 |
CELL_VALIGNS = ("top", "middle", "bottom")
|
| 99 |
CELL_SIZES = ("s", "m", "l", "xl")
|
| 100 |
|
| 101 |
+
#: ββ WAVE 54 / R10 + R11 - THE TYPEFACE AND THE POINT SIZE. Mirrored in
|
| 102 |
+
#: `types.ts::CELL_FONTS` / `DEFAULT_CELL_FONT` / `DEFAULT_FONT_PT` / `MIN_FONT_PT` / `MAX_FONT_PT`.
|
| 103 |
+
#:
|
| 104 |
+
#: R10: a cell's typeface is USER DATA, exactly as its fill colour is; the app's own chrome stays
|
| 105 |
+
#: Inter and that is a different decision. The list is closed and every face in it is one a machine
|
| 106 |
+
#: already has, because the client imports no webfont; the bare NAME is what is stored and the
|
| 107 |
+
#: client resolves it to a full stack at paint time, for the reason a colour is stored as a token.
|
| 108 |
+
#:
|
| 109 |
+
#: R11: the `size` slot carries EITHER one of the four step names above OR a point size, and never
|
| 110 |
+
#: a second field. `DEFAULT_FONT_PT` is `m`, in points, and both are stored as an ABSENCE.
|
| 111 |
+
CELL_FONTS = (
|
| 112 |
+
"Inter", "Arial", "Georgia", "Times New Roman", "Courier New", "Verdana", "Trebuchet MS",
|
| 113 |
+
)
|
| 114 |
+
DEFAULT_CELL_FONT = "Inter"
|
| 115 |
+
DEFAULT_FONT_PT = 10
|
| 116 |
+
MIN_FONT_PT = 6
|
| 117 |
+
MAX_FONT_PT = 96
|
| 118 |
+
|
| 119 |
#: The style keys A1 and C2 name. Anything else is DROPPED, in silence and on purpose; see
|
| 120 |
#: `_clean_style` for why that is not the same decision as an unknown `format.kind`.
|
| 121 |
_STYLE_MARKS = ("bold", "italic", "underline")
|
|
|
|
| 125 |
#: outlives every layout change, exactly as a stored hex outlives a palette.
|
| 126 |
_MAX_INDENT = 8
|
| 127 |
|
| 128 |
+
#: Wave 54: how far a cell's value may be turned, in DEGREES. Excel's own range, and it is signed
|
| 129 |
+
#: because turning a header up and turning it down are two different requests. Zero is upright and
|
| 130 |
+
#: is stored as an ABSENCE, for `_clean_style`'s falsey-mark reason. Mirrored in
|
| 131 |
+
#: `types.ts::MIN_TEXT_ROTATION` / `MAX_TEXT_ROTATION`.
|
| 132 |
+
MIN_TEXT_ROTATION = -90
|
| 133 |
+
MAX_TEXT_ROTATION = 90
|
| 134 |
+
|
| 135 |
+
#: Wave 54: a cell may carry a LINK and a NOTE, and neither is a value. A note is never counted as
|
| 136 |
+
#: hand typed, never reaches a formula and never becomes a cell's display; a link says what its
|
| 137 |
+
#: target IS, because a web address, an A1 address and a tab name are opened by three different
|
| 138 |
+
#: doors. Mirrored in `types.ts::Cell.link` / `Cell.note`.
|
| 139 |
+
CELL_LINK_KINDS = ("url", "cell", "sheet")
|
| 140 |
+
_MAX_LINK_HREF = 512
|
| 141 |
+
_MAX_CELL_NOTE = 1000
|
| 142 |
+
|
| 143 |
+
#: Wave 54: a cell may also carry a SPARKLINE, a picture of a range drawn inside the cell itself.
|
| 144 |
+
#: It is CELL level and not tab level, unlike a chart, because that is what it is: the renderer is
|
| 145 |
+
#: `web/src/sheet/sparkline.ts`, called from `SheetGrid.tsx::paintCell` with the cell in hand, so
|
| 146 |
+
#: a tab-level array would have to be searched per cell on every paint. The three kinds are
|
| 147 |
+
#: Excel's own. Mirrored in `types.ts::SPARKLINE_KINDS` / `CellSparkline`.
|
| 148 |
+
SPARKLINE_KINDS = ("line", "column", "winloss")
|
| 149 |
+
|
| 150 |
#: C2's custom format code. β THE CAPS ARE PART OF THE VOCABULARY, not a guess: a format code is
|
| 151 |
#: interpreted by the client's formatter, so an unbounded one is an unbounded parse, and Excel's
|
| 152 |
#: own grammar holds at most four sections (positive; negative; zero; text).
|
|
|
|
| 163 |
SHEET_RULE_OPS = ("gt", "lt", "gte", "lte", "eq", "neq", "between", "contains", "empty",
|
| 164 |
"notEmpty")
|
| 165 |
|
| 166 |
+
#: ββ W54-T05's THREE RULE KINDS, and the SAME refusal discipline the ten operators get. A
|
| 167 |
+
#: `cell` rule is a condition and a flat style; a `scale` bands its value across a stored low..high
|
| 168 |
+
#: range; a `bar` draws a proportional rectangle inside the cell. A kind nothing can paint is
|
| 169 |
+
#: refused by name rather than dropped, because dropping it would silently turn a colour scale into
|
| 170 |
+
#: a highlight rule reading `between`, which is a DIFFERENT paint than the one somebody asked for.
|
| 171 |
+
#:
|
| 172 |
+
#: β `cell` IS STORED AS AN ABSENCE, exactly as `wrap: false` and `indent: 0` are: it is what
|
| 173 |
+
#: every rule written before this ticket already is, so writing the word onto them would make a
|
| 174 |
+
#: reload compare unequal to the save. Mirrored in `web/src/sheet/types.ts::SHEET_RULE_KINDS`.
|
| 175 |
+
SHEET_RULE_KINDS = ("cell", "scale", "bar")
|
| 176 |
+
|
| 177 |
#: The style keys a conditional format rule may repaint. A rule is a PAINT, never a format: it
|
| 178 |
#: cannot change how a number reads, so it carries no `format`.
|
| 179 |
_RULE_STYLE_MARKS = ("bold",)
|
| 180 |
_RULE_STYLE_COLOURS = ("fill", "color")
|
| 181 |
|
| 182 |
+
#: ββ THE CHART KINDS A DOCUMENT MAY HOLD, which is NOT the same list as the chart kinds a
|
| 183 |
+
#: renderer can draw, and the two were one list until wave 54 made the difference matter.
|
| 184 |
+
#: `_clean_charts` drops a chart whose kind is outside this tuple, so a kind missing from here is
|
| 185 |
+
#: a picture somebody made that is gone on the next read, in silence: exactly D-640's mechanism,
|
| 186 |
+
#: one level down. This tuple is therefore the STORAGE vocabulary and it is mirrored, name for
|
| 187 |
+
#: name and in this order, by `types.ts::SheetChartSpec.kind`.
|
| 188 |
+
#:
|
| 189 |
+
#: β `types.ts::SHEET_CHART_DRAWN_KINDS` IS A DIFFERENT AND NARROWER THING: a CAPABILITY list,
|
| 190 |
+
#: naming the kinds the client can put on a canvas today. A kind stored here and not drawn there
|
| 191 |
+
#: is a chart the document keeps safely while its renderer is built. The reverse, a kind drawn
|
| 192 |
+
#: but not stored here, is the defect, and it is what widening this tuple prevents.
|
| 193 |
+
SHEET_CHART_KINDS = ("bar", "line", "area", "donut", "column", "pie", "scatter", "combo")
|
| 194 |
+
|
| 195 |
+
#: ββ D-640's MECHANISM, STATED. THIS IS EVERY KEY A CLEANED TAB MAY CARRY, and a key that is
|
| 196 |
+
#: not named here is DELETED on the next save, in silence, with nothing going red: `_clean_sheet`
|
| 197 |
+
#: returns a FRESH dict rather than an amended copy of what it was handed, so the document saves,
|
| 198 |
+
#: the tab is valid, and whatever the client put in the unnamed slot is simply not in it. That is
|
| 199 |
+
#: how `charts` was eaten between W49-T08 and W51-T21, and it is how the NEXT slot added to a tab
|
| 200 |
+
#: gets eaten unless its name is added to this tuple in the same change that adds it.
|
| 201 |
+
#:
|
| 202 |
+
#: β THE SET IS THE FUNCTION'S OWN RULER. `_clean_sheet` emits its optional strata by walking
|
| 203 |
+
#: this tuple, so the two cannot drift apart by an edit to one of them, and `verify_sheet.py`
|
| 204 |
+
#: section 1 drives the real cleaner with a tab carrying every stratum and asserts it returns
|
| 205 |
+
#: nothing outside this set. Removing `charts` from here reds that leg, which is the negative
|
| 206 |
+
#: control D-640 is closed with.
|
| 207 |
+
#:
|
| 208 |
+
#: The order is the order a cleaned tab reads in: identity, then A2's geometry, then C2's strata.
|
| 209 |
+
SHEET_TAB_KEYS = ("id", "name", "cols", "rows", "cells", "colWidths", "freeze",
|
| 210 |
+
"rules", "hiddenRows", "hiddenCols", "charts", "imported")
|
| 211 |
+
|
| 212 |
+
#: The keys above that `_clean_sheet` writes UNCONDITIONALLY. Every other member of
|
| 213 |
+
#: `SHEET_TAB_KEYS` is written only when it holds something, for `_clean_style`'s reason: a tab
|
| 214 |
+
#: with no rules and a tab with `rules: []` read identically, so only one of them is stored and a
|
| 215 |
+
#: reload compares equal to the thing it saved.
|
| 216 |
+
SHEET_TAB_ALWAYS_KEYS = ("id", "name", "cols", "rows", "cells")
|
| 217 |
|
| 218 |
_MAX_RULES = 100
|
| 219 |
_MAX_HIDDEN = 5000
|
|
|
|
| 236 |
#: column letters and seven row digits, and `a1.ts` agrees with it; 702 is the last TWO letter
|
| 237 |
#: column (ZZ) and 100000 rows is what glide's virtualised scroller stays comfortable inside. A
|
| 238 |
#: sheet at the ceiling is still far above `_MAX_CELLS_PER_SHEET`, so content runs out first.
|
| 239 |
+
DEFAULT_SHEET_COLS = 200
|
| 240 |
+
DEFAULT_SHEET_ROWS = 10000
|
| 241 |
DEFAULT_COL_WIDTH = 120
|
| 242 |
MIN_SHEET_COLS = 1
|
| 243 |
MIN_SHEET_ROWS = 1
|
|
|
|
| 537 |
if steps:
|
| 538 |
out["indent"] = steps
|
| 539 |
|
| 540 |
+
#: ββ R11: THE SAME SLOT, TWO SHAPES, AND THE ORDER OF THE BRANCHES IS THE WHOLE OF IT.
|
| 541 |
+
#: `_text` stringifies anything it is handed, so reading a point size through it would turn 12
|
| 542 |
+
#: into "12", find it outside the four step names and drop it in silence: a size the person
|
| 543 |
+
#: picked, gone on the next read with nothing to say so. The type is decided FIRST, and a step
|
| 544 |
+
#: name still round trips exactly as it always did. A point size is CLAMPED, not refused, for
|
| 545 |
+
#: the rotation's reason below, and the default is stored as an absence just as `m` is.
|
| 546 |
+
size = raw.get("size")
|
| 547 |
+
if isinstance(size, str):
|
| 548 |
+
step = _text(size, 4)
|
| 549 |
+
if step in CELL_SIZES and step != "m":
|
| 550 |
+
out["size"] = step
|
| 551 |
+
elif not isinstance(size, bool) and isinstance(size, (int, float)):
|
| 552 |
+
points = max(MIN_FONT_PT, min(MAX_FONT_PT, int(round(size))))
|
| 553 |
+
if points != DEFAULT_FONT_PT:
|
| 554 |
+
out["size"] = points
|
| 555 |
+
|
| 556 |
+
#: R10's typeface. A name outside the closed list is DROPPED in silence, which is this
|
| 557 |
+
#: cleaner's house rule for a decoration the client cannot promise to paint; the default face
|
| 558 |
+
#: is an absence, so a cell set back to it is the cell it was.
|
| 559 |
+
font = _text(raw.get("font"), 40)
|
| 560 |
+
if font in CELL_FONTS and font != DEFAULT_CELL_FONT:
|
| 561 |
+
out["font"] = font
|
| 562 |
+
|
| 563 |
+
#: Wave 54's turn, clamped rather than refused, exactly as the indent is: a rotation is a
|
| 564 |
+
#: presentation, so 400 degrees is somebody asking for the most turn there is, not a document
|
| 565 |
+
#: that has to be rejected. Upright is stored as an absence, so an unrotated cell is byte for
|
| 566 |
+
#: byte the cell it was before somebody turned it and turned it back.
|
| 567 |
+
rotation = raw.get("textRotation")
|
| 568 |
+
if not isinstance(rotation, bool) and isinstance(rotation, (int, float)):
|
| 569 |
+
degrees = max(MIN_TEXT_ROTATION, min(MAX_TEXT_ROTATION, int(rotation)))
|
| 570 |
+
if degrees:
|
| 571 |
+
out["textRotation"] = degrees
|
| 572 |
|
| 573 |
fmt = _clean_format(raw.get("format"))
|
| 574 |
if fmt:
|
|
|
|
| 612 |
return {"list": out} if out else None
|
| 613 |
|
| 614 |
|
| 615 |
+
def _clean_link(raw):
|
| 616 |
+
"""Wave 54's cell link `{href, kind}`, or None when nothing survives.
|
| 617 |
+
|
| 618 |
+
β BOTH HALVES OR NEITHER. A link with a target and no kind cannot be opened, because the kind
|
| 619 |
+
is what decides WHICH door opens it: a web address, an A1 address on this workbook, and a tab
|
| 620 |
+
by name are three different acts. Storing half of one would leave a cell wearing an
|
| 621 |
+
affordance that does nothing when it is clicked.
|
| 622 |
+
|
| 623 |
+
β THE HREF IS CLAMPED, NOT PARSED. This module stores documents; deciding whether a URL is
|
| 624 |
+
reachable, or whether `Sheet2!B7` exists, belongs to the door that opens it, which can say so
|
| 625 |
+
at the moment somebody clicks.
|
| 626 |
+
"""
|
| 627 |
+
if not isinstance(raw, dict):
|
| 628 |
+
return None
|
| 629 |
+
kind = _text(raw.get("kind"), 12)
|
| 630 |
+
href = _text(raw.get("href"), _MAX_LINK_HREF)
|
| 631 |
+
if kind not in CELL_LINK_KINDS or not href:
|
| 632 |
+
return None
|
| 633 |
+
return {"href": href, "kind": kind}
|
| 634 |
+
|
| 635 |
+
|
| 636 |
+
def _clean_sparkline(raw):
|
| 637 |
+
"""Wave 54's in-cell sparkline `{kind, range}`, or None when nothing survives.
|
| 638 |
+
|
| 639 |
+
β BOTH HALVES OR NEITHER, for `_clean_link`'s reason. A sparkline with a range and no kind
|
| 640 |
+
cannot be drawn, because the kind is what decides WHICH picture is drawn over those numbers: a
|
| 641 |
+
line, a column run and a win/loss bar say three different things about the same range. Storing
|
| 642 |
+
half of one would leave a cell that claims to hold a picture nothing can put on a canvas.
|
| 643 |
+
|
| 644 |
+
β IT IS DROPPED WHEN MALFORMED, NEVER REFUSED, which is the link's decision and not the format
|
| 645 |
+
code's: a sparkline does not change what any cell READS AS, so a broken one is a missing
|
| 646 |
+
picture and never a wrong number on a screen. Refusing would 400 a whole workbook save over a
|
| 647 |
+
decoration.
|
| 648 |
+
|
| 649 |
+
β THE RANGE IS `_clean_range`'s, so a sparkline's rectangle is spelled the same way a chart's
|
| 650 |
+
and a rule's are. It takes `"B2:D40"`, the single cell `"B2"` and the rectangle dict, and it
|
| 651 |
+
stores the rectangle: a document with two spellings of one rectangle is a document every later
|
| 652 |
+
reader has to branch on.
|
| 653 |
+
"""
|
| 654 |
+
if not isinstance(raw, dict):
|
| 655 |
+
return None
|
| 656 |
+
kind = _text(raw.get("kind"), 20)
|
| 657 |
+
if kind not in SPARKLINE_KINDS:
|
| 658 |
+
return None
|
| 659 |
+
rect = _clean_range(raw.get("range"))
|
| 660 |
+
if rect is None:
|
| 661 |
+
return None
|
| 662 |
+
return {"kind": kind, "range": rect}
|
| 663 |
+
|
| 664 |
+
|
| 665 |
def clean_cell(raw, addr=""):
|
| 666 |
"""Normalize ONE cell, or raise `SheetRefusal` with a named code.
|
| 667 |
|
|
|
|
| 704 |
validation = _clean_validation(raw.get("validation"))
|
| 705 |
if validation:
|
| 706 |
cell["validation"] = validation
|
| 707 |
+
#: β THE SPARKLINE SURVIVES THIS BRANCH, AND LEAVING IT OUT WOULD BE THE COMMON CASE
|
| 708 |
+
#: RATHER THAN THE EDGE ONE. A sparkline cell usually holds no text at all: somebody
|
| 709 |
+
#: paints a picture of the row beside it and types nothing, which is precisely an
|
| 710 |
+
#: `empty` cell. A picture is not content in the sense this branch strips, because it
|
| 711 |
+
#: has no value, is never hand typed and never reaches a formula, so it belongs with
|
| 712 |
+
#: the style rather than with the text that is dropped here.
|
| 713 |
+
sparkline = _clean_sparkline(raw.get("sparkline"))
|
| 714 |
+
if sparkline:
|
| 715 |
+
cell["sparkline"] = sparkline
|
| 716 |
return cell
|
| 717 |
|
| 718 |
if raw.get("text") is not None:
|
|
|
|
| 739 |
if raw.get("refreshed_at") is not None:
|
| 740 |
cell["refreshed_at"] = _text(raw.get("refreshed_at"), 120)
|
| 741 |
|
| 742 |
+
#: Wave 54's link, note and sparkline. All three are DROPPED when malformed rather than
|
| 743 |
+
#: refused, which is the validation list's decision and not the format code's: none of them
|
| 744 |
+
#: changes what the cell READS AS, so a broken link is a missing affordance and a broken
|
| 745 |
+
#: sparkline is a missing picture, never a wrong number on a screen.
|
| 746 |
+
link = _clean_link(raw.get("link"))
|
| 747 |
+
if link:
|
| 748 |
+
cell["link"] = link
|
| 749 |
+
if raw.get("note") is not None:
|
| 750 |
+
note = _text(raw.get("note"), _MAX_CELL_NOTE)
|
| 751 |
+
if note:
|
| 752 |
+
cell["note"] = note
|
| 753 |
+
sparkline = _clean_sparkline(raw.get("sparkline"))
|
| 754 |
+
if sparkline:
|
| 755 |
+
cell["sparkline"] = sparkline
|
| 756 |
+
|
| 757 |
#: C2: the in-cell list. Normalized before the style so a refusing style still reports first.
|
| 758 |
validation = _clean_validation(raw.get("validation"))
|
| 759 |
if validation:
|
|
|
|
| 921 |
return out
|
| 922 |
|
| 923 |
|
| 924 |
+
def _clean_rule_scale(raw):
|
| 925 |
+
"""A COLOUR SCALE's two end TOKENS, or None.
|
| 926 |
+
|
| 927 |
+
β BOTH ENDS OR NEITHER. One end alone names no ramp at all, and storing half of one would
|
| 928 |
+
leave the client looking up a pair that cannot match and falling back to a default scale the
|
| 929 |
+
person never chose. The tokens go through the same `_COLOUR` guard `_clean_rule_style` uses,
|
| 930 |
+
so nothing free form reaches a canvas `fillStyle` from a stored document.
|
| 931 |
+
|
| 932 |
+
β THE SCALE'S BOUNDS ARE NOT HERE. They ride `value` and `value2` on the rule itself, which
|
| 933 |
+
`_clean_rules` already persists for every op that takes operands, so a colour scale needed no
|
| 934 |
+
new numeric slot at all.
|
| 935 |
+
"""
|
| 936 |
+
if not isinstance(raw, dict):
|
| 937 |
+
return None
|
| 938 |
+
out = {}
|
| 939 |
+
for key in ("low", "high"):
|
| 940 |
+
token = _text(raw.get(key), 40)
|
| 941 |
+
if not token or not _COLOUR.match(token):
|
| 942 |
+
return None
|
| 943 |
+
out[key] = token
|
| 944 |
+
return out
|
| 945 |
+
|
| 946 |
+
|
| 947 |
def _clean_rules(raw):
|
| 948 |
"""C2's conditional format rules for one tab, at most `_MAX_RULES` of them.
|
| 949 |
|
| 950 |
β AN OP OUTSIDE `SHEET_RULE_OPS` IS REFUSED BY NAME, for `_clean_format`'s reason: a rule
|
| 951 |
whose operator nothing can evaluate never fires, so dropping it would leave a person looking
|
| 952 |
+
at a sheet they believe is painted by a rule that is not there. A KIND outside
|
| 953 |
+
`SHEET_RULE_KINDS` is refused the same way, and for a sharper version of the same reason: a
|
| 954 |
+
dropped kind does not stop the rule firing, it makes it fire as a DIFFERENT paint.
|
| 955 |
+
|
| 956 |
+
ββ AND THIS IS THE D-640 SHAPE, SO READ IT BEFORE ADDING A FIELD. Each rule below is built
|
| 957 |
+
EXPLICITLY, key by key, which means a field the client starts writing and this function does
|
| 958 |
+
not learn is dropped on the very next read: the feature would delete itself one save later,
|
| 959 |
+
with the editor still listing what it wrote. W54-T05's `kind` and `scale` are here because
|
| 960 |
+
that ticket added them to both halves in one commit.
|
| 961 |
"""
|
| 962 |
if raw is None:
|
| 963 |
return []
|
|
|
|
| 972 |
raise SheetRefusal(
|
| 973 |
"sheet_rule_op_unknown",
|
| 974 |
"A sheet rule condition must be one of " + ", ".join(SHEET_RULE_OPS) + ".")
|
| 975 |
+
kind = _text(row.get("kind"), 20) or "cell"
|
| 976 |
+
if kind not in SHEET_RULE_KINDS:
|
| 977 |
+
raise SheetRefusal(
|
| 978 |
+
"sheet_rule_kind_unknown",
|
| 979 |
+
"A sheet rule kind must be one of " + ", ".join(SHEET_RULE_KINDS) + ".")
|
| 980 |
rect = _clean_range(row.get("range"))
|
| 981 |
if rect is None:
|
| 982 |
continue
|
| 983 |
rule = {"id": _text(row.get("id"), _MAX_ID) or uuid.uuid4().hex[:12],
|
| 984 |
"range": rect, "op": op, "style": _clean_rule_style(row.get("style"))}
|
| 985 |
+
#: β THE DEFAULT KIND IS AN ABSENCE (see `SHEET_RULE_KINDS`), so a rule that was turned
|
| 986 |
+
#: into a colour scale and back is byte for byte the rule it started as.
|
| 987 |
+
if kind != "cell":
|
| 988 |
+
rule["kind"] = kind
|
| 989 |
+
scale = _clean_rule_scale(row.get("scale"))
|
| 990 |
+
if scale:
|
| 991 |
+
rule["scale"] = scale
|
| 992 |
#: β `empty` and `notEmpty` take NO operand, and carrying one would store a rule whose
|
| 993 |
#: text says it compares against something it can never read.
|
| 994 |
if op not in ("empty", "notEmpty"):
|
|
|
|
| 1078 |
|
| 1079 |
β EVERY KEY THIS FUNCTION DOES NOT NAME IS DROPPED, and that is worth knowing before adding
|
| 1080 |
one: the return below is a fresh dict, not an amended copy of `raw`. A2's four geometry keys
|
| 1081 |
+
and C2's five strata are named for exactly that reason, and `charts` is named because it was
|
| 1082 |
+
the one this rule silently ate until W51-T21 (D-640).
|
| 1083 |
+
|
| 1084 |
+
ββ THE NAMES LIVE IN `SHEET_TAB_KEYS` AND THIS FUNCTION EMITS THROUGH IT, which is D-640
|
| 1085 |
+
closed rather than patched. Before wave 54 the set was implicit: it existed only as the
|
| 1086 |
+
literals typed into this body, so nothing stated it, nothing could gate it, and the only way
|
| 1087 |
+
to learn that a new slot was being eaten was to save a tab and reload it. Walking the tuple
|
| 1088 |
+
means a stratum computed here but missing from the tuple is never written, and
|
| 1089 |
+
`verify_sheet.py` reds when the two disagree, so the next slot cannot repeat the defect.
|
| 1090 |
"""
|
| 1091 |
if not isinstance(raw, dict):
|
| 1092 |
raise SheetRefusal("sheet_not_an_object", "A sheet must be an object.")
|
|
|
|
| 1102 |
#: silently un-described.
|
| 1103 |
sheet = {"id": sid, "name": name, "cols": cols, "rows": rows,
|
| 1104 |
"cells": _clean_cells(raw.get("cells"), sheet_name=name)}
|
| 1105 |
+
|
| 1106 |
+
#: β THE ORDER OF THIS DICT IS THE ORDER THE CLEANERS RUN IN, and it is load bearing: two of
|
| 1107 |
+
#: them REFUSE by name (`_clean_rules` on an unknown op, `_clean_imported` on a record that is
|
| 1108 |
+
#: not an object), so a reordering here would change which refusal a caller sees first when a
|
| 1109 |
+
#: tab is wrong in two places at once.
|
| 1110 |
+
optional = {
|
| 1111 |
+
"colWidths": _clean_col_widths(raw.get("colWidths"), cols),
|
| 1112 |
+
"freeze": _clean_freeze(raw.get("freeze"), cols, rows),
|
| 1113 |
+
"rules": _clean_rules(raw.get("rules")),
|
| 1114 |
+
"hiddenRows": _clean_hidden(raw.get("hiddenRows"), "rows"),
|
| 1115 |
+
"hiddenCols": _clean_hidden(raw.get("hiddenCols"), "columns"),
|
| 1116 |
+
"charts": _clean_charts(raw.get("charts")),
|
| 1117 |
+
"imported": _clean_imported(raw.get("imported")),
|
| 1118 |
+
}
|
| 1119 |
+
|
| 1120 |
+
#: β THE WALK IS THROUGH `SHEET_TAB_KEYS`, NOT THROUGH `optional`, AND THAT IS THE WHOLE
|
| 1121 |
+
#: POINT OF D-640'S FIX. A stratum cleaned above but never added to the tuple is dropped here
|
| 1122 |
+
#: rather than written, which is the same silent loss as before EXCEPT that the gate now sees
|
| 1123 |
+
#: it: `verify_sheet.py` drives a tab carrying every stratum and compares what comes back
|
| 1124 |
+
#: against the tuple, so the disagreement reds instead of shipping.
|
| 1125 |
+
#:
|
| 1126 |
+
#: Each is written only when it holds something, for `_clean_style`'s reason: a tab with no
|
| 1127 |
+
#: rules and a tab with `rules: []` read identically, so only one of them is stored and a
|
| 1128 |
+
#: reload compares equal to the thing it saved.
|
| 1129 |
+
for key in SHEET_TAB_KEYS:
|
| 1130 |
+
value = optional.get(key)
|
| 1131 |
+
if value:
|
| 1132 |
+
sheet[key] = value
|
| 1133 |
return sheet
|
| 1134 |
|
| 1135 |
|
platform/core/table_store.py
CHANGED
|
@@ -2133,6 +2133,34 @@ class TableStore:
|
|
| 2133 |
|
| 2134 |
self._update(username, _drop, shared=lambda shared_fields: shared_fields.pop(key, None))
|
| 2135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2136 |
def _tenant_wide_keys(self):
|
| 2137 |
"""The columns of THIS table whose values live in the tenant-wide stratum.
|
| 2138 |
|
|
@@ -2148,7 +2176,7 @@ class TableStore:
|
|
| 2148 |
"""
|
| 2149 |
try:
|
| 2150 |
import core.shared_overlay as shared_overlay
|
| 2151 |
-
return set(shared_overlay.fields(self.
|
| 2152 |
except Exception: # noqa: BLE001
|
| 2153 |
return set()
|
| 2154 |
|
|
@@ -2186,7 +2214,7 @@ class TableStore:
|
|
| 2186 |
# β `st=self._st`, NEVER the module default. The two strata must resolve to the SAME
|
| 2187 |
# tenant handle, or a value written by one is invisible to the other and the user's
|
| 2188 |
# edit vanishes the moment they save it (`_ProductTableStore` records the same rule).
|
| 2189 |
-
shared_overlay.put_cells(self.
|
| 2190 |
if not personal:
|
| 2191 |
return
|
| 2192 |
|
|
@@ -2223,7 +2251,7 @@ class TableStore:
|
|
| 2223 |
if shared:
|
| 2224 |
import core.shared_overlay as shared_overlay
|
| 2225 |
shared_overlay.put_cells_and_choice_options(
|
| 2226 |
-
self.
|
| 2227 |
|
| 2228 |
if not personal:
|
| 2229 |
return
|
|
|
|
| 2133 |
|
| 2134 |
self._update(username, _drop, shared=lambda shared_fields: shared_fields.pop(key, None))
|
| 2135 |
|
| 2136 |
+
def _shared_stratum_key(self):
|
| 2137 |
+
"""WHICH document holds this table's tenant-wide stratum β D-643.
|
| 2138 |
+
|
| 2139 |
+
ββ THE BUG THIS CLOSES, AND THE DIRECTION IT IS CLOSED IN. Every call below used to hand
|
| 2140 |
+
`self.table_key` straight to `core.shared_overlay`, whose `bucket()` appends `__shared`.
|
| 2141 |
+
For a user database that key is `ut_<x>_table_workspace`, so the three sites addressed
|
| 2142 |
+
`ut_<x>_table_workspace__shared` while the CREATE door
|
| 2143 |
+
(`core.grid_events._field_share_keys`, the authority) mints and every one of the seven
|
| 2144 |
+
readers reads the BARE `ut_<x>__shared`. `_tenant_wide_keys` therefore answered the empty
|
| 2145 |
+
set for every `ut_*` table that has a shared column, and `patch_overlay` routed a
|
| 2146 |
+
tenant-wide value into the caller's own per-user member.
|
| 2147 |
+
|
| 2148 |
+
β THIS IS THE OPPOSITE OF THE CHANGE WAVE 50 REFUSED, and the difference matters because
|
| 2149 |
+
the two look alike. Its lane D was asked to make `_field_storage_keys` resolve the
|
| 2150 |
+
WORKSPACE spelling, and refused: that would have pointed the share dialog at a bucket
|
| 2151 |
+
nothing writes and orphaned every `ut_*` shared column with every gate green
|
| 2152 |
+
([[the-ut-shared-bucket-is-bare-on-purpose]]). This aligns `TableStore` DOWN to the bare
|
| 2153 |
+
spelling the create door and the readers already use, which is the same rule stated once.
|
| 2154 |
+
|
| 2155 |
+
β ONLY THE `ut_` BRANCH MOVES. `product_table_workspace` and `customer_table_workspace`
|
| 2156 |
+
are correct exactly as they stand (a gate asserts them), so every other key is returned
|
| 2157 |
+
unchanged.
|
| 2158 |
+
"""
|
| 2159 |
+
raw = str(self.table_key or '')
|
| 2160 |
+
if raw.startswith('ut_') and raw.endswith('_table_workspace'):
|
| 2161 |
+
return raw[:-len('_table_workspace')]
|
| 2162 |
+
return raw
|
| 2163 |
+
|
| 2164 |
def _tenant_wide_keys(self):
|
| 2165 |
"""The columns of THIS table whose values live in the tenant-wide stratum.
|
| 2166 |
|
|
|
|
| 2176 |
"""
|
| 2177 |
try:
|
| 2178 |
import core.shared_overlay as shared_overlay
|
| 2179 |
+
return set(shared_overlay.fields(self._shared_stratum_key(), st=self._st) or ())
|
| 2180 |
except Exception: # noqa: BLE001
|
| 2181 |
return set()
|
| 2182 |
|
|
|
|
| 2214 |
# β `st=self._st`, NEVER the module default. The two strata must resolve to the SAME
|
| 2215 |
# tenant handle, or a value written by one is invisible to the other and the user's
|
| 2216 |
# edit vanishes the moment they save it (`_ProductTableStore` records the same rule).
|
| 2217 |
+
shared_overlay.put_cells(self._shared_stratum_key(), pid, shared, st=self._st)
|
| 2218 |
if not personal:
|
| 2219 |
return
|
| 2220 |
|
|
|
|
| 2251 |
if shared:
|
| 2252 |
import core.shared_overlay as shared_overlay
|
| 2253 |
shared_overlay.put_cells_and_choice_options(
|
| 2254 |
+
self._shared_stratum_key(), pid, shared, shared_additions, st=self._st)
|
| 2255 |
|
| 2256 |
if not personal:
|
| 2257 |
return
|
platform/harness/runtime.py
CHANGED
|
@@ -307,22 +307,40 @@ class TenantRuntime:
|
|
| 307 |
return self._store().delete_path(self.store_key(path_in_repo))
|
| 308 |
|
| 309 |
# ---------------------------------------------------------------- the Odoo source (R3)
|
| 310 |
-
def odoo_source(self):
|
| 311 |
"""THIS tenant's Odoo connector, or None β the keychain CUTOVER's resolution seam
|
| 312 |
(2026-08-04; `keychain.odoo_creds` was previously called by nothing but its test).
|
| 313 |
|
| 314 |
Resolution, fail-closed:
|
| 315 |
-
1.
|
| 316 |
-
|
| 317 |
-
|
|
|
|
|
|
|
| 318 |
3. anyone else β None. NEVER the environment: env is tenant #0's connection, and
|
| 319 |
handing it to another tenant is the leak this method exists to prevent.
|
| 320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
Rebuilt per call on purpose β `core.odoo` caches the CLIENT per (slug, creds
|
| 322 |
fingerprint), so this stays cheap while a rotated key reconnects on the next call."""
|
| 323 |
import core.keychain as keychain
|
|
|
|
| 324 |
try:
|
| 325 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
except Exception: # locked or unreadable keychain β fall through, fail closed
|
| 327 |
creds = None
|
| 328 |
if creds:
|
|
@@ -332,34 +350,49 @@ class TenantRuntime:
|
|
| 332 |
return OdooConnector(tenant_slug=self.key, creds=creds,
|
| 333 |
scope={"team_ids": list(bus.values()) or None,
|
| 334 |
"team_names": {v: k for k, v in bus.items()} or None})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
if self.key == "royal-imports":
|
| 336 |
return (getattr(self.tenant, "sources", {}) or {}).get("odoo")
|
| 337 |
return None
|
| 338 |
|
| 339 |
# ------------------------------------------------------- the connector PAUSE (D-10, wave 24)
|
| 340 |
-
def odoo_flag_key(self):
|
| 341 |
"""WHICH connector flag governs this tenant's Odoo β the key `connectors[<k>].paused`
|
| 342 |
is stored under, or None when nothing would serve.
|
| 343 |
|
| 344 |
THE SAME RESOLUTION AS `odoo_source()` ABOVE, expressed as an identity instead of a
|
| 345 |
-
client:
|
| 346 |
-
nothing. It lives here so there is ONE
|
| 347 |
-
was a second copy of these three rules in
|
| 348 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
"""
|
| 350 |
import core.keychain as keychain
|
|
|
|
| 351 |
try:
|
| 352 |
-
|
| 353 |
except Exception:
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
|
|
|
| 358 |
if self.key == "royal-imports" and os.environ.get("ODOO_URL"):
|
| 359 |
return ENV_ODOO_FLAG_KEY
|
| 360 |
return None
|
| 361 |
|
| 362 |
-
def odoo_paused(self):
|
| 363 |
"""Is THIS tenant's RESOLVED Odoo source paused?
|
| 364 |
|
| 365 |
β RESOLVED, not "any entry" β pausing an entry that is not the one serving freezes
|
|
@@ -367,9 +400,13 @@ class TenantRuntime:
|
|
| 367 |
False, because a store hiccup must not freeze a live surface. That policy is inherited
|
| 368 |
from the API-layer function this one replaced, deliberately, so there is one answer to
|
| 369 |
"what happens when we cannot tell" rather than two that can disagree.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
"""
|
| 371 |
try:
|
| 372 |
-
flag_key = self.odoo_flag_key()
|
| 373 |
if not flag_key:
|
| 374 |
return False
|
| 375 |
flags = self.get(CONNECTOR_FLAGS_KEY) or {}
|
|
|
|
| 307 |
return self._store().delete_path(self.store_key(path_in_repo))
|
| 308 |
|
| 309 |
# ---------------------------------------------------------------- the Odoo source (R3)
|
| 310 |
+
def odoo_source(self, connection_id=None):
|
| 311 |
"""THIS tenant's Odoo connector, or None β the keychain CUTOVER's resolution seam
|
| 312 |
(2026-08-04; `keychain.odoo_creds` was previously called by nothing but its test).
|
| 313 |
|
| 314 |
Resolution, fail-closed:
|
| 315 |
+
1. the keychain `odoo` connection NAMED by `connection_id` (W54-T45 / R4), or the
|
| 316 |
+
tenant's DESIGNATED DEFAULT connection when no id is named β a connector bound to
|
| 317 |
+
THOSE creds;
|
| 318 |
+
2. tenant #0 with an empty/locked keychain and NO id named β its compiled env
|
| 319 |
+
connector (R3's "live with env fallback", which keeps Royal working unchanged);
|
| 320 |
3. anyone else β None. NEVER the environment: env is tenant #0's connection, and
|
| 321 |
handing it to another tenant is the leak this method exists to prevent.
|
| 322 |
|
| 323 |
+
ββ W54-T45 β THE ENV FALLBACK NARROWS HERE AND MUST NEVER WIDEN. A caller that NAMES a
|
| 324 |
+
connection and gets nothing back is answered None, full stop: not the default connection,
|
| 325 |
+
not a sibling, and above all not tenant #0's `.env`. Under R4 an agency holds one Odoo
|
| 326 |
+
connection per client, and under R7 that isolation is strict β a named-but-unresolvable
|
| 327 |
+
connection quietly falling through to the environment would serve tenant #0's own Odoo to
|
| 328 |
+
a question asked about somebody else's books, with nothing red anywhere. Leg (2) is
|
| 329 |
+
reachable only on the UNNAMED path, which is exactly the pre-wave behaviour.
|
| 330 |
+
|
| 331 |
Rebuilt per call on purpose β `core.odoo` caches the CLIENT per (slug, creds
|
| 332 |
fingerprint), so this stays cheap while a rotated key reconnects on the next call."""
|
| 333 |
import core.keychain as keychain
|
| 334 |
+
named = connection_id is not None
|
| 335 |
try:
|
| 336 |
+
# β THE UNNAMED PATH IS SPELLED AS THE PRE-WAVE CALL, VERBATIM, and the branch is not
|
| 337 |
+
# decoration: `verify_api`'s R11 leg pins the literal `keychain.odoo_creds(self)` in
|
| 338 |
+
# this method's source as its proof that the resolver is KEYCHAIN-FIRST. Writing only
|
| 339 |
+
# the two-argument form would have turned that gate red for a reason that has nothing
|
| 340 |
+
# to do with the rule it guards, in a file this lane may not edit. The two arms are
|
| 341 |
+
# the same question; the left one is the one every existing caller asks.
|
| 342 |
+
creds = (keychain.odoo_creds(self) if not named
|
| 343 |
+
else keychain.odoo_creds(self, connection_id))
|
| 344 |
except Exception: # locked or unreadable keychain β fall through, fail closed
|
| 345 |
creds = None
|
| 346 |
if creds:
|
|
|
|
| 350 |
return OdooConnector(tenant_slug=self.key, creds=creds,
|
| 351 |
scope={"team_ids": list(bus.values()) or None,
|
| 352 |
"team_names": {v: k for k, v in bus.items()} or None})
|
| 353 |
+
# β THE NAMED LEG STOPS HERE. See the docstring: an explicit connection that did not
|
| 354 |
+
# resolve is None, never the environment and never another connection.
|
| 355 |
+
if named:
|
| 356 |
+
return None
|
| 357 |
if self.key == "royal-imports":
|
| 358 |
return (getattr(self.tenant, "sources", {}) or {}).get("odoo")
|
| 359 |
return None
|
| 360 |
|
| 361 |
# ------------------------------------------------------- the connector PAUSE (D-10, wave 24)
|
| 362 |
+
def odoo_flag_key(self, connection_id=None):
|
| 363 |
"""WHICH connector flag governs this tenant's Odoo β the key `connectors[<k>].paused`
|
| 364 |
is stored under, or None when nothing would serve.
|
| 365 |
|
| 366 |
THE SAME RESOLUTION AS `odoo_source()` ABOVE, expressed as an identity instead of a
|
| 367 |
+
client: the keychain `odoo` connection named (or the designated default when none is),
|
| 368 |
+
else tenant #0's compiled env source, else nothing. It lives here so there is ONE
|
| 369 |
+
resolver β `routes_keychain._resolved_odoo_key` was a second copy of these three rules in
|
| 370 |
+
the API layer, and a pause flag written against one resolution and read against the other
|
| 371 |
+
freezes nothing while reporting success.
|
| 372 |
+
|
| 373 |
+
ββ W54-T45 β AND THE INLINE WALK IS GONE, WHICH IS WHAT MADE THE SENTENCE ABOVE TRUE.
|
| 374 |
+
This method claimed to be the one resolver while carrying its own copy of "the first
|
| 375 |
+
`odoo` entry", so `keychain` and `runtime` each decided which connection serves. Both now
|
| 376 |
+
ask `keychain.resolve_connection_id`, which decrypts nothing β a pause flag has to resolve
|
| 377 |
+
on a LOCKED keychain, which is why this is an identity call and not a credential one.
|
| 378 |
+
β A NAMED CONNECTION THAT DOES NOT RESOLVE IS None, exactly as in `odoo_source`: pausing
|
| 379 |
+
by a connection id must never silently address tenant #0's environment source instead.
|
| 380 |
"""
|
| 381 |
import core.keychain as keychain
|
| 382 |
+
named = connection_id is not None
|
| 383 |
try:
|
| 384 |
+
resolved = keychain.resolve_connection_id(self, "odoo", connection_id)
|
| 385 |
except Exception:
|
| 386 |
+
resolved = None
|
| 387 |
+
if resolved and keychain.unlocked():
|
| 388 |
+
return resolved
|
| 389 |
+
if named:
|
| 390 |
+
return None
|
| 391 |
if self.key == "royal-imports" and os.environ.get("ODOO_URL"):
|
| 392 |
return ENV_ODOO_FLAG_KEY
|
| 393 |
return None
|
| 394 |
|
| 395 |
+
def odoo_paused(self, connection_id=None):
|
| 396 |
"""Is THIS tenant's RESOLVED Odoo source paused?
|
| 397 |
|
| 398 |
β RESOLVED, not "any entry" β pausing an entry that is not the one serving freezes
|
|
|
|
| 400 |
False, because a store hiccup must not freeze a live surface. That policy is inherited
|
| 401 |
from the API-layer function this one replaced, deliberately, so there is one answer to
|
| 402 |
"what happens when we cannot tell" rather than two that can disagree.
|
| 403 |
+
|
| 404 |
+
β W54-T45 β `connection_id` passes straight through to `odoo_flag_key`, so "is the
|
| 405 |
+
connection serving THIS client paused" is answerable per connection under R4. No id keeps
|
| 406 |
+
meaning the tenant's designated default, which is every existing caller.
|
| 407 |
"""
|
| 408 |
try:
|
| 409 |
+
flag_key = self.odoo_flag_key(connection_id)
|
| 410 |
if not flag_key:
|
| 411 |
return False
|
| 412 |
flags = self.get(CONNECTOR_FLAGS_KEY) or {}
|
platform/odoo_client.py
CHANGED
|
@@ -61,12 +61,28 @@ class OdooClient:
|
|
| 61 |
def __init__(self, creds=None):
|
| 62 |
"""`creds` (R3 keychain cutover): an explicit {url, db, user, api_key} dict β a TENANT'S
|
| 63 |
stored credentials β wins over the environment. None keeps the env/.env behavior every
|
| 64 |
-
existing caller relies on (tenant #0's connection).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
creds = creds or {}
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
missing = [k for k, v in [('ODOO_URL', self.url), ('ODOO_DB', self.db),
|
| 71 |
('ODOO_USER', self.user), ('ODOO_API_KEY', self.api_key)] if not v]
|
| 72 |
if missing:
|
|
|
|
| 61 |
def __init__(self, creds=None):
|
| 62 |
"""`creds` (R3 keychain cutover): an explicit {url, db, user, api_key} dict β a TENANT'S
|
| 63 |
stored credentials β wins over the environment. None keeps the env/.env behavior every
|
| 64 |
+
existing caller relies on (tenant #0's connection).
|
| 65 |
+
|
| 66 |
+
ββ W54-T45 / R7 β IT IS ALL-OR-NOTHING, AND THE PER-FIELD VERSION WAS A REAL LEAK SHAPE.
|
| 67 |
+
Each field used to read `creds.get(k) or os.environ.get(...)` INDIVIDUALLY, so an explicit
|
| 68 |
+
connection whose stored `db` was blank or missing silently inherited tenant #0's `ODOO_DB`
|
| 69 |
+
while keeping the caller's `url`, `user` and `api_key`. Under R4 an agency holds one Odoo
|
| 70 |
+
connection per client and under R7 that isolation is strict: a half-environment client is
|
| 71 |
+
one client's question authenticated against another's database, and it does not raise β
|
| 72 |
+
it returns real, plausible, wrong rows. So a supplied `creds` is used WHOLE, and a field
|
| 73 |
+
it is missing is MISSING (the `RuntimeError` below names it) rather than borrowed. With no
|
| 74 |
+
`creds` at all the environment builds the client exactly as it always did.
|
| 75 |
+
"""
|
| 76 |
+
from_env = creds is None
|
| 77 |
creds = creds or {}
|
| 78 |
+
|
| 79 |
+
def _f(key, env_key):
|
| 80 |
+
return str((os.environ.get(env_key, '') if from_env else creds.get(key)) or '')
|
| 81 |
+
|
| 82 |
+
self.url = _f('url', 'ODOO_URL').rstrip('/')
|
| 83 |
+
self.db = _f('db', 'ODOO_DB')
|
| 84 |
+
self.user = _f('user', 'ODOO_USER')
|
| 85 |
+
self.api_key = _f('api_key', 'ODOO_API_KEY')
|
| 86 |
missing = [k for k, v in [('ODOO_URL', self.url), ('ODOO_DB', self.db),
|
| 87 |
('ODOO_USER', self.user), ('ODOO_API_KEY', self.api_key)] if not v]
|
| 88 |
if missing:
|
web/src/connectors/ConnectorsPage.tsx
CHANGED
|
@@ -169,18 +169,16 @@ export interface ConnectorRow {
|
|
| 169 |
*/
|
| 170 |
scope?: string;
|
| 171 |
/**
|
| 172 |
-
*
|
| 173 |
-
*
|
| 174 |
-
* `
|
| 175 |
-
*
|
| 176 |
*
|
| 177 |
-
* β IT IS THE SOURCE'S RULE, NOT THIS READER'S PERMISSION
|
| 178 |
-
*
|
| 179 |
-
*
|
| 180 |
-
*
|
| 181 |
-
*
|
| 182 |
-
* ever NARROWS a tier, so a missing one leaves the page exactly as it was before this ticket
|
| 183 |
-
* rather than hiding a connection the reader really holds.
|
| 184 |
*/
|
| 185 |
allowedScopes?: string[];
|
| 186 |
/** What the admin will be asked for β shown where the decision is made, not in a tour. */
|
|
@@ -245,13 +243,14 @@ type Load =
|
|
| 245 |
gaps: ConnectorGap[];
|
| 246 |
/** W49-T18: the category rail, exactly as the server counted it. */
|
| 247 |
chips: DirectoryCategory[];
|
| 248 |
-
/*
|
| 249 |
-
*
|
| 250 |
-
*
|
| 251 |
-
*
|
| 252 |
-
*
|
|
|
|
|
|
|
| 253 |
*/
|
| 254 |
-
canBusiness: boolean;
|
| 255 |
}
|
| 256 |
| { phase: "error"; message: string };
|
| 257 |
|
|
@@ -353,11 +352,13 @@ export function parseDirectory(body: unknown): ConnectorRow[] {
|
|
| 353 |
...(str(c.startUrl) ? { startUrl: str(c.startUrl) } : {}),
|
| 354 |
...(str(c.note) ? { note: str(c.note) } : {}),
|
| 355 |
...(str(c.scope) ? { scope: str(c.scope) } : {}),
|
| 356 |
-
//
|
| 357 |
-
//
|
| 358 |
-
//
|
| 359 |
-
//
|
| 360 |
-
//
|
|
|
|
|
|
|
| 361 |
...(parseCategoryTags(c.allowedScopes).length
|
| 362 |
? { allowedScopes: parseCategoryTags(c.allowedScopes) }
|
| 363 |
: {}),
|
|
@@ -614,21 +615,17 @@ export default function ConnectorsPage({
|
|
| 614 |
* spends money is closed.
|
| 615 |
*/
|
| 616 |
const [canPull, setCanPull] = useState(false);
|
| 617 |
-
/*
|
| 618 |
-
*
|
| 619 |
-
*
|
| 620 |
-
*
|
| 621 |
-
*
|
| 622 |
-
* this ticket. `routes_keychain.py::SCOPES` already names these two ideas and every row on the
|
| 623 |
-
* wire is filed by them; a second client-only pair of words for the same split would be one
|
| 624 |
-
* rename away from a tier that filters on a word nothing sends. "Company" and "Mine" are the
|
| 625 |
-
* ruling's LABELS, which is a copy decision, and they live in the buttons below and nowhere
|
| 626 |
-
* else. Read as a string for the same reason `state` is (the wave-9 law).
|
| 627 |
*
|
| 628 |
-
* β
|
| 629 |
-
*
|
|
|
|
|
|
|
| 630 |
*/
|
| 631 |
-
const [scopeTier, setScopeTier] = useState("business");
|
| 632 |
|
| 633 |
useEffect(() => {
|
| 634 |
let dead = false;
|
|
@@ -638,7 +635,7 @@ export default function ConnectorsPage({
|
|
| 638 |
credentials: CREDENTIALS,
|
| 639 |
});
|
| 640 |
const body = (await res.json().catch(() => null)) as
|
| 641 |
-
| { error?: { message?: string }
|
| 642 |
| null;
|
| 643 |
if (dead) return;
|
| 644 |
if (!res.ok) {
|
|
@@ -653,11 +650,6 @@ export default function ConnectorsPage({
|
|
| 653 |
rows: parseDirectory(body),
|
| 654 |
gaps: parseGaps(body),
|
| 655 |
chips: parseCategories(body),
|
| 656 |
-
// ββ W53-T29 / R6 β a LITERAL `true` is permission and anything else is not. An older
|
| 657 |
-
// server sends nothing here and this reader gets no Company side, which is the safe way
|
| 658 |
-
// round: the toggle appearing for a member would be the ruling broken, while a missing
|
| 659 |
-
// toggle for an admin is a page that still lists every connection they have.
|
| 660 |
-
canBusiness: (body as { canBusiness?: unknown } | null)?.canBusiness === true,
|
| 661 |
});
|
| 662 |
} catch {
|
| 663 |
if (!dead) setLoad({ phase: "error", message: "Cannot reach the server." });
|
|
@@ -721,62 +713,21 @@ export default function ConnectorsPage({
|
|
| 721 |
const databaseRows = rows.filter((r) => r.spawns_tables === true);
|
| 722 |
const otherRows = rows.filter((r) => r.spawns_tables !== true);
|
| 723 |
/**
|
| 724 |
-
* ββ
|
| 725 |
*
|
| 726 |
-
*
|
| 727 |
-
*
|
| 728 |
-
*
|
| 729 |
-
*
|
| 730 |
-
* card is the company's.
|
| 731 |
*
|
| 732 |
-
* β ONLY A CONNECTED CARD IS
|
| 733 |
-
* connection yet, so
|
| 734 |
-
*
|
| 735 |
*
|
| 736 |
-
* β
|
| 737 |
-
*
|
| 738 |
-
* the connection. A connected Odoo row therefore belongs to "Databases" above AND to "Connected
|
| 739 |
-
* for the company" here, because the two headings answer different questions about it.
|
| 740 |
*/
|
| 741 |
const connectedRows = rows.filter((r) => r.state === "connected");
|
| 742 |
-
/**
|
| 743 |
-
* ββ W53-T29 Β· OWNER RULING R6 β TWO QUESTIONS PER CARD, AND BOTH ARE ASKED.
|
| 744 |
-
*
|
| 745 |
-
* `row.scope` is what this connection WAS STORED AS; `row.allowedScopes` is what its SOURCE may
|
| 746 |
-
* ever be (`routes_keychain.allowed_scopes`, derived from the same `TENANT_WIDE_TYPES` tuple the
|
| 747 |
-
* server's refusals are derived from). A tier needs both: without the second, one stray or
|
| 748 |
-
* legacy `scope` value would put Odoo under Mine, and Odoo is the credential this whole
|
| 749 |
-
* workspace's databases are read through.
|
| 750 |
-
*
|
| 751 |
-
* β IT ONLY EVER NARROWS. A row that carries no `allowedScopes` (an older server) is treated as
|
| 752 |
-
* unrestricted, so the worst an absent declaration can do is leave the page as it was.
|
| 753 |
-
*/
|
| 754 |
-
const eligible = (row: ConnectorRow, scope: string) =>
|
| 755 |
-
!row.allowedScopes || row.allowedScopes.includes(scope);
|
| 756 |
-
const companyRows = connectedRows.filter(
|
| 757 |
-
(r) => r.scope !== "personal" && eligible(r, "business"),
|
| 758 |
-
);
|
| 759 |
-
const personalRows = connectedRows.filter(
|
| 760 |
-
(r) => r.scope === "personal" && eligible(r, "personal"),
|
| 761 |
-
);
|
| 762 |
-
/**
|
| 763 |
-
* ββ W53-T29 Β· OWNER RULING R6 β THE NON-ADMIN CASE IS STRUCTURAL, NOT A HIDDEN BUTTON.
|
| 764 |
-
*
|
| 765 |
-
* R6, verbatim: *"A non-admin does not see the Company side at all; the toggle itself is hidden
|
| 766 |
-
* for them."* So `showCompany` cannot be reached without `canBusiness` and `showPersonal` is
|
| 767 |
-
* unconditionally true without it: a member sees their own connections and no toggle, and no
|
| 768 |
-
* sequence of clicks, stale state or hot reload can produce a Company section for them, because
|
| 769 |
-
* there is no state in which one renders. Hiding a control is not a permission check, which is
|
| 770 |
-
* why the SERVER refuses a member's business-scoped create as well
|
| 771 |
-
* (`routes_keychain.add_key` -> 403 `not_admin`).
|
| 772 |
-
*
|
| 773 |
-
* β THE TOGGLE NEEDS SOMETHING TO TOGGLE. With no connected card at all it renders nothing
|
| 774 |
-
* rather than two chips over an empty page, the same rule the tier headings already keep.
|
| 775 |
-
*/
|
| 776 |
-
const canBusiness = load.phase === "ready" && load.canBusiness;
|
| 777 |
-
const showCompany = canBusiness && scopeTier !== "personal";
|
| 778 |
-
const showPersonal = !canBusiness || scopeTier === "personal";
|
| 779 |
-
const showScopeToggle = canBusiness && connectedRows.length > 0;
|
| 780 |
// β Resolved against `allRows`, not the filtered list: typing in the search box while a modal is
|
| 781 |
// open must not close the modal out from under the reader.
|
| 782 |
const openRow = allRows.find((row) => row.key === openKey);
|
|
@@ -853,93 +804,29 @@ export default function ConnectorsPage({
|
|
| 853 |
) : null}
|
| 854 |
|
| 855 |
{/*
|
| 856 |
-
ββ
|
| 857 |
|
| 858 |
-
β
|
| 859 |
-
one
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
they map is different, so a connector's card behaves exactly as it did before this ticket
|
| 865 |
-
wherever it lands.
|
| 866 |
-
*/}
|
| 867 |
-
{/*
|
| 868 |
-
ββ W52-T02 Β· RULING R2 / CONTRACT C2 β THE TWO OWNERSHIP SECTIONS.
|
| 869 |
|
| 870 |
-
β
|
| 871 |
-
|
| 872 |
-
|
| 873 |
|
| 874 |
-
β SAME `ConnectorCard`, NOT A FORK
|
| 875 |
-
|
| 876 |
*/}
|
| 877 |
-
{
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
`is-on`, styled in `styles/wave49/connectors.css`). DESIGN.md Β§4: a filter rail keeps one
|
| 882 |
-
control shape, and this ticket ships no stylesheet, so a class invented here would render
|
| 883 |
-
as unstyled native chrome.
|
| 884 |
-
β REAL BUTTONS, NOT A DIV. `aria-pressed` carries the selected state to a screen reader
|
| 885 |
-
and `type="button"` keeps it off any form; the visible word IS the accessible name, which
|
| 886 |
-
is why neither carries an `aria-label` that would say something else.
|
| 887 |
-
*/}
|
| 888 |
-
{showScopeToggle ? (
|
| 889 |
-
<div className="conn-chips" role="group" aria-label="Which connections to show">
|
| 890 |
-
<button
|
| 891 |
-
type="button"
|
| 892 |
-
className={"conn-chip" + (showCompany ? " is-on" : "")}
|
| 893 |
-
aria-pressed={showCompany}
|
| 894 |
-
onClick={() => setScopeTier("business")}
|
| 895 |
-
>
|
| 896 |
-
<span className="conn-chip-name">Company</span>
|
| 897 |
-
</button>
|
| 898 |
-
<button
|
| 899 |
-
type="button"
|
| 900 |
-
className={"conn-chip" + (showCompany ? "" : " is-on")}
|
| 901 |
-
aria-pressed={!showCompany}
|
| 902 |
-
onClick={() => setScopeTier("personal")}
|
| 903 |
-
>
|
| 904 |
-
<span className="conn-chip-name">Mine</span>
|
| 905 |
-
</button>
|
| 906 |
-
</div>
|
| 907 |
-
) : null}
|
| 908 |
-
{/* ONE line and the way out, the same shape the empty grid above already uses: a side of
|
| 909 |
-
the toggle with nothing on it must say so, or the reader reads the silence as a page
|
| 910 |
-
that failed to load. */}
|
| 911 |
-
{showScopeToggle && (showCompany ? companyRows.length === 0 : personalRows.length === 0) ? (
|
| 912 |
-
<p className="conn-note">
|
| 913 |
-
{showCompany
|
| 914 |
-
? "No connection is shared with the whole company yet."
|
| 915 |
-
: "You have no personal connections yet."}
|
| 916 |
-
</p>
|
| 917 |
-
) : null}
|
| 918 |
-
{showCompany && companyRows.length > 0 ? (
|
| 919 |
-
<section className="conn-tier" aria-labelledby="conn-tier-company-heading">
|
| 920 |
-
<h2 id="conn-tier-company-heading" className="conn-tier-heading">
|
| 921 |
-
Connected for the company
|
| 922 |
-
</h2>
|
| 923 |
-
<div className="conn-grid">
|
| 924 |
-
{companyRows.map((row) => (
|
| 925 |
-
<ConnectorCard
|
| 926 |
-
key={row.key}
|
| 927 |
-
row={row}
|
| 928 |
-
onKeychain={onKeychain}
|
| 929 |
-
onOpen={() => setOpenKey(row.key)}
|
| 930 |
-
onPullReviews={pullHandler(row)}
|
| 931 |
-
/>
|
| 932 |
-
))}
|
| 933 |
-
</div>
|
| 934 |
-
</section>
|
| 935 |
-
) : null}
|
| 936 |
-
{showPersonal && personalRows.length > 0 ? (
|
| 937 |
-
<section className="conn-tier" aria-labelledby="conn-tier-personal-heading">
|
| 938 |
-
<h2 id="conn-tier-personal-heading" className="conn-tier-heading">
|
| 939 |
-
Connected by you
|
| 940 |
</h2>
|
| 941 |
<div className="conn-grid">
|
| 942 |
-
{
|
| 943 |
<ConnectorCard
|
| 944 |
key={row.key}
|
| 945 |
row={row}
|
|
@@ -951,6 +838,18 @@ export default function ConnectorsPage({
|
|
| 951 |
</div>
|
| 952 |
</section>
|
| 953 |
) : null}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 954 |
{databaseRows.length > 0 ? (
|
| 955 |
<section className="conn-tier" aria-labelledby="conn-tier-databases-heading">
|
| 956 |
<h2 id="conn-tier-databases-heading" className="conn-tier-heading">
|
|
|
|
| 169 |
*/
|
| 170 |
scope?: string;
|
| 171 |
/**
|
| 172 |
+
* WHICH SCOPES THIS SOURCE MAY EVER CARRY, e.g. `["business"]` for Odoo and both words for
|
| 173 |
+
* Gmail. The server's one declaration of it is `routes_keychain.allowed_scopes`, built on the
|
| 174 |
+
* same `TENANT_WIDE_TYPES` tuple its refusals are built on, and every directory row is stamped
|
| 175 |
+
* with it.
|
| 176 |
*
|
| 177 |
+
* β IT IS THE SOURCE'S RULE, NOT THIS READER'S PERMISSION, and since WAVE 54 Β· RULING R4 no
|
| 178 |
+
* section on this page branches on it: the Company / Mine toggle that read it is withdrawn.
|
| 179 |
+
* The field is still read off the wire because the server still declares it and the keychain
|
| 180 |
+
* surface in Settings still decides a scope with it. This page lists connections; it no longer
|
| 181 |
+
* sorts them by who they belong to.
|
|
|
|
|
|
|
| 182 |
*/
|
| 183 |
allowedScopes?: string[];
|
| 184 |
/** What the admin will be asked for β shown where the decision is made, not in a tour. */
|
|
|
|
| 243 |
gaps: ConnectorGap[];
|
| 244 |
/** W49-T18: the category rail, exactly as the server counted it. */
|
| 245 |
chips: DirectoryCategory[];
|
| 246 |
+
/*
|
| 247 |
+
* ββ THE ADMIN PERMISSION FLAG STOOD HERE AND IS DELETED BY W54-T42 Β· RULING R4
|
| 248 |
+
* (2026-09-06). It was the field the Company / Mine toggle branched on, and the toggle is
|
| 249 |
+
* withdrawn, so a permission this page reads and never uses would be one edit away from
|
| 250 |
+
* reviving a wall the owner removed. The server still sends it on the directory payload and
|
| 251 |
+
* `settings/SettingsModal.tsx` still reads it where a scope is actually chosen; what is gone
|
| 252 |
+
* is this page's copy, and the gate scan in `verify_schema_overlay.py` keeps it gone.
|
| 253 |
*/
|
|
|
|
| 254 |
}
|
| 255 |
| { phase: "error"; message: string };
|
| 256 |
|
|
|
|
| 352 |
...(str(c.startUrl) ? { startUrl: str(c.startUrl) } : {}),
|
| 353 |
...(str(c.note) ? { note: str(c.note) } : {}),
|
| 354 |
...(str(c.scope) ? { scope: str(c.scope) } : {}),
|
| 355 |
+
// The source's declared eligibility, COPIED off the wire like every other field here.
|
| 356 |
+
// `parseCategoryTags` is this file's one reader for a list of words from the server
|
| 357 |
+
// (strings only, blanks dropped, deduped); a second identical parser would be a second
|
| 358 |
+
// place for "read a string list" to go wrong. An empty or absent list yields no key at all.
|
| 359 |
+
// β W54-T42 Β· R4 β nothing on this page FILTERS on it any more; the tiers that did are
|
| 360 |
+
// withdrawn. It is kept because the server declares it on every row and the keychain
|
| 361 |
+
// surface in Settings still decides a scope with it.
|
| 362 |
...(parseCategoryTags(c.allowedScopes).length
|
| 363 |
? { allowedScopes: parseCategoryTags(c.allowedScopes) }
|
| 364 |
: {}),
|
|
|
|
| 615 |
* spends money is closed.
|
| 616 |
*/
|
| 617 |
const [canPull, setCanPull] = useState(false);
|
| 618 |
+
/*
|
| 619 |
+
* ββ THE COMPANY / MINE TOGGLE STOOD HERE AND IS WITHDRAWN BY W54-T42 Β· OWNER RULING R4
|
| 620 |
+
* (2026-09-06). Its state, its two chips, its permission read and the two connected tiers it
|
| 621 |
+
* partitioned are all deleted: one flat "Connected" section now lists every connected card, so
|
| 622 |
+
* a member reaches the same connections an admin does.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 623 |
*
|
| 624 |
+
* β THE SERVER'S REFUSAL IS DELIBERATELY UNTOUCHED. R4 replaces WHO may add a connector with a
|
| 625 |
+
* per-user grant on a third axis (Database, Module, Connector), which is a separate ticket's
|
| 626 |
+
* work; until that lands, `routes_keychain` still refuses a member's company-wide create and a
|
| 627 |
+
* personal scope on a tenant-wide source. Withdrawing a control is not opening a door.
|
| 628 |
*/
|
|
|
|
| 629 |
|
| 630 |
useEffect(() => {
|
| 631 |
let dead = false;
|
|
|
|
| 635 |
credentials: CREDENTIALS,
|
| 636 |
});
|
| 637 |
const body = (await res.json().catch(() => null)) as
|
| 638 |
+
| { error?: { message?: string } }
|
| 639 |
| null;
|
| 640 |
if (dead) return;
|
| 641 |
if (!res.ok) {
|
|
|
|
| 650 |
rows: parseDirectory(body),
|
| 651 |
gaps: parseGaps(body),
|
| 652 |
chips: parseCategories(body),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 653 |
});
|
| 654 |
} catch {
|
| 655 |
if (!dead) setLoad({ phase: "error", message: "Cannot reach the server." });
|
|
|
|
| 713 |
const databaseRows = rows.filter((r) => r.spawns_tables === true);
|
| 714 |
const otherRows = rows.filter((r) => r.spawns_tables !== true);
|
| 715 |
/**
|
| 716 |
+
* ββ W54-T42 Β· OWNER RULING R4 β EVERY CONNECTED CARD, IN ONE SECTION.
|
| 717 |
*
|
| 718 |
+
* R4 withdrew the Company / Mine toggle and the company-wide tier beside it, so who a
|
| 719 |
+
* connection belongs to is no longer a question this page asks. What is left is the one honest
|
| 720 |
+
* statement: these are the sources this workspace is connected to. Access is granted per user
|
| 721 |
+
* on a third axis instead (Database, Module, Connector), which lives in Settings.
|
|
|
|
| 722 |
*
|
| 723 |
+
* β ONLY A CONNECTED CARD IS LIFTED HERE. An `available`/`planned`/`catalogue` row is not a
|
| 724 |
+
* connection yet, so putting it under "Connected" would claim one this workspace does not have;
|
| 725 |
+
* it keeps its one home in the Databases / Other sources catalog below.
|
| 726 |
*
|
| 727 |
+
* β A CONNECTED ODOO ROW APPEARS HERE AND UNDER "Databases", deliberately: R1's tiering asks
|
| 728 |
+
* whether a card spawns tables, and this heading answers a different question about it.
|
|
|
|
|
|
|
| 729 |
*/
|
| 730 |
const connectedRows = rows.filter((r) => r.state === "connected");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 731 |
// β Resolved against `allRows`, not the filtered list: typing in the search box while a modal is
|
| 732 |
// open must not close the modal out from under the reader.
|
| 733 |
const openRow = allRows.find((row) => row.key === openKey);
|
|
|
|
| 804 |
) : null}
|
| 805 |
|
| 806 |
{/*
|
| 807 |
+
ββ W54-T42 Β· OWNER RULING R4 β ONE SECTION FOR EVERY CONNECTED CARD.
|
| 808 |
|
| 809 |
+
β WHAT STOOD HERE WAS THE COMPANY / MINE TOGGLE AND THE TWO OWNERSHIP TIERS UNDER IT,
|
| 810 |
+
one headed for the whole company and one for the reader's own connections, built by
|
| 811 |
+
W53-T29 ten days earlier. R4 withdraws the whole split: a workspace's connections are one
|
| 812 |
+
list, and access is granted per user on a third axis (Database, Module, Connector) from
|
| 813 |
+
Settings rather than by a scope wall on this page. Leaving only the personal tier would
|
| 814 |
+
have kept the other half of the same wall, so both went and this replaced them.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 815 |
|
| 816 |
+
β IT RENDERS ONLY WHEN IT HOLDS A CARD, the same rule the Databases / Other sources pair
|
| 817 |
+
below already keeps: a chip or a search term that empties it must not leave a heading
|
| 818 |
+
standing over nothing.
|
| 819 |
|
| 820 |
+
β SAME `ConnectorCard`, NOT A FORK, and the same classes: no new control shape and no new
|
| 821 |
+
stylesheet, which is what keeps the page's rhythm exactly as it was minus a chip row.
|
| 822 |
*/}
|
| 823 |
+
{connectedRows.length > 0 ? (
|
| 824 |
+
<section className="conn-tier" aria-labelledby="conn-tier-connected-heading">
|
| 825 |
+
<h2 id="conn-tier-connected-heading" className="conn-tier-heading">
|
| 826 |
+
Connected
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 827 |
</h2>
|
| 828 |
<div className="conn-grid">
|
| 829 |
+
{connectedRows.map((row) => (
|
| 830 |
<ConnectorCard
|
| 831 |
key={row.key}
|
| 832 |
row={row}
|
|
|
|
| 838 |
</div>
|
| 839 |
</section>
|
| 840 |
) : null}
|
| 841 |
+
{/*
|
| 842 |
+
ββ W52-T01 Β· RULING R1 / CONTRACT C1 β THE TWO HEADED CATALOG SECTIONS.
|
| 843 |
+
|
| 844 |
+
β EACH SECTION RENDERS ONLY WHEN IT HOLDS A CARD. A chip or a search term that empties
|
| 845 |
+
one tier must not leave a heading standing over nothing β `rows.length === 0` above
|
| 846 |
+
already covers "neither tier has anything", so this is the one-tier-emptied case one
|
| 847 |
+
interaction later, and the same honesty rule the empty-state message already keeps.
|
| 848 |
+
|
| 849 |
+
β SAME `ConnectorCard`, NOT A FORK. Both loops pass the identical props; only which array
|
| 850 |
+
they map is different, so a connector's card behaves exactly as it did before this ticket
|
| 851 |
+
wherever it lands.
|
| 852 |
+
*/}
|
| 853 |
{databaseRows.length > 0 ? (
|
| 854 |
<section className="conn-tier" aria-labelledby="conn-tier-databases-heading">
|
| 855 |
<h2 id="conn-tier-databases-heading" className="conn-tier-heading">
|
web/src/customer-grid/CustomerGrid.tsx
CHANGED
|
@@ -100,6 +100,8 @@ import { DatePicker } from "./DatePicker";
|
|
| 100 |
* shapes for one act is what R6 retires; the manager's copy is another lane's fence.
|
| 101 |
*/
|
| 102 |
import { ConfirmDialog, DialogToggle } from "../ui/ConfirmDialog";
|
|
|
|
|
|
|
| 103 |
// W49-T17: R32's pre-delete disclosure. A static import is safe here -- nothing else in the
|
| 104 |
// tree imports this component, so it joins THIS chunk rather than pinning another one open
|
| 105 |
// [[tsc-cannot-see-a-broken-code-split]].
|
|
@@ -3390,6 +3392,23 @@ function CustomerGridSurface({
|
|
| 3390 |
const displaySpec = resolvedDisplaySpec;
|
| 3391 |
const displayMode: DisplayMode = serverWindowed ? "grid" : displaySpec?.mode ?? "grid";
|
| 3392 |
const [routePanelOpen, setRoutePanelOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3393 |
useEffect(() => {
|
| 3394 |
const openRoute = (event: Event) => {
|
| 3395 |
const detail = (event as CustomEvent<{ routeId?: string; forwarded?: boolean }>).detail;
|
|
|
|
| 100 |
* shapes for one act is what R6 retires; the manager's copy is another lane's fence.
|
| 101 |
*/
|
| 102 |
import { ConfirmDialog, DialogToggle } from "../ui/ConfirmDialog";
|
| 103 |
+
// D-673 / W54-T21 - the one Escape arbiter, for the route navigator's own close.
|
| 104 |
+
import { useEscapeClose } from "../ui/useEscapeClose";
|
| 105 |
// W49-T17: R32's pre-delete disclosure. A static import is safe here -- nothing else in the
|
| 106 |
// tree imports this component, so it joins THIS chunk rather than pinning another one open
|
| 107 |
// [[tsc-cannot-see-a-broken-code-split]].
|
|
|
|
| 3392 |
const displaySpec = resolvedDisplaySpec;
|
| 3393 |
const displayMode: DisplayMode = serverWindowed ? "grid" : displaySpec?.mode ?? "grid";
|
| 3394 |
const [routePanelOpen, setRoutePanelOpen] = useState(false);
|
| 3395 |
+
/**
|
| 3396 |
+
* ββ D-673 / W54-T21 β THE TOP RUNG OF THE MAP'S ESCAPE LADDER, AND IT HAS TO BE HERE.
|
| 3397 |
+
*
|
| 3398 |
+
* W51-T28 built the rungs it could reach from lane G's fence: the kit dialog, then the open
|
| 3399 |
+
* Route, then the Zone editor and the Zone chooser. The route NAVIGATOR itself stayed
|
| 3400 |
+
* undismissable, and the register row says exactly why: `routePanelOpen` is this component's
|
| 3401 |
+
* own `useState`, handed to `MapView` as a read-only prop with no close callback, so no file
|
| 3402 |
+
* downstream can reach it. Threading a callback through `MapView.tsx` would touch three files
|
| 3403 |
+
* to arrive at this one line.
|
| 3404 |
+
*
|
| 3405 |
+
* β AND IT IS THE BOTTOM OF THE STACK, NOT A PRIORITY OF ITS OWN. The claim is pushed when the
|
| 3406 |
+
* panel opens, so everything opened INSIDE it - a row menu, the create menu, an open Route, a
|
| 3407 |
+
* rename, the delete confirm, the search query - registers later and is therefore topmost. One
|
| 3408 |
+
* press resolves to the innermost live surface and stops there; only when nothing is left above
|
| 3409 |
+
* it does Escape close the navigator.
|
| 3410 |
+
*/
|
| 3411 |
+
useEscapeClose(routePanelOpen, () => setRoutePanelOpen(false));
|
| 3412 |
useEffect(() => {
|
| 3413 |
const openRoute = (event: Event) => {
|
| 3414 |
const detail = (event as CustomEvent<{ routeId?: string; forwarded?: boolean }>).detail;
|
web/src/customer-grid/RecordDetail.css
CHANGED
|
@@ -852,6 +852,53 @@
|
|
| 852 |
white-space: nowrap;
|
| 853 |
}
|
| 854 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 855 |
.cg-record-insights {
|
| 856 |
padding: 12px 16px 24px;
|
| 857 |
}
|
|
@@ -1305,3 +1352,115 @@
|
|
| 1305 |
margin-left: auto;
|
| 1306 |
margin-right: 6px;
|
| 1307 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 852 |
white-space: nowrap;
|
| 853 |
}
|
| 854 |
|
| 855 |
+
/* ββ W54-T39 (instruction 22) β THE RAIL WHILE `/related` IS IN FLIGHT.
|
| 856 |
+
The listing is roughly four times faster now, so most readers never see this; the ones on a
|
| 857 |
+
cold compute or a slow link do, and what they saw before was `Details` alone with no sign that
|
| 858 |
+
anything else was coming (`waves/wave54/shots/F-before-record.png`).
|
| 859 |
+
|
| 860 |
+
β NO SHIMMER AND NO SPIN, and this is the app's existing decision rather than a new one:
|
| 861 |
+
`shell/navExtras.css`'s `.shell-rail-skeleton-bar` states it in full β an animated sweep is a
|
| 862 |
+
second thing moving in a rail whose whole complaint is movement, and `prefers-reduced-motion`
|
| 863 |
+
would then need a third state. One flat tone at the same `--lp-surface-2` that rail uses. There
|
| 864 |
+
is no animation here for a reduced-motion query to have to undo.
|
| 865 |
+
β THE ROW GEOMETRY IS `.cg-record-rail-row`'S OWN, inherited rather than restated, so the
|
| 866 |
+
placeholder occupies exactly the height a real row will and nothing shifts when the listing
|
| 867 |
+
lands. Only `cursor` and the pointer wall are overridden; DESIGN section 4 asks a new nav
|
| 868 |
+
element to join the existing rhythm rather than introduce a shape. */
|
| 869 |
+
.cg-record-rail-row.is-skeleton {
|
| 870 |
+
cursor: default;
|
| 871 |
+
pointer-events: none;
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
/* Sized to read as a name that has not arrived: the same 9 px bar height and 4 px radius the page
|
| 875 |
+
rail's skeleton uses, at a width that sits under `.cg-record-rail-row-label`'s single line. */
|
| 876 |
+
.cg-record-rail-skeleton-bar {
|
| 877 |
+
width: 78%;
|
| 878 |
+
max-width: 108px;
|
| 879 |
+
height: 9px;
|
| 880 |
+
margin: 3px 0;
|
| 881 |
+
border-radius: 4px;
|
| 882 |
+
background: var(--lp-surface-2);
|
| 883 |
+
}
|
| 884 |
+
|
| 885 |
+
/* The SUBTITLE's stand-in: shorter and quieter, because that is what the second line of a real
|
| 886 |
+
row is. Together the pair occupies the two-line height 24 of the 25 real edges settle at, so
|
| 887 |
+
the rail does not step when the listing lands. */
|
| 888 |
+
.cg-record-rail-skeleton-bar.is-sub {
|
| 889 |
+
width: 58%;
|
| 890 |
+
max-width: 82px;
|
| 891 |
+
height: 7px;
|
| 892 |
+
opacity: 0.6;
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
/* Folded, the real rows show no labels at all, so the placeholders drop their bars for the same
|
| 896 |
+
reason `.shell-side.is-collapsed .shell-rail-skeleton-bar` does: otherwise the fold runs
|
| 897 |
+
against a width the settled rail never has. */
|
| 898 |
+
.cg-views.is-collapsed .cg-record-rail-skeleton-bar {
|
| 899 |
+
display: none;
|
| 900 |
+
}
|
| 901 |
+
|
| 902 |
.cg-record-insights {
|
| 903 |
padding: 12px 16px 24px;
|
| 904 |
}
|
|
|
|
| 1352 |
margin-left: auto;
|
| 1353 |
margin-right: 6px;
|
| 1354 |
}
|
| 1355 |
+
|
| 1356 |
+
/* ββ W54-T38 (instruction 22, contract C5, DESIGN.md section 4) β A REFUSAL IS ONE SENTENCE,
|
| 1357 |
+
AND ITS DIAGNOSIS IS ONE CLICK DOWN.
|
| 1358 |
+
|
| 1359 |
+
The owner was shown a sixty-word paragraph four times over on one record. W54-T37 fixed the
|
| 1360 |
+
CAUSE and left the presentation, which is the other half of what he reported: section 4 says
|
| 1361 |
+
"never over-explain", and the block sat ABOVE the grid, so a tab's own rows started below the
|
| 1362 |
+
fold. The markup fix is in `RecordDetail.tsx` (the strip moved under the grid and each refusal
|
| 1363 |
+
became a `<details>`); these rules are what make it read as one quiet line.
|
| 1364 |
+
|
| 1365 |
+
β WHY THIS FILE AND NOT `index.css`. This ticket owns `RecordDetail.css` and does not own
|
| 1366 |
+
`index.css`, where the one existing disclosure-over-a-refusal (`.cg-ts-refused`) lives. These
|
| 1367 |
+
rules FOLLOW that precedent deliberately, down to both of its scars, rather than reaching for
|
| 1368 |
+
its classes: a shared class would put this surface's layout inside a stylesheet that another
|
| 1369 |
+
lane owns.
|
| 1370 |
+
|
| 1371 |
+
ββ SCAR 1, INHERITED FROM `.cg-ts-refsum`: THE CARET IS DRAWN WITH BORDERS. A triangle glyph
|
| 1372 |
+
renders at a different size in every font on the three platforms this runs on, and this one has
|
| 1373 |
+
to sit on a line of 12px text. It is also not an icon, which matters twice over: this ticket may
|
| 1374 |
+
not extend `iconShapes.ts`.
|
| 1375 |
+
ββ SCAR 2, AND IT SHIPPED ONCE AND WAS CAUGHT ONLY BY A SCREENSHOT: THE CLOSED STATE IS
|
| 1376 |
+
DECLARED. `<details>` hides its non-summary children through a UA rule, and ANY author `display`
|
| 1377 |
+
beats a UA declaration regardless of specificity, so `.cg-refusal-why { display: block }` alone
|
| 1378 |
+
would re-show the whole wall behind a summary claiming to hide it. Both states are stated. */
|
| 1379 |
+
.cg-refusal-strip {
|
| 1380 |
+
flex: 0 0 auto;
|
| 1381 |
+
display: flex;
|
| 1382 |
+
flex-direction: column;
|
| 1383 |
+
gap: 2px;
|
| 1384 |
+
padding: 10px 16px 12px;
|
| 1385 |
+
border-top: 1px solid var(--lp-line);
|
| 1386 |
+
}
|
| 1387 |
+
|
| 1388 |
+
.cg-refusal-sum {
|
| 1389 |
+
display: flex;
|
| 1390 |
+
align-items: baseline;
|
| 1391 |
+
gap: 6px;
|
| 1392 |
+
padding: 2px 0;
|
| 1393 |
+
color: var(--lp-muted);
|
| 1394 |
+
font-size: var(--lp-fs-2xs);
|
| 1395 |
+
line-height: 1.45;
|
| 1396 |
+
cursor: pointer;
|
| 1397 |
+
list-style: none; /* Safari and Chrome draw their own triangle; replaced below */
|
| 1398 |
+
user-select: none;
|
| 1399 |
+
}
|
| 1400 |
+
|
| 1401 |
+
.cg-refusal-sum::-webkit-details-marker {
|
| 1402 |
+
display: none;
|
| 1403 |
+
}
|
| 1404 |
+
|
| 1405 |
+
.cg-refusal-sum::before {
|
| 1406 |
+
content: "";
|
| 1407 |
+
flex: 0 0 auto;
|
| 1408 |
+
align-self: center;
|
| 1409 |
+
width: 0;
|
| 1410 |
+
height: 0;
|
| 1411 |
+
border-left: 4px solid currentColor;
|
| 1412 |
+
border-top: 3.5px solid transparent;
|
| 1413 |
+
border-bottom: 3.5px solid transparent;
|
| 1414 |
+
transition: transform 120ms ease-out;
|
| 1415 |
+
}
|
| 1416 |
+
|
| 1417 |
+
.cg-refusal[open] > .cg-refusal-sum::before {
|
| 1418 |
+
transform: rotate(90deg);
|
| 1419 |
+
}
|
| 1420 |
+
|
| 1421 |
+
.cg-refusal-sum:hover {
|
| 1422 |
+
color: var(--lp-ink);
|
| 1423 |
+
}
|
| 1424 |
+
|
| 1425 |
+
.cg-refusal-sum:focus-visible {
|
| 1426 |
+
outline: 2px solid var(--lp-blue-deep);
|
| 1427 |
+
outline-offset: 1px;
|
| 1428 |
+
border-radius: var(--lp-r-md);
|
| 1429 |
+
}
|
| 1430 |
+
|
| 1431 |
+
/* The subject the server named, on the same line as its sentence rather than above it: a second
|
| 1432 |
+
line per refusal is the stacking this ticket is removing. */
|
| 1433 |
+
.cg-refusal-who {
|
| 1434 |
+
flex: 0 0 auto;
|
| 1435 |
+
color: var(--lp-ink);
|
| 1436 |
+
font-weight: 600;
|
| 1437 |
+
}
|
| 1438 |
+
|
| 1439 |
+
.cg-refusal-say {
|
| 1440 |
+
min-width: 0;
|
| 1441 |
+
}
|
| 1442 |
+
|
| 1443 |
+
.cg-refusal-why {
|
| 1444 |
+
display: none;
|
| 1445 |
+
margin: 2px 0 6px;
|
| 1446 |
+
padding: 0 0 0 10px;
|
| 1447 |
+
color: var(--lp-muted);
|
| 1448 |
+
font-size: var(--lp-fs-2xs);
|
| 1449 |
+
line-height: 1.5;
|
| 1450 |
+
}
|
| 1451 |
+
|
| 1452 |
+
.cg-refusal[open] > .cg-refusal-why {
|
| 1453 |
+
display: block;
|
| 1454 |
+
}
|
| 1455 |
+
|
| 1456 |
+
/* A refusal the server sent with no diagnosis (a pinned read: `_refusal_error` carries the
|
| 1457 |
+
sentence and no second string) keeps the panel's ordinary note voice and grows no caret. */
|
| 1458 |
+
.cg-refusal-flat {
|
| 1459 |
+
padding: 16px;
|
| 1460 |
+
}
|
| 1461 |
+
|
| 1462 |
+
@media (prefers-reduced-motion: reduce) {
|
| 1463 |
+
.cg-refusal-sum::before {
|
| 1464 |
+
transition: none;
|
| 1465 |
+
}
|
| 1466 |
+
}
|
web/src/customer-grid/RecordDetail.tsx
CHANGED
|
@@ -47,7 +47,7 @@ import { AI_STATE_PREFIX, choiceOptions, codeLanguageOf, isPickType, mayEditFiel
|
|
| 47 |
declares what a `/related` entry and a pinned read ARE, so this panel and `CustomerGrid`
|
| 48 |
cannot come to hold two opinions about one wire contract
|
| 49 |
[[two-lanes-one-contract-dead-feature]]. */
|
| 50 |
-
import { CUSTOMER_TOPIC, PRODUCT_TOPIC, RELATED_REFUSAL, relatedTabs,
|
| 51 |
topicForScope } from "./types";
|
| 52 |
import type { CustomerDoc, Field, RelatedEntry, RelatedPin, RelatedRefusal, RelatedVia, Row,
|
| 53 |
Viewer } from "./types";
|
|
@@ -505,9 +505,139 @@ function refusalSubject(
|
|
| 505 |
if (code === RELATED_REFUSAL.noRelatedRows) return "";
|
| 506 |
if (code === RELATED_REFUSAL.forbiddenTable && table) return labelFor(table) || table;
|
| 507 |
if (code === RELATED_REFUSAL.hopFiltered && hop) return hopWords(hop);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 508 |
return "";
|
| 509 |
}
|
| 510 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
/**
|
| 512 |
* β W51-T06 CLAUSE 9 β ONE HOP of the record view's navigation, carrying everything needed to
|
| 513 |
* render it. See the shadow note inside the component for why the row and the field contract
|
|
@@ -542,6 +672,8 @@ interface RecordFrame {
|
|
| 542 |
const EMPTY_ENTRIES: RelatedEntry[] = [];
|
| 543 |
/** β W53-T24 β and the listing's refusals need one for exactly the same reason. */
|
| 544 |
const EMPTY_REFUSALS: RelatedRefusal[] = [];
|
|
|
|
|
|
|
| 545 |
const EMPTY_ROWS: Row[] = [];
|
| 546 |
const EMPTY_FIELDS: Field[] = [];
|
| 547 |
|
|
@@ -971,10 +1103,39 @@ export default function RecordDetail({
|
|
| 971 |
};
|
| 972 |
}, [scope, recordTable]);
|
| 973 |
|
| 974 |
-
/**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 975 |
const tabs = useMemo(
|
| 976 |
-
() =>
|
| 977 |
-
|
|
|
|
|
|
|
| 978 |
);
|
| 979 |
|
| 980 |
/**
|
|
@@ -1297,7 +1458,22 @@ export default function RecordDetail({
|
|
| 1297 |
setTabState({ status: "projected" });
|
| 1298 |
return;
|
| 1299 |
}
|
| 1300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1301 |
if (!live) return;
|
| 1302 |
/* β A `null` here means the pinned door answered 200 while the ROSTER said no, which is
|
| 1303 |
the one state with no server sentence (see `unpinnableNote`) and therefore no code
|
|
@@ -1306,7 +1482,11 @@ export default function RecordDetail({
|
|
| 1306 |
status: "refused",
|
| 1307 |
reason: refused?.reason ?? unpinnableNote(target),
|
| 1308 |
code: refused?.code ?? "",
|
| 1309 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1310 |
hop: refused?.hop,
|
| 1311 |
});
|
| 1312 |
})();
|
|
@@ -1315,6 +1495,9 @@ export default function RecordDetail({
|
|
| 1315 |
};
|
| 1316 |
}, [activeRelated, relatedPin, projectedIds]);
|
| 1317 |
|
|
|
|
|
|
|
|
|
|
| 1318 |
/** β W53-T24 Β· R13 β the emphasised subject of the open tab's refusal, or `""` for the two
|
| 1319 |
* states that have none (`no_related_rows`, and any code this client does not know). */
|
| 1320 |
const refusedSubject = tabState.status === "refused"
|
|
@@ -2247,35 +2430,6 @@ export default function RecordDetail({
|
|
| 2247 |
β THE GRID IS THE PANEL, not a card inside one. DESIGN section 4 allows ONE
|
| 2248 |
containment layer and the drawer is already it; a bordered box around a grid
|
| 2249 |
inside a drawer inside a modal is the card-in-card the section names. */}
|
| 2250 |
-
{/* ββ W53-T24 Β· RULING R13 β **WHAT THE LISTING WOULD NOT SHOW YOU**, said out loud.
|
| 2251 |
-
A traversal filtered out of the rail is otherwise a tab that never appears, and
|
| 2252 |
-
a tab that never appears is indistinguishable from an edge that was never
|
| 2253 |
-
declared. `refusals` is `[]` whenever nothing was walled off, so this block is
|
| 2254 |
-
absent on every ordinary record rather than a permanent apology.
|
| 2255 |
-
β IN THE PANEL, NOT AN OVERLAY, and a FLEX ITEM of `.cg-record-related` rather
|
| 2256 |
-
than a sibling of it: that wrapper is `height: 100%` of the scrolling body
|
| 2257 |
-
(`styles/wave51/grid.css`), so a paragraph placed BEFORE it would push a
|
| 2258 |
-
full-height block down and overflow the drawer. Inside, the grid keeps
|
| 2259 |
-
`flex: 1 1 auto` and simply takes the remaining height. */}
|
| 2260 |
-
{refusals.map((refusal) => {
|
| 2261 |
-
const subject = refusalSubject(
|
| 2262 |
-
refusal.code,
|
| 2263 |
-
(table) => tableLabels[table] ?? "",
|
| 2264 |
-
refusal.table,
|
| 2265 |
-
refusal.hop,
|
| 2266 |
-
);
|
| 2267 |
-
return (
|
| 2268 |
-
<p
|
| 2269 |
-
key={`${refusal.code}:${refusal.path.join(">")}`}
|
| 2270 |
-
className="cg-record-related-note"
|
| 2271 |
-
role="status"
|
| 2272 |
-
data-refusal={refusal.code}
|
| 2273 |
-
>
|
| 2274 |
-
{subject ? <><strong>{subject}</strong><br /></> : null}
|
| 2275 |
-
{refusal.message}
|
| 2276 |
-
</p>
|
| 2277 |
-
);
|
| 2278 |
-
})}
|
| 2279 |
{tabState.status === "refused" ? (
|
| 2280 |
/* β R6's SECOND SENTENCE β the limit, its cause and what to do instead, in the
|
| 2281 |
SERVER's words. `role="status"` rather than `alert`: a declared relation that
|
|
@@ -2295,14 +2449,17 @@ export default function RecordDetail({
|
|
| 2295 |
β `data-refusal` IS THE STATE, MACHINE-READABLE. Three renders that differ only
|
| 2296 |
in prose cannot be told apart by QA or by a gate; this attribute is how the
|
| 2297 |
distinction survives a screenshot. */
|
| 2298 |
-
<
|
| 2299 |
-
|
| 2300 |
-
|
| 2301 |
-
|
| 2302 |
-
|
| 2303 |
-
|
| 2304 |
-
|
| 2305 |
-
|
|
|
|
|
|
|
|
|
|
| 2306 |
) : tabState.status === "probing" ? (
|
| 2307 |
/* Owner R6 β one small bare rotating mark, NO WORDS on screen. The `aria-label`
|
| 2308 |
is not a word on screen and stays, or the wait is announced as nothing at all
|
|
@@ -2380,6 +2537,47 @@ export default function RecordDetail({
|
|
| 2380 |
/>
|
| 2381 |
</Suspense>
|
| 2382 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2383 |
</div>
|
| 2384 |
) : (
|
| 2385 |
<>
|
|
|
|
| 47 |
declares what a `/related` entry and a pinned read ARE, so this panel and `CustomerGrid`
|
| 48 |
cannot come to hold two opinions about one wire contract
|
| 49 |
[[two-lanes-one-contract-dead-feature]]. */
|
| 50 |
+
import { CUSTOMER_TOPIC, PRODUCT_TOPIC, RELATED_REFUSAL, relatedTabs, skeletonTabs,
|
| 51 |
topicForScope } from "./types";
|
| 52 |
import type { CustomerDoc, Field, RelatedEntry, RelatedPin, RelatedRefusal, RelatedVia, Row,
|
| 53 |
Viewer } from "./types";
|
|
|
|
| 505 |
if (code === RELATED_REFUSAL.noRelatedRows) return "";
|
| 506 |
if (code === RELATED_REFUSAL.forbiddenTable && table) return labelFor(table) || table;
|
| 507 |
if (code === RELATED_REFUSAL.hopFiltered && hop) return hopWords(hop);
|
| 508 |
+
/* ββ W54-T38 Β· C5's FOURTH STATE, AND IT IS THE ONE BRANCH THAT MUST NOT FALL BACK TO THE
|
| 509 |
+
RAW KEY. The other two subjects name something the reader can be shown: a database they hold
|
| 510 |
+
a name for, or a hop. A RETIRED table has no roster entry by definition, so `labelFor` is
|
| 511 |
+
empty and the `|| table` fallback above would print `ut_odoo_customers` in bold, which is
|
| 512 |
+
exactly the screen the owner pasted back at us in instruction 22. The short sentence already
|
| 513 |
+
names the absent database in the server's own words, so there is nothing for a subject line
|
| 514 |
+
to add and it stays empty unless a display name genuinely exists. */
|
| 515 |
+
if (code === RELATED_REFUSAL.retiredTarget && table) return labelFor(table);
|
| 516 |
+
/* ββ W54-T40 β THE ONE STATE WITH NO SERVER **CODE** STILL HAS A SUBJECT, AND IT IS THE TAB
|
| 517 |
+
THE OWNER NAMED. `unpinnableNote` is the client's own sentence for "the read-through roster
|
| 518 |
+
does not name this database", so no code comes back with it and every branch above misses;
|
| 519 |
+
the refusal then rendered as a lone paragraph with nothing saying WHICH database it was
|
| 520 |
+
about. β THE DISPLAY NAME OR NOTHING, exactly as the retired branch above decided: this
|
| 521 |
+
falls through to `labelFor` with no `|| table`, so a database with no roster entry stays
|
| 522 |
+
silent rather than putting a raw key in bold on the owner's screen. */
|
| 523 |
+
if (!code && table) return labelFor(table);
|
| 524 |
return "";
|
| 525 |
}
|
| 526 |
|
| 527 |
+
/**
|
| 528 |
+
* ββ W54-T38 Β· INSTRUCTION 22 Β· DESIGN.md SECTION 4 β **ONE REFUSAL, AS ONE SENTENCE, WITH THE
|
| 529 |
+
* DIAGNOSIS ONE CLICK DOWN.**
|
| 530 |
+
*
|
| 531 |
+
* The owner, verbatim: *"I still get refusals like ... and a wall of ..."*, pasting one sixty-word
|
| 532 |
+
* paragraph that his screen was showing him FOUR TIMES over. W54-T37 fixed the CAUSE (a retired
|
| 533 |
+
* database reported as a permission problem) and left the presentation exactly as it was, which
|
| 534 |
+
* is half the defect: DESIGN.md section 4 says *"never over-explain"*, and four paragraphs stacked
|
| 535 |
+
* above a grid push the rows a reader asked for below the fold.
|
| 536 |
+
*
|
| 537 |
+
* ββ THE DIAGNOSIS IS NOT CUT, IT IS MOVED. W53-T18 wrote those paragraphs on purpose, so that a
|
| 538 |
+
* traversal is never served short and silent; deleting them would trade this defect for the one
|
| 539 |
+
* they were written against. The server now authors BOTH strings (`relations.py`, the banner above
|
| 540 |
+
* `no_related_rows_refusal`) and this component only chooses the treatment.
|
| 541 |
+
* β SO THIS FILE STILL AUTHORS NO PROSE AND STILL SPLITS NOTHING. Cutting `message` at its first
|
| 542 |
+
* full stop would make the client a second author of one wire contract, which is the rule this
|
| 543 |
+
* file already carries beside the refusal render below.
|
| 544 |
+
*
|
| 545 |
+
* β NO `detail` MEANS NO DISCLOSURE, and that is a measured case rather than defensive habit: a
|
| 546 |
+
* PIN-time refusal is authored by `routes_odoo_tables._related_pin`, which raises one sentence and
|
| 547 |
+
* no diagnosis at all. Such a refusal renders as the short sentence in the ordinary muted voice,
|
| 548 |
+
* exactly as it did before, and never as a caret with nothing behind it.
|
| 549 |
+
* β W54-T40 CORRECTS THE ROUTE NAMED HERE. The old text said this refusal arrived through
|
| 550 |
+
* `routes_grid._refusal_error`; it does not. `probeRelatedRead` addresses the ROWS door, and
|
| 551 |
+
* `_refusal_error` belongs to `GET /grid/{table}/related`, whose refusals reach this file through
|
| 552 |
+
* `fetchRelated` and DO carry their diagnosis (W54-T40 added `detail` to the keys it copies, which
|
| 553 |
+
* is the row W54-T38 booked). The two doors are now consistent; the pin door is simply the one
|
| 554 |
+
* with nothing to disclose.
|
| 555 |
+
*
|
| 556 |
+
* β `data-refusal` STAYS THE MACHINE-READABLE STATE, on the outermost element either way. It
|
| 557 |
+
* carries the SERVER's code and nothing else may be spelled into it (see the empty-link note
|
| 558 |
+
* below, which deliberately uses a different attribute).
|
| 559 |
+
* β THE CARET IS DRAWN IN CSS, NOT AN ICON. `RecordDetail.css` owns it, following
|
| 560 |
+
* `.cg-ts-refsum` in `index.css`: a triangle glyph renders at a different size in every font, and
|
| 561 |
+
* this ticket may not extend the icon vocabulary.
|
| 562 |
+
*/
|
| 563 |
+
function RelatedRefusalNote(
|
| 564 |
+
{ code, subject, message, details }:
|
| 565 |
+
{ code: string; subject: string; message: string; details: string[] },
|
| 566 |
+
) {
|
| 567 |
+
if (details.length === 0) {
|
| 568 |
+
return (
|
| 569 |
+
<p
|
| 570 |
+
className="cg-record-related-note cg-refusal-flat"
|
| 571 |
+
role="status"
|
| 572 |
+
data-refusal={code || undefined}
|
| 573 |
+
>
|
| 574 |
+
{subject ? <><strong>{subject}</strong><br /></> : null}
|
| 575 |
+
{message}
|
| 576 |
+
</p>
|
| 577 |
+
);
|
| 578 |
+
}
|
| 579 |
+
return (
|
| 580 |
+
<details className="cg-refusal" data-refusal={code || undefined}>
|
| 581 |
+
<summary className="cg-refusal-sum">
|
| 582 |
+
{subject ? <strong className="cg-refusal-who">{subject}</strong> : null}
|
| 583 |
+
<span className="cg-refusal-say">{message}</span>
|
| 584 |
+
</summary>
|
| 585 |
+
{/* β MORE THAN ONE ONLY WHERE THE SERVER SENT MORE THAN ONE DIAGNOSIS UNDER ONE SENTENCE.
|
| 586 |
+
See `groupRefusals`: the paths differ, the sentence does not, so they share a line and
|
| 587 |
+
each keeps its own paragraph. */}
|
| 588 |
+
{details.map((why) => <p key={why} className="cg-refusal-why">{why}</p>)}
|
| 589 |
+
</details>
|
| 590 |
+
);
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
/**
|
| 594 |
+
* ββ W54-T38 β **ONE LINE PER SENTENCE, NOT ONE LINE PER PATH**, and this is the half of the
|
| 595 |
+
* repetition that shortening the copy CREATED rather than removed.
|
| 596 |
+
*
|
| 597 |
+
* `relations.wall_refusals` collapses its answer on `(code, table, hop)`, which was exactly right
|
| 598 |
+
* while every sentence quoted its own path: a dozen removed paths through one closed table came
|
| 599 |
+
* back as a handful of genuinely different paragraphs. Now that the sentence a reader meets is
|
| 600 |
+
* SHORT, it names less than that key does, and four paths onto one absent database render as four
|
| 601 |
+
* identical lines. Measured on `customer_data` with a staged retirement: four copies of *"is no
|
| 602 |
+
* longer part of this workspace"*, which is instruction 22's wall again at one line each.
|
| 603 |
+
*
|
| 604 |
+
* β IT GROUPS, IT DOES NOT DROP. Each member's diagnosis is kept and stacked inside the one
|
| 605 |
+
* disclosure, so nothing the server said is lost and the count of removed paths is still
|
| 606 |
+
* recoverable by opening it. Dropping the duplicates would delete real answers.
|
| 607 |
+
* β AND IT AUTHORS NOTHING. The group key is the server's own `code` plus the server's own
|
| 608 |
+
* sentence, compared byte for byte; this file writes no summary line, no count and no prose.
|
| 609 |
+
* β THE SUBJECT IS TAKEN FROM THE FIRST MEMBER and that is safe by construction: a group shares
|
| 610 |
+
* one sentence, and each code's sentence quotes whichever of `table` / `hop` its subject is drawn
|
| 611 |
+
* from, so two members with one sentence cannot disagree about it.
|
| 612 |
+
*/
|
| 613 |
+
interface GroupedRefusal {
|
| 614 |
+
code: string;
|
| 615 |
+
table?: string;
|
| 616 |
+
hop?: string;
|
| 617 |
+
message: string;
|
| 618 |
+
details: string[];
|
| 619 |
+
}
|
| 620 |
+
|
| 621 |
+
function groupRefusals(refusals: RelatedRefusal[]): GroupedRefusal[] {
|
| 622 |
+
const byLine = new Map<string, GroupedRefusal>();
|
| 623 |
+
for (const refusal of refusals) {
|
| 624 |
+
const key = `${refusal.code}\u0000${refusal.message}`;
|
| 625 |
+
const seen = byLine.get(key);
|
| 626 |
+
if (!seen) {
|
| 627 |
+
byLine.set(key, {
|
| 628 |
+
code: refusal.code,
|
| 629 |
+
table: refusal.table,
|
| 630 |
+
hop: refusal.hop,
|
| 631 |
+
message: refusal.message,
|
| 632 |
+
details: refusal.detail ? [refusal.detail] : [],
|
| 633 |
+
});
|
| 634 |
+
} else if (refusal.detail && !seen.details.includes(refusal.detail)) {
|
| 635 |
+
seen.details.push(refusal.detail);
|
| 636 |
+
}
|
| 637 |
+
}
|
| 638 |
+
return [...byLine.values()];
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
/**
|
| 642 |
* β W51-T06 CLAUSE 9 β ONE HOP of the record view's navigation, carrying everything needed to
|
| 643 |
* render it. See the shadow note inside the component for why the row and the field contract
|
|
|
|
| 672 |
const EMPTY_ENTRIES: RelatedEntry[] = [];
|
| 673 |
/** β W53-T24 β and the listing's refusals need one for exactly the same reason. */
|
| 674 |
const EMPTY_REFUSALS: RelatedRefusal[] = [];
|
| 675 |
+
/** β W54-T38 β and so does the diagnosis list a PIN-time refusal never has. */
|
| 676 |
+
const EMPTY_DIAGNOSES: string[] = [];
|
| 677 |
const EMPTY_ROWS: Row[] = [];
|
| 678 |
const EMPTY_FIELDS: Field[] = [];
|
| 679 |
|
|
|
|
| 1103 |
};
|
| 1104 |
}, [scope, recordTable]);
|
| 1105 |
|
| 1106 |
+
/**
|
| 1107 |
+
* ββ W54-T39 β IS THE LISTING STILL IN FLIGHT? Derived, never a fourth piece of state, and it
|
| 1108 |
+
* is already exactly what `related.table` records: the state is stamped with the table it was
|
| 1109 |
+
* fetched FOR, so a stamp that does not match this record's table means no answer for this
|
| 1110 |
+
* table has landed yet. `scope == null` is the fail-closed branch that never fetches at all and
|
| 1111 |
+
* therefore never waits.
|
| 1112 |
+
* β IT ALWAYS TERMINATES. `apiBridge.ts::fetchRelated` resolves `EMPTY_LISTING` on a non-ok
|
| 1113 |
+
* response and on a thrown fetch, so the effect's `setRelated` runs on every outcome and the
|
| 1114 |
+
* stamp always catches up. A skeleton that could outlive its request would be worse than the
|
| 1115 |
+
* bare rail it replaces.
|
| 1116 |
+
*/
|
| 1117 |
+
const relatedPending = scope != null && related.table !== recordTable;
|
| 1118 |
+
|
| 1119 |
+
/**
|
| 1120 |
+
* Clause 1 + clause 2 β the tab strip, in the server's order (forward, reverse, bridge).
|
| 1121 |
+
*
|
| 1122 |
+
* ββ W54-T39 β AND THE PLACEHOLDER ROWS WHILE IT IS STILL COMING. Before this, the rail
|
| 1123 |
+
* rendered `Details` alone for as long as `/related` took, with nothing to say more was on the
|
| 1124 |
+
* way: `waves/wave54/shots/F-before-record.png` is that frame, and *"the left-side rail takes
|
| 1125 |
+
* forever to load"* is the owner reading it. The listing itself is now roughly four times
|
| 1126 |
+
* faster (`routes_grid.py::_relation_context`), so this is the smaller half of the fix and it
|
| 1127 |
+
* has to stay honest about which state it is in.
|
| 1128 |
+
* β THE PLACEHOLDERS REPLACE AN EMPTY LIST, THEY NEVER SIT BESIDE A REAL ROW. `entries` is
|
| 1129 |
+
* empty until the answer lands, so there is no frame in which four grey bars and a real tab are
|
| 1130 |
+
* on screen together β the two-row-states defect `shell/navExtras.css` fixed in the page rail.
|
| 1131 |
+
* β AND AN EMPTY ANSWER IS NOT A LOADING ONE. A database with no relations settles to zero
|
| 1132 |
+
* tabs and the placeholders go, because `relatedPending` is false the moment the stamp matches.
|
| 1133 |
+
*/
|
| 1134 |
const tabs = useMemo(
|
| 1135 |
+
() => (relatedPending && !entries.length
|
| 1136 |
+
? skeletonTabs()
|
| 1137 |
+
: relatedTabs(entries, (target) => tableLabels[target] ?? "")),
|
| 1138 |
+
[entries, tableLabels, relatedPending]
|
| 1139 |
);
|
| 1140 |
|
| 1141 |
/**
|
|
|
|
| 1458 |
setTabState({ status: "projected" });
|
| 1459 |
return;
|
| 1460 |
}
|
| 1461 |
+
/* ββ W54-T40 Β· INSTRUCTION 22 β **THE PROBE IS ONLY ASKED OF A DOOR THAT KNOWS THIS
|
| 1462 |
+
TARGET**, and skipping it is the whole of the owner's third error.
|
| 1463 |
+
`probeRelatedRead` addresses `odoo-tables/<key>/rows`, whose vocabulary is the
|
| 1464 |
+
read-through roster and nothing else. MEASURED 2026-09-06: opening **Products ordered**
|
| 1465 |
+
asked that door for `product_data`, a compiled registry module it has never heard of, and
|
| 1466 |
+
got `404 unknown_table` back. Its message is the honest answer to the question that door
|
| 1467 |
+
was asked and the WRONG answer to the one the reader asked, so the tab rendered a bare
|
| 1468 |
+
lower-case *"that database does not exist"* about a database that plainly does exist.
|
| 1469 |
+
β THE ROSTER IS ALREADY THE MOUNT CONDITION (see `pinnable` above), so a target it does
|
| 1470 |
+
not name has no pinned read to probe: there is nothing this call can learn and one wrong
|
| 1471 |
+
sentence it can bring back. The state that is left is exactly the one `unpinnableNote`
|
| 1472 |
+
was written for, and it says what was asked, why it cannot be answered here and what to
|
| 1473 |
+
do instead.
|
| 1474 |
+
β THE PROBE SURVIVES FOR THE STATE IT EXISTS FOR: a target the roster DOES name whose
|
| 1475 |
+
edge is `served: false`. That door has a real sentence and it is still the server's. */
|
| 1476 |
+
const refused = through.has(target) ? await probeRelatedRead(target, pin) : null;
|
| 1477 |
if (!live) return;
|
| 1478 |
/* β A `null` here means the pinned door answered 200 while the ROSTER said no, which is
|
| 1479 |
the one state with no server sentence (see `unpinnableNote`) and therefore no code
|
|
|
|
| 1482 |
status: "refused",
|
| 1483 |
reason: refused?.reason ?? unpinnableNote(target),
|
| 1484 |
code: refused?.code ?? "",
|
| 1485 |
+
/* β W54-T40 β THE SERVER'S SUBJECT WHERE THERE IS ONE, AND THIS TAB'S TARGET WHERE THERE
|
| 1486 |
+
IS NOT. A refusal the client authored is still ABOUT a database, and the only one it
|
| 1487 |
+
can be about is the target of the tab that is open. See `refusalSubject`'s last
|
| 1488 |
+
branch, which turns this into a display name or into nothing. */
|
| 1489 |
+
table: refused?.table ?? target,
|
| 1490 |
hop: refused?.hop,
|
| 1491 |
});
|
| 1492 |
})();
|
|
|
|
| 1495 |
};
|
| 1496 |
}, [activeRelated, relatedPin, projectedIds]);
|
| 1497 |
|
| 1498 |
+
/** β W54-T38 β the listing's refusals, one row per distinct sentence. See `groupRefusals`. */
|
| 1499 |
+
const groupedRefusals = useMemo(() => groupRefusals(refusals), [refusals]);
|
| 1500 |
+
|
| 1501 |
/** β W53-T24 Β· R13 β the emphasised subject of the open tab's refusal, or `""` for the two
|
| 1502 |
* states that have none (`no_related_rows`, and any code this client does not know). */
|
| 1503 |
const refusedSubject = tabState.status === "refused"
|
|
|
|
| 2430 |
β THE GRID IS THE PANEL, not a card inside one. DESIGN section 4 allows ONE
|
| 2431 |
containment layer and the drawer is already it; a bordered box around a grid
|
| 2432 |
inside a drawer inside a modal is the card-in-card the section names. */}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2433 |
{tabState.status === "refused" ? (
|
| 2434 |
/* β R6's SECOND SENTENCE β the limit, its cause and what to do instead, in the
|
| 2435 |
SERVER's words. `role="status"` rather than `alert`: a declared relation that
|
|
|
|
| 2449 |
β `data-refusal` IS THE STATE, MACHINE-READABLE. Three renders that differ only
|
| 2450 |
in prose cannot be told apart by QA or by a gate; this attribute is how the
|
| 2451 |
distinction survives a screenshot. */
|
| 2452 |
+
<RelatedRefusalNote
|
| 2453 |
+
code={tabState.code}
|
| 2454 |
+
subject={refusedSubject}
|
| 2455 |
+
message={tabState.reason}
|
| 2456 |
+
/* β EMPTY, AND MEASURED: a PIN-time refusal is one sentence raised by
|
| 2457 |
+
`routes_odoo_tables._related_pin` with no diagnosis beside it, so there is
|
| 2458 |
+
none to disclose here. It renders as the sentence alone. See
|
| 2459 |
+
`RelatedRefusalNote` for why the LISTING's refusals are the ones that carry a
|
| 2460 |
+
disclosure, and for the route this comment used to name wrongly. */
|
| 2461 |
+
details={EMPTY_DIAGNOSES}
|
| 2462 |
+
/>
|
| 2463 |
) : tabState.status === "probing" ? (
|
| 2464 |
/* Owner R6 β one small bare rotating mark, NO WORDS on screen. The `aria-label`
|
| 2465 |
is not a word on screen and stays, or the wait is announced as nothing at all
|
|
|
|
| 2537 |
/>
|
| 2538 |
</Suspense>
|
| 2539 |
)}
|
| 2540 |
+
|
| 2541 |
+
{/* ββ W53-T24 Β· R13 β **WHAT THE LISTING WOULD NOT SHOW YOU**, said out loud. A
|
| 2542 |
+
traversal filtered out of the rail is otherwise a tab that never appears, and a
|
| 2543 |
+
tab that never appears is indistinguishable from an edge that was never declared.
|
| 2544 |
+
`refusals` is `[]` whenever nothing was walled off, so this block is absent on
|
| 2545 |
+
every ordinary record rather than a permanent apology.
|
| 2546 |
+
|
| 2547 |
+
ββ W54-T38 Β· INSTRUCTION 22 β AND IT MOVED **BELOW THE TAB'S OWN CONTENT**,
|
| 2548 |
+
which is the half of the owner's report that was about layout rather than about
|
| 2549 |
+
words. These refusals belong to the RAIL: they describe edges that are missing
|
| 2550 |
+
from the tab strip, not the tab that is open. Rendered first, they appeared at
|
| 2551 |
+
the top of EVERY related tab, so opening Orders meant scrolling past five
|
| 2552 |
+
paragraphs about other edges to reach the orders. See
|
| 2553 |
+
`shots/F-before-orders-tab.png`, which is that exact frame.
|
| 2554 |
+
β STILL A FLEX ITEM OF `.cg-record-related`, NEVER AN OVERLAY AND NEVER A
|
| 2555 |
+
SIBLING OF IT: that wrapper is `height: 100%` of the scrolling body
|
| 2556 |
+
(`styles/wave51/grid.css`) and the grid inside it is `flex: 1 1 auto`, so this
|
| 2557 |
+
strip is `flex: 0 0 auto` and takes only the lines it needs while the grid keeps
|
| 2558 |
+
the rest. A block placed before it pushed a full-height element down and
|
| 2559 |
+
overflowed the drawer, which is why the ordering is written down here.
|
| 2560 |
+
β ONE `role="status"` FOR THE GROUP rather than one per row: each row is a
|
| 2561 |
+
`<details>` whose summary is a real disclosure control, and wrapping every one of
|
| 2562 |
+
them in its own live region would announce the same strip N times. */}
|
| 2563 |
+
{groupedRefusals.length > 0 && (
|
| 2564 |
+
<div className="cg-refusal-strip" role="status">
|
| 2565 |
+
{groupedRefusals.map((refusal) => (
|
| 2566 |
+
<RelatedRefusalNote
|
| 2567 |
+
key={`${refusal.code}:${refusal.message}`}
|
| 2568 |
+
code={refusal.code}
|
| 2569 |
+
subject={refusalSubject(
|
| 2570 |
+
refusal.code,
|
| 2571 |
+
(table) => tableLabels[table] ?? "",
|
| 2572 |
+
refusal.table,
|
| 2573 |
+
refusal.hop,
|
| 2574 |
+
)}
|
| 2575 |
+
message={refusal.message}
|
| 2576 |
+
details={refusal.details}
|
| 2577 |
+
/>
|
| 2578 |
+
))}
|
| 2579 |
+
</div>
|
| 2580 |
+
)}
|
| 2581 |
</div>
|
| 2582 |
) : (
|
| 2583 |
<>
|
web/src/customer-grid/RecordRail.tsx
CHANGED
|
@@ -90,7 +90,14 @@ export default function RecordRail({ tabs, activeTab, onSelect }: RecordRailProp
|
|
| 90 |
</button>
|
| 91 |
</div>
|
| 92 |
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
{/* R6 calls this "Details" in words even though the state key underneath (and the old
|
| 95 |
tablist strip) both spelled it "fields" β the reader never sees that key, and "Fields"
|
| 96 |
over a panel that also shows a picture upload and a rating row is a name for the data
|
|
@@ -103,7 +110,31 @@ export default function RecordRail({ tabs, activeTab, onSelect }: RecordRailProp
|
|
| 103 |
>
|
| 104 |
<span className="cg-record-rail-row-label">Details</span>
|
| 105 |
</button>
|
| 106 |
-
{tabs.map((tab) => (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
<button
|
| 108 |
key={tab.entry.key}
|
| 109 |
type="button"
|
|
@@ -137,7 +168,7 @@ export default function RecordRail({ tabs, activeTab, onSelect }: RecordRailProp
|
|
| 137 |
prop would redden two gates to carry a number that belongs to one row. */}
|
| 138 |
{tab.hops === 2 && <span className="cg-record-rail-row-sub">2 hops</span>}
|
| 139 |
</button>
|
| 140 |
-
))}
|
| 141 |
</div>
|
| 142 |
</nav>
|
| 143 |
);
|
|
|
|
| 90 |
</button>
|
| 91 |
</div>
|
| 92 |
|
| 93 |
+
{/* ββ W54-T39 β `aria-busy` IS THE WHOLE ANNOUNCEMENT, and it is deliberately not a
|
| 94 |
+
sentence. The placeholder rows below say "more is coming" to a sighted reader; this says
|
| 95 |
+
the same thing to a screen reader without adding a line of copy that would then have to
|
| 96 |
+
be un-said the moment the listing lands. */}
|
| 97 |
+
<div
|
| 98 |
+
className="cg-views-scroll cg-record-rail-list"
|
| 99 |
+
aria-busy={tabs.some((tab) => tab.skeleton) || undefined}
|
| 100 |
+
>
|
| 101 |
{/* R6 calls this "Details" in words even though the state key underneath (and the old
|
| 102 |
tablist strip) both spelled it "fields" β the reader never sees that key, and "Fields"
|
| 103 |
over a panel that also shows a picture upload and a rating row is a name for the data
|
|
|
|
| 110 |
>
|
| 111 |
<span className="cg-record-rail-row-label">Details</span>
|
| 112 |
</button>
|
| 113 |
+
{tabs.map((tab) => (tab.skeleton ? (
|
| 114 |
+
/* ββ W54-T39 β THE RAIL WHILE `/related` IS IN FLIGHT.
|
| 115 |
+
β A `<div>`, NOT A DISABLED BUTTON, and that is the accessibility half rather than a
|
| 116 |
+
preference: a disabled button is still in the accessibility tree and still announced,
|
| 117 |
+
so a reader would be told about four controls that are not there. `aria-hidden` on an
|
| 118 |
+
inert element says the honest thing, and `aria-busy` on the list above says the rest.
|
| 119 |
+
β NO SHIMMER. `shell/navExtras.css`'s `.shell-rail-skeleton` is this app's rail
|
| 120 |
+
skeleton and its own note gives the reason in full: an animated sweep is a second
|
| 121 |
+
thing moving in a rail whose complaint is movement, and `prefers-reduced-motion`
|
| 122 |
+
would then need a third state. This follows it, so there is nothing to reduce.
|
| 123 |
+
β SAME ROW GEOMETRY as `.cg-record-rail-row` (DESIGN Β§4, join the existing rhythm),
|
| 124 |
+
and TWO bars rather than one for the same reason: a real row is a label over a
|
| 125 |
+
subtitle on 24 of the 25 edges tenant #0's `customer_data` offers, so a one-line
|
| 126 |
+
placeholder would settle by growing and the rail would step down under the reader's
|
| 127 |
+
eye. The bars stand in for `.cg-record-rail-row-label` and
|
| 128 |
+
`.cg-record-rail-row-sub`, in that order and at their two widths. */
|
| 129 |
+
<div
|
| 130 |
+
key={tab.entry.key}
|
| 131 |
+
className="cg-record-rail-row is-skeleton"
|
| 132 |
+
aria-hidden="true"
|
| 133 |
+
>
|
| 134 |
+
<span className="cg-record-rail-skeleton-bar" />
|
| 135 |
+
<span className="cg-record-rail-skeleton-bar is-sub" />
|
| 136 |
+
</div>
|
| 137 |
+
) : (
|
| 138 |
<button
|
| 139 |
key={tab.entry.key}
|
| 140 |
type="button"
|
|
|
|
| 168 |
prop would redden two gates to carry a number that belongs to one row. */}
|
| 169 |
{tab.hops === 2 && <span className="cg-record-rail-row-sub">2 hops</span>}
|
| 170 |
</button>
|
| 171 |
+
)))}
|
| 172 |
</div>
|
| 173 |
</nav>
|
| 174 |
);
|
web/src/customer-grid/RouteNav.tsx
CHANGED
|
@@ -313,6 +313,8 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 313 |
| null
|
| 314 |
>(null);
|
| 315 |
const [renameId, setRenameId] = useState<string | null>(null);
|
|
|
|
|
|
|
| 316 |
const [busy, setBusy] = useState(false);
|
| 317 |
const [deliveryMapsPerLink, setDeliveryMapsPerLink] = useState(10);
|
| 318 |
const [deliveryNotice, setDeliveryNotice] = useState<string | null>(null);
|
|
@@ -992,6 +994,39 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 992 |
const backToRoutes = useCallback(() => onActiveRouteChange(null), [onActiveRouteChange]);
|
| 993 |
useEscapeClose(route !== null && titleDraft === null && !deleteConfirm, backToRoutes);
|
| 994 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 995 |
if (route) {
|
| 996 |
// β W46-T25 / RULING R2's guard stood here: a Route projected from a legacy `route_order`
|
| 997 |
// column was refused until an administrator migrated it, because unlocking an unmigrated one
|
|
@@ -1736,9 +1771,16 @@ export function RouteNav({ routes, folders, selectedIds, activeRouteId, sources,
|
|
| 1736 |
<input className="cg-input cg-fold-rename" autoFocus defaultValue={folder.name}
|
| 1737 |
aria-label={`Rename ${folder.name}`} onClick={(event) => event.stopPropagation()}
|
| 1738 |
onBlur={(event) => {
|
|
|
|
|
|
|
|
|
|
| 1739 |
const value = event.target.value.trim();
|
| 1740 |
-
|
| 1741 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1742 |
}}
|
| 1743 |
onKeyDown={(event) => {
|
| 1744 |
if (event.key === "Enter") event.currentTarget.blur();
|
|
|
|
| 313 |
| null
|
| 314 |
>(null);
|
| 315 |
const [renameId, setRenameId] = useState<string | null>(null);
|
| 316 |
+
/** W54-T21 - raised by the rename's Escape claim so the blur it causes does not save. */
|
| 317 |
+
const renameEscaping = useRef(false);
|
| 318 |
const [busy, setBusy] = useState(false);
|
| 319 |
const [deliveryMapsPerLink, setDeliveryMapsPerLink] = useState(10);
|
| 320 |
const [deliveryNotice, setDeliveryNotice] = useState<string | null>(null);
|
|
|
|
| 994 |
const backToRoutes = useCallback(() => onActiveRouteChange(null), [onActiveRouteChange]);
|
| 995 |
useEscapeClose(route !== null && titleDraft === null && !deleteConfirm, backToRoutes);
|
| 996 |
|
| 997 |
+
/* βββββββββ W54-T21 / D-673 β THE RUNGS THAT USED TO BE COVERED BY SILENCE βββββββββββββββ
|
| 998 |
+
*
|
| 999 |
+
* ββ THE STAND-DOWNS ABOVE ONLY WORKED WHILE NOTHING ELSE CLAIMED ESCAPE. Standing down means
|
| 1000 |
+
* "let the key fall through", and until this ticket it fell through to NOBODY, so React's own
|
| 1001 |
+
* handlers on the rename input and the search box still saw it and the delete confirm simply
|
| 1002 |
+
* ignored the press. D-673 puts a claim UNDERNEATH this whole panel - `CustomerGrid.tsx` closes
|
| 1003 |
+
* the navigator - so a fall-through now closes the entire navigator instead. Every surface the
|
| 1004 |
+
* open Route stands down for therefore has to claim the key itself, or the press it was meant
|
| 1005 |
+
* to reach would take the panel down with it.
|
| 1006 |
+
*
|
| 1007 |
+
* β THE LINE ABOVE IS UNTOUCHED, DELIBERATELY. `verify_map.py` slices the FIRST
|
| 1008 |
+
* `useEscapeClose` statement in this file and asserts each of its terms, so these three sit
|
| 1009 |
+
* BELOW it; putting one above would hand that leg the wrong statement to read.
|
| 1010 |
+
*
|
| 1011 |
+
* β `renameEscaping` IS THE SAME ORDERING PROBLEM THE SHEET'S FORMULA EDITOR HAS. The arbiter
|
| 1012 |
+
* blurs the focused element before it calls close, and the folder rename input's blur is what
|
| 1013 |
+
* SAVES the new name, so a bare claim would have made Escape commit a rename it was pressed to
|
| 1014 |
+
* cancel. The blur defers its decision by one microtask and this flag, raised by the close,
|
| 1015 |
+
* wins that race by construction rather than by luck.
|
| 1016 |
+
*
|
| 1017 |
+
* β THE QUERY RUNG IS THE ONE BEHAVIOUR CHANGE, AND IT IS THE SMALL ONE. Escape with a typed
|
| 1018 |
+
* route filter clears the filter and leaves the panel open, which is what the box's own
|
| 1019 |
+
* handler always did; with the box empty there is nothing to clear and the press reaches the
|
| 1020 |
+
* navigator's close. The box keeps its own handler because `verify_map.py` pins it.
|
| 1021 |
+
*/
|
| 1022 |
+
useEscapeClose(titleDraft !== null, () => setTitleDraft(null));
|
| 1023 |
+
useEscapeClose(deleteConfirm, () => setDeleteConfirm(false));
|
| 1024 |
+
useEscapeClose(renameId !== null, () => {
|
| 1025 |
+
renameEscaping.current = true;
|
| 1026 |
+
setRenameId(null);
|
| 1027 |
+
});
|
| 1028 |
+
useEscapeClose(routeQuery !== "", () => setRouteQuery(""));
|
| 1029 |
+
|
| 1030 |
if (route) {
|
| 1031 |
// β W46-T25 / RULING R2's guard stood here: a Route projected from a legacy `route_order`
|
| 1032 |
// column was refused until an administrator migrated it, because unlocking an unmigrated one
|
|
|
|
| 1771 |
<input className="cg-input cg-fold-rename" autoFocus defaultValue={folder.name}
|
| 1772 |
aria-label={`Rename ${folder.name}`} onClick={(event) => event.stopPropagation()}
|
| 1773 |
onBlur={(event) => {
|
| 1774 |
+
// W54-T21 - deferred by ONE microtask so an Escape that blurred this input on
|
| 1775 |
+
// its way to cancelling the rename gets to say so first. A click away, a Tab
|
| 1776 |
+
// and the Enter path all still save, one microtask later, unchanged.
|
| 1777 |
const value = event.target.value.trim();
|
| 1778 |
+
renameEscaping.current = false;
|
| 1779 |
+
queueMicrotask(() => {
|
| 1780 |
+
if (renameEscaping.current) return;
|
| 1781 |
+
if (value && value !== folder.name) finish(onFolderUpdate(folder, { name: value }));
|
| 1782 |
+
setRenameId(null);
|
| 1783 |
+
});
|
| 1784 |
}}
|
| 1785 |
onKeyDown={(event) => {
|
| 1786 |
if (event.key === "Enter") event.currentTarget.blur();
|
web/src/customer-grid/Toolbar.tsx
CHANGED
|
@@ -55,6 +55,17 @@ import { FilterBuilderPanel, FieldsHidePanel, Popover } from "../filter-kit";
|
|
| 55 |
import { MEASURE_OP_LIST, countConditions, newRuleId, opsForType } from "../filter-kit/ops";
|
| 56 |
import "./filters.css";
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
interface ToolbarBaseProps {
|
| 59 |
fields: Field[];
|
| 60 |
/** Identity used only to classify shared fields into ownership sections. */
|
|
@@ -257,6 +268,30 @@ interface ToolbarBaseProps {
|
|
| 257 |
*/
|
| 258 |
frozen?: boolean;
|
| 259 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
/**
|
| 261 |
* β W41-T42 Β· RULING R9 β what this table can pivot to: its LINK FIELDS. Empty means the table
|
| 262 |
* has no link yet, and the control says exactly that rather than offering nothing silently.
|
|
@@ -398,6 +433,26 @@ function IconRelational() {
|
|
| 398 |
</svg>
|
| 399 |
);
|
| 400 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
function IconGroup() {
|
| 402 |
return (
|
| 403 |
<svg {...ic} aria-hidden>
|
|
@@ -814,6 +869,9 @@ export default function Toolbar({
|
|
| 814 |
filterSeed = null,
|
| 815 |
modeControl,
|
| 816 |
frozen = false,
|
|
|
|
|
|
|
|
|
|
| 817 |
relationalTargets = [],
|
| 818 |
relational = null,
|
| 819 |
onRelational,
|
|
@@ -952,6 +1010,25 @@ export default function Toolbar({
|
|
| 952 |
// W41-T42 β the same idiom `colorLabel` and `groupLabel` already use: a control that HAS a
|
| 953 |
// current answer names it on the trigger, so the reader does not have to open it to find out.
|
| 954 |
const relationalLabel = relational ? `Related: ${relational.label}` : "Related";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 955 |
|
| 956 |
/**
|
| 957 |
* R11's greying, as one attribute. `inert` is not in React 18's JSX typings (it landed with
|
|
@@ -976,6 +1053,41 @@ export default function Toolbar({
|
|
| 976 |
on. */}
|
| 977 |
{modeControl}
|
| 978 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 979 |
{/* Fields β show / hide columns, searchable, Pre-set chips (item 7 remainder) */}
|
| 980 |
{/* Owner item 23 β "Hide fields", the panel's actual job and Airtable's wording. */}
|
| 981 |
<Popover label="Fields" icon={<EyeOffIcon />} active={shownCount < fields.length}>
|
|
|
|
| 55 |
import { MEASURE_OP_LIST, countConditions, newRuleId, opsForType } from "../filter-kit/ops";
|
| 56 |
import "./filters.css";
|
| 57 |
|
| 58 |
+
/**
|
| 59 |
+
* ββ W54-T49 Β· C4 β ONE connection, as the selector sees it: a stable id and the EDITABLE label
|
| 60 |
+
* its owner gave it. Two members and no third, because "which client's numbers are these" is
|
| 61 |
+
* answered by the id and read by the label; anything else a connection knows belongs to the
|
| 62 |
+
* Connectors panel, not to a picker above a grid.
|
| 63 |
+
*/
|
| 64 |
+
export interface ConnectionChoice {
|
| 65 |
+
id: string;
|
| 66 |
+
label: string;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
interface ToolbarBaseProps {
|
| 70 |
fields: Field[];
|
| 71 |
/** Identity used only to classify shared fields into ownership sections. */
|
|
|
|
| 268 |
*/
|
| 269 |
frozen?: boolean;
|
| 270 |
|
| 271 |
+
/**
|
| 272 |
+
* ββ W54-T49 Β· RULING R7 / CONTRACT C4 β THE CONNECTION THIS TABLE IS READ THROUGH.
|
| 273 |
+
*
|
| 274 |
+
* R7, verbatim: *"Every Odoo-reading module gains a connection selector; picking one client
|
| 275 |
+
* shows only that client's numbers. β There is no 'All' option that blends two clients."*
|
| 276 |
+
* So the list carries real connections and nothing else: this control has no "All" row, and
|
| 277 |
+
* there is no value of `connectionId` that means "both".
|
| 278 |
+
*
|
| 279 |
+
* β OPTIONAL, AND A CALLER THAT PASSES NOTHING RENDERS NO CONTROL AT ALL β not an empty one,
|
| 280 |
+
* not an inert one. Same posture as `ViewSidebar`'s folder props (*"a caller that passes no
|
| 281 |
+
* `folders` and no handlers renders exactly the pre-wave-8 flat rail"*), and it is what keeps
|
| 282 |
+
* every existing mount of this toolbar byte-identical: a workspace with one connection has
|
| 283 |
+
* nothing to choose between and is shown nothing to choose with.
|
| 284 |
+
*
|
| 285 |
+
* β SUPPLIED, NEVER DERIVED. Which connections exist and which one is in force are SERVER
|
| 286 |
+
* answers (`perm_scope.connection_options` / `perm_scope.connection_scope`); a toolbar that
|
| 287 |
+
* guessed them would be wrong the moment an administrator added a client.
|
| 288 |
+
*/
|
| 289 |
+
connections?: ConnectionChoice[];
|
| 290 |
+
/** The connection in force. It is always one id, because a read is always one connection. */
|
| 291 |
+
connectionId?: string | null;
|
| 292 |
+
/** Read this table through that connection instead. One id, never a set. */
|
| 293 |
+
onConnection?: (connectionId: string) => void;
|
| 294 |
+
|
| 295 |
/**
|
| 296 |
* β W41-T42 Β· RULING R9 β what this table can pivot to: its LINK FIELDS. Empty means the table
|
| 297 |
* has no link yet, and the control says exactly that rather than offering nothing silently.
|
|
|
|
| 433 |
</svg>
|
| 434 |
);
|
| 435 |
}
|
| 436 |
+
/**
|
| 437 |
+
* β W54-T49 β the connection selector's mark, and it is a REUSED glyph rather than a new one.
|
| 438 |
+
*
|
| 439 |
+
* The path is `icons.tsx::MENU_ICONS.swap` verbatim: the two opposed arrows this app already
|
| 440 |
+
* uses for "switch which of these is in force", which is exactly what choosing a connection
|
| 441 |
+
* does. It is drawn here at the toolbar's own 14px / 1.5 stroke rather than imported through
|
| 442 |
+
* `MenuIcon`, because that renders the menu's 16px / 1.3 and the controls in this row share a
|
| 443 |
+
* height and a baseline. `icons.tsx` and `iconShapes.ts` are untouched: the vocabulary has no
|
| 444 |
+
* plug or database mark, and inventing one belongs to whoever owns that file.
|
| 445 |
+
*/
|
| 446 |
+
function IconConnection() {
|
| 447 |
+
return (
|
| 448 |
+
<svg {...ic} aria-hidden>
|
| 449 |
+
<path
|
| 450 |
+
d="M3.5 6h9M10.2 3.7 12.5 6l-2.3 2.3M12.5 10.5h-9M5.8 8.2 3.5 10.5l2.3 2.3"
|
| 451 |
+
{...stroke}
|
| 452 |
+
/>
|
| 453 |
+
</svg>
|
| 454 |
+
);
|
| 455 |
+
}
|
| 456 |
function IconGroup() {
|
| 457 |
return (
|
| 458 |
<svg {...ic} aria-hidden>
|
|
|
|
| 869 |
filterSeed = null,
|
| 870 |
modeControl,
|
| 871 |
frozen = false,
|
| 872 |
+
connections = [],
|
| 873 |
+
connectionId = null,
|
| 874 |
+
onConnection,
|
| 875 |
relationalTargets = [],
|
| 876 |
relational = null,
|
| 877 |
onRelational,
|
|
|
|
| 1010 |
// W41-T42 β the same idiom `colorLabel` and `groupLabel` already use: a control that HAS a
|
| 1011 |
// current answer names it on the trigger, so the reader does not have to open it to find out.
|
| 1012 |
const relationalLabel = relational ? `Related: ${relational.label}` : "Related";
|
| 1013 |
+
// ββ W54-T49 (R7) β the same idiom again, and here it is load bearing rather than convenient:
|
| 1014 |
+
// two connections show the same databases under the same column names, so the ONE thing on
|
| 1015 |
+
// screen that says whose numbers these are is this trigger. It names the client, always.
|
| 1016 |
+
const currentConnection =
|
| 1017 |
+
connections.find((conn) => conn.id === connectionId) ?? connections[0];
|
| 1018 |
+
const connectionLabel = currentConnection
|
| 1019 |
+
? `Connection: ${currentConnection.label}`
|
| 1020 |
+
: "Connection";
|
| 1021 |
+
/**
|
| 1022 |
+
* β R7 β the control renders when there is a connection to name AND a host to take the choice.
|
| 1023 |
+
*
|
| 1024 |
+
* BOTH halves: a picker nothing listens to is a lie, and a picker with no connection behind it
|
| 1025 |
+
* would name a client this workspace does not have. β ONE connection still renders it, unlike
|
| 1026 |
+
* the nav rail's per-connection folders, and the asymmetry is deliberate: the rail is naming
|
| 1027 |
+
* FOLDERS, which a single connection does not need, while this says whose numbers are on the
|
| 1028 |
+
* screen, which is exactly as true at one client as at two. A caller that supplies neither
|
| 1029 |
+
* prop renders nothing, which is every mount of this toolbar today.
|
| 1030 |
+
*/
|
| 1031 |
+
const canPickConnection = !!onConnection && connections.length > 0;
|
| 1032 |
|
| 1033 |
/**
|
| 1034 |
* R11's greying, as one attribute. `inert` is not in React 18's JSX typings (it landed with
|
|
|
|
| 1053 |
on. */}
|
| 1054 |
{modeControl}
|
| 1055 |
|
| 1056 |
+
{/* ββ W54-T49 (R7 / C4) β WHICH CONNECTION THIS TABLE IS READ THROUGH.
|
| 1057 |
+
FIRST in the strip, and first is the argument: every other control here operates on
|
| 1058 |
+
rows, and this one decides which client's rows exist at all. It takes no `order:` of
|
| 1059 |
+
its own, so it sits in the initial cluster with Fields, Filter, Sort and Color and
|
| 1060 |
+
paints where the DOM puts it; the run W50-T07 froze (Color, Rows, Edit, Related, Notes,
|
| 1061 |
+
Full screen) is untouched, in the markup and in the tab sequence alike.
|
| 1062 |
+
|
| 1063 |
+
β NO "ALL" ROW, AND THERE IS NOWHERE TO PUT ONE. R7 is explicit that no option may
|
| 1064 |
+
blend two clients, and the server agrees by construction: `perm_scope.connection_scope`
|
| 1065 |
+
returns one connection or refuses. A radio group, never checkboxes, for the same
|
| 1066 |
+
reason β the control's SHAPE has to say "exactly one" before anybody reads a label. */}
|
| 1067 |
+
{canPickConnection && (
|
| 1068 |
+
<Popover label={connectionLabel} icon={<IconConnection />} active={connections.length > 1}>
|
| 1069 |
+
{(close) => (
|
| 1070 |
+
<div className="cg-pop-body">
|
| 1071 |
+
<div className="cg-pop-title">Connection</div>
|
| 1072 |
+
{connections.map((conn) => (
|
| 1073 |
+
<label key={conn.id} className="cg-radio-row">
|
| 1074 |
+
<input
|
| 1075 |
+
type="radio"
|
| 1076 |
+
name="cg-connection"
|
| 1077 |
+
checked={conn.id === currentConnection?.id}
|
| 1078 |
+
onChange={() => {
|
| 1079 |
+
onConnection?.(conn.id);
|
| 1080 |
+
close();
|
| 1081 |
+
}}
|
| 1082 |
+
/>
|
| 1083 |
+
<span>{conn.label}</span>
|
| 1084 |
+
</label>
|
| 1085 |
+
))}
|
| 1086 |
+
</div>
|
| 1087 |
+
)}
|
| 1088 |
+
</Popover>
|
| 1089 |
+
)}
|
| 1090 |
+
|
| 1091 |
{/* Fields β show / hide columns, searchable, Pre-set chips (item 7 remainder) */}
|
| 1092 |
{/* Owner item 23 β "Hide fields", the panel's actual job and Airtable's wording. */}
|
| 1093 |
<Popover label="Fields" icon={<EyeOffIcon />} active={shownCount < fields.length}>
|
web/src/customer-grid/ViewSidebar.tsx
CHANGED
|
@@ -994,7 +994,25 @@ function DataDatabaseNavigator({
|
|
| 994 |
onClick={() => pushDataLevel({ kind: "origin", label: group.label })}
|
| 995 |
>
|
| 996 |
<FolderMark size={16} />
|
| 997 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 998 |
<span className="cg-fold-count">{group.databases.length}</span>
|
| 999 |
</button>
|
| 1000 |
</div>
|
|
|
|
| 994 |
onClick={() => pushDataLevel({ kind: "origin", label: group.label })}
|
| 995 |
>
|
| 996 |
<FolderMark size={16} />
|
| 997 |
+
{/* β W54-T48 (R4 / C4) β THE FULL NAME ON HOVER, BECAUSE THIS NAME IS NOW THE
|
| 998 |
+
USER'S. This row used to read the literal "Odoo" for every connected
|
| 999 |
+
database and could not truncate; it now reads the CONNECTION's keychain
|
| 1000 |
+
label once a tenant has two connections to tell apart, and a label may run
|
| 1001 |
+
to 80 characters against a rail measured to the pixel. `.cg-fold-name`
|
| 1002 |
+
(index.css:5929) is `overflow:hidden; text-overflow:ellipsis;
|
| 1003 |
+
white-space:nowrap`, so "Royal Production (Jakarta warehouse)" reads as
|
| 1004 |
+
"Royal Production (Jakartβ¦" with nothing to open it.
|
| 1005 |
+
β ON THE SPAN, NOT ON THE BUTTON, and that is the accessibility half. The
|
| 1006 |
+
button's accessible name is its `aria-label` ("Open folder <name>"), which
|
| 1007 |
+
already carries the whole label to a screen reader; a `title` on the button
|
| 1008 |
+
would be a second name competing with it. On the text span it is a POINTER
|
| 1009 |
+
affordance only and adds nothing to the accessibility tree.
|
| 1010 |
+
β The same treatment `PathCrumbs` gives a truncatable path segment
|
| 1011 |
+
(`title={segment.label}`, this file) and the shape `.cg-fold-name` already
|
| 1012 |
+
takes in the view layer below. No CSS: a title needs none. */}
|
| 1013 |
+
<span className="cg-fold-name" title={group.label}>
|
| 1014 |
+
{group.label}
|
| 1015 |
+
</span>
|
| 1016 |
<span className="cg-fold-count">{group.databases.length}</span>
|
| 1017 |
</button>
|
| 1018 |
</div>
|
web/src/customer-grid/iconShapes.ts
CHANGED
|
@@ -437,6 +437,37 @@ export const FOLDER_TONE_LABELS: Record<FolderTone, string> = {
|
|
| 437 |
* as two icon vocabularies, and a second source of colour would let the two marks drift apart.
|
| 438 |
* β IT IS STILL NOT A `FolderShape`. A folder's mark is user-chosen and stored in nav prefs; this
|
| 439 |
* one is what the row IS, so nothing offers it in the shape picker.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
*/
|
| 441 |
export function DatabaseMark({ size = 16 }: { size?: number }): ReactElement {
|
| 442 |
const paint = folderTonePaint(DATABASE_MARK_TONE);
|
|
@@ -449,16 +480,22 @@ export function DatabaseMark({ size = 16 }: { size?: number }): ReactElement {
|
|
| 449 |
viewBox: "0 0 16 16",
|
| 450 |
"aria-hidden": true,
|
| 451 |
},
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
)
|
| 463 |
);
|
| 464 |
}
|
|
|
|
| 437 |
* as two icon vocabularies, and a second source of colour would let the two marks drift apart.
|
| 438 |
* β IT IS STILL NOT A `FolderShape`. A folder's mark is user-chosen and stored in nav prefs; this
|
| 439 |
* one is what the row IS, so nothing offers it in the shape picker.
|
| 440 |
+
*
|
| 441 |
+
* ββ W54-T41 (owner instruction 23) β THE OPTICAL NORMALISATION, AND WHY IT IS A TRANSFORM
|
| 442 |
+
* RATHER THAN NEW PATH DATA.
|
| 443 |
+
*
|
| 444 |
+
* Owner, verbatim: *"Under the view navigation rail, the height of the Database icon and the
|
| 445 |
+
* Folder icon is not the same, making the rail asymmetric and unpleasant when going back and
|
| 446 |
+
* forth along a path."* Both marks already shared the 16x16 box, the 16px render size and the
|
| 447 |
+
* 1.35 stroke, so nothing about the ATTRIBUTES said anything was wrong. The INK did: the cylinder
|
| 448 |
+
* draws from y 2.0 to y 14.0 and the default folder from y 3.6 to y 13.2, which is 12.0 units of
|
| 449 |
+
* geometry against 9.6 β about 19% taller, and a rail alternating between the two steps up and
|
| 450 |
+
* down as you walk a path.
|
| 451 |
+
*
|
| 452 |
+
* The fix is a UNIFORM scale of 0.8 about the group, offset by 1.6 across and 2.0 down, with the
|
| 453 |
+
* stroke pre-divided so it still RENDERS at 1.35:
|
| 454 |
+
* - vertical ink 0.8 x 12.0 + 1.35 = 10.95, the folder's 9.6 + 1.35 exactly;
|
| 455 |
+
* - top and bottom edges land on y 3.6 and y 13.2, the folder's own edges, so the two marks
|
| 456 |
+
* share a baseline as well as a height and the rail shows no step;
|
| 457 |
+
* - horizontal ink 0.8 x 9.0 = 7.2 wide, centred on x 8. Narrower than the folder, which is
|
| 458 |
+
* what the note above already documents as intended: the silhouettes must differ.
|
| 459 |
+
*
|
| 460 |
+
* β UNIFORM, never a y-only squash. The rim-depth note above is the reason: `ry` 1.9 against
|
| 461 |
+
* `rx` 4.5 is what stops the cylinder reading as a rectangle at 16px, and flattening only the
|
| 462 |
+
* vertical axis would push it straight back toward one. A uniform scale preserves the ratio.
|
| 463 |
+
*
|
| 464 |
+
* β AND THE `d` STRINGS ARE UNTOUCHED BY DESIGN. `shell/icons.tsx::DatabaseIcon` carries a
|
| 465 |
+
* deliberate byte-identical COPY of these three paths (importing the constant would drag the
|
| 466 |
+
* grid's 48 kB icon chunk into the eager shell entry), and `verify_icons.py::t35_database_faults`
|
| 467 |
+
* compares the two byte for byte. Editing the geometry here would red that leg from a file the
|
| 468 |
+
* shell copy cannot follow, so the normalisation lives in the RENDERER and the data stays data.
|
| 469 |
+
* `verify_icons.py::t41_ink_faults` measures the drawn ink of both marks β arcs sampled through
|
| 470 |
+
* the SVG centre parameterisation, so the rim's bulge counts β and holds the two extents equal.
|
| 471 |
*/
|
| 472 |
export function DatabaseMark({ size = 16 }: { size?: number }): ReactElement {
|
| 473 |
const paint = folderTonePaint(DATABASE_MARK_TONE);
|
|
|
|
| 480 |
viewBox: "0 0 16 16",
|
| 481 |
"aria-hidden": true,
|
| 482 |
},
|
| 483 |
+
createElement(
|
| 484 |
+
"g",
|
| 485 |
+
{ transform: "translate(1.6 2) scale(0.8)" },
|
| 486 |
+
DATABASE_SHAPE_PATHS.map((s) =>
|
| 487 |
+
createElement("path", {
|
| 488 |
+
key: s.d,
|
| 489 |
+
d: s.d,
|
| 490 |
+
fill: "none",
|
| 491 |
+
stroke: paint.stroke,
|
| 492 |
+
// Pre-divided by the group's scale, so what reaches the screen is still the 1.35 every
|
| 493 |
+
// sibling mark in this vocabulary strokes at.
|
| 494 |
+
strokeWidth: 1.35 / 0.8,
|
| 495 |
+
strokeLinecap: "round",
|
| 496 |
+
strokeLinejoin: "round",
|
| 497 |
+
})
|
| 498 |
+
)
|
| 499 |
)
|
| 500 |
);
|
| 501 |
}
|
web/src/customer-grid/types.ts
CHANGED
|
@@ -4234,17 +4234,40 @@ export interface RelatedEntry {
|
|
| 4234 |
*/
|
| 4235 |
export interface RelatedRefusal {
|
| 4236 |
code: string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4237 |
message: string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4238 |
path: string[];
|
| 4239 |
table?: string;
|
| 4240 |
hop?: string;
|
| 4241 |
}
|
| 4242 |
|
| 4243 |
/**
|
| 4244 |
-
* ββ W53-T24 Β·
|
|
|
|
| 4245 |
*
|
| 4246 |
-
* β A CONSTANT RATHER THAN
|
| 4247 |
-
* whole content is that these
|
| 4248 |
* site silently collapses that answer back into the default treatment, which is the empty-grid
|
| 4249 |
* failure wearing a new disguise, and no gate on either side of the wire would see it. Imported
|
| 4250 |
* where the states are chosen, so `tsc` binds the declaration to its consumer.
|
|
@@ -4255,6 +4278,16 @@ export const RELATED_REFUSAL = {
|
|
| 4255 |
noRelatedRows: "no_related_rows",
|
| 4256 |
forbiddenTable: "forbidden_table",
|
| 4257 |
hopFiltered: "hop_filtered",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4258 |
} as const;
|
| 4259 |
|
| 4260 |
/**
|
|
@@ -4284,6 +4317,68 @@ export interface RelatedTab {
|
|
| 4284 |
* fourth prop would redden two gates for a mark that belongs to one row anyway.
|
| 4285 |
*/
|
| 4286 |
hops: 1 | 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4287 |
}
|
| 4288 |
|
| 4289 |
/**
|
|
@@ -4378,6 +4473,13 @@ export function relatedRefusals(body: unknown): RelatedRefusal[] {
|
|
| 4378 |
};
|
| 4379 |
if (typeof raw?.table === "string" && raw.table) refusal.table = raw.table;
|
| 4380 |
if (typeof raw?.hop === "string" && raw.hop) refusal.hop = raw.hop;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4381 |
out.push(refusal);
|
| 4382 |
}
|
| 4383 |
return out;
|
|
|
|
| 4234 |
*/
|
| 4235 |
export interface RelatedRefusal {
|
| 4236 |
code: string;
|
| 4237 |
+
/**
|
| 4238 |
+
* ββ W54-T38 Β· INSTRUCTION 22 β **ONE SHORT SENTENCE**, and that is now a
|
| 4239 |
+
* property of the wire rather than a hope about the server. The owner was shown this string
|
| 4240 |
+
* four times on one screen at sixty words each, which DESIGN.md section 4 forbids in as many
|
| 4241 |
+
* words ("never over-explain"). `relations.py` now authors two strings per refusal and this is
|
| 4242 |
+
* the first one.
|
| 4243 |
+
*/
|
| 4244 |
message: string;
|
| 4245 |
+
/**
|
| 4246 |
+
* ββ THE DIAGNOSIS, for the disclosure. Word for word what `message` used to be:
|
| 4247 |
+
* which hop went, which door is shut, what to do about it.
|
| 4248 |
+
*
|
| 4249 |
+
* ββ OPTIONAL, AND THE ONE PLACE IT IS GENUINELY ABSENT IS MEASURED RATHER THAN
|
| 4250 |
+
* GUESSED. The LISTING carries it (`routes_grid.related_refusals` returns `wall_refusals`'
|
| 4251 |
+
* bags whole), so every refusal drawn from `/related` has one. A PIN-time refusal does not:
|
| 4252 |
+
* `routes_grid._refusal_error` copies only `table`, `hop`, `path` and `candidates` into the X2
|
| 4253 |
+
* envelope, and that file is another ticket's fence. So an absent `detail` means "the server
|
| 4254 |
+
* sent no diagnosis", which renders as the short sentence alone, never as an invented one.
|
| 4255 |
+
* β THE CLIENT NEVER SPLITS `message` TO FILL THIS. Cutting a paragraph at its first full
|
| 4256 |
+
* stop would make this file a second author of one wire contract, which is the rule
|
| 4257 |
+
* `RecordDetail.tsx` already carries beside the refusal render.
|
| 4258 |
+
*/
|
| 4259 |
+
detail?: string;
|
| 4260 |
path: string[];
|
| 4261 |
table?: string;
|
| 4262 |
hop?: string;
|
| 4263 |
}
|
| 4264 |
|
| 4265 |
/**
|
| 4266 |
+
* ββ W53-T24 Β· R13 Β· C3, EXTENDED BY W54-T38 Β· C5 β **THE FOUR CODES,
|
| 4267 |
+
* SPELLED EXACTLY ONCE IN THIS CLIENT.**
|
| 4268 |
*
|
| 4269 |
+
* β A CONSTANT RATHER THAN FOUR STRING LITERALS SCATTERED THROUGH A RENDER, because R13's
|
| 4270 |
+
* whole content is that these four are DIFFERENT ANSWERS: a typo in one literal at one call
|
| 4271 |
* site silently collapses that answer back into the default treatment, which is the empty-grid
|
| 4272 |
* failure wearing a new disguise, and no gate on either side of the wire would see it. Imported
|
| 4273 |
* where the states are chosen, so `tsc` binds the declaration to its consumer.
|
|
|
|
| 4278 |
noRelatedRows: "no_related_rows",
|
| 4279 |
forbiddenTable: "forbidden_table",
|
| 4280 |
hopFiltered: "hop_filtered",
|
| 4281 |
+
/**
|
| 4282 |
+
* ββ W54-T38 Β· CONTRACT C5's FOURTH ANSWER, and it is the one instruction 22 is
|
| 4283 |
+
* about: the edge opens a database this deployment does not have any more. It is NOT a
|
| 4284 |
+
* permission answer, it must never be treated as one, and the whole complaint was a reader
|
| 4285 |
+
* being told to ask an administrator for access to a table nobody can grant.
|
| 4286 |
+
* β `unknown_via` is a FIFTH code on the wire and is deliberately not spelled here: this
|
| 4287 |
+
* client renders no branch of its own for it, and a constant nothing reads would be a
|
| 4288 |
+
* declaration pretending to be a consumer.
|
| 4289 |
+
*/
|
| 4290 |
+
retiredTarget: "retired_target",
|
| 4291 |
} as const;
|
| 4292 |
|
| 4293 |
/**
|
|
|
|
| 4317 |
* fourth prop would redden two gates for a mark that belongs to one row anyway.
|
| 4318 |
*/
|
| 4319 |
hops: 1 | 2;
|
| 4320 |
+
/**
|
| 4321 |
+
* ββ W54-T39 β TRUE ONLY ON A PLACEHOLDER, AND IT TRAVELS HERE FOR THE SAME REASON `hops`
|
| 4322 |
+
* DOES. While `/related` is in flight the rail knows about exactly one row, `Details`, and
|
| 4323 |
+
* shows it alone with nothing to say more is coming β the owner's *"the left-side rail takes
|
| 4324 |
+
* forever to load"*, photographed at `waves/wave54/shots/F-before-record.png`. The rail needs
|
| 4325 |
+
* to be told it is waiting, and `verify_wiring.py` plus `verify_record_layout.py` both assert
|
| 4326 |
+
* its mount as the exact string `<RecordRail tabs={tabs} activeTab={activeTab}
|
| 4327 |
+
* onSelect={setTab} />`, so a fourth prop is not available to say it. The signal rides the tab.
|
| 4328 |
+
*
|
| 4329 |
+
* β A SKELETON TAB IS NEVER SELECTABLE AND NEVER RESOLVES TO AN EDGE. Its `entry.key` is
|
| 4330 |
+
* `SKELETON_TAB_PREFIX + n`, a spelling no server edge can carry, so `RecordDetail`'s
|
| 4331 |
+
* `activeTab` falls back to `"fields"` and `activeRelated` stays null exactly as it does before
|
| 4332 |
+
* any listing arrives. `RecordRail` renders these rows as inert `<div>`s rather than buttons,
|
| 4333 |
+
* so neither a click nor a Tab key can reach one.
|
| 4334 |
+
* β OPTIONAL, and absent on every real tab: `relatedTabs` never sets it, so a tab built from
|
| 4335 |
+
* the server's own answer cannot be mistaken for a placeholder.
|
| 4336 |
+
*/
|
| 4337 |
+
skeleton?: true;
|
| 4338 |
+
}
|
| 4339 |
+
|
| 4340 |
+
/**
|
| 4341 |
+
* β THE ONE SPELLING A PLACEHOLDER ROW'S KEY MAY TAKE, and it is deliberately not a legal edge
|
| 4342 |
+
* key: `relations.py` mints edge keys out of field, table and bridge names, none of which can
|
| 4343 |
+
* begin with a space. So no listing can ever collide with one of these, and no stale selection
|
| 4344 |
+
* can point at one.
|
| 4345 |
+
*/
|
| 4346 |
+
export const SKELETON_TAB_PREFIX = " skeleton:";
|
| 4347 |
+
|
| 4348 |
+
/**
|
| 4349 |
+
* ββ W54-T39 β THE RAIL'S IN-FLIGHT ROWS. Four, because the rail's real answer on tenant #0's
|
| 4350 |
+
* `customer_data` is twenty-five and on its smallest database is two; four fills the fold without
|
| 4351 |
+
* promising a count, which is what a skeleton is for.
|
| 4352 |
+
*
|
| 4353 |
+
* β DESIGN Β§4 β A SKELETON, NOT A SPINNER, and the same one the app already uses. `.lp-spin`
|
| 4354 |
+
* belongs to a per-tab row load, where one small thing is fetching inside a settled page; this is
|
| 4355 |
+
* the whole rail arriving, and the house answer to that is `shell/navExtras.css`'s
|
| 4356 |
+
* `.shell-rail-skeleton`, which is flat-toned and does not animate at all. Following it means
|
| 4357 |
+
* there is no shimmer for `prefers-reduced-motion` to have to undo.
|
| 4358 |
+
* β NO COPY. The rows carry no words, so there is nothing here to get the dash rule or sentence
|
| 4359 |
+
* case wrong; `RecordRail` marks the list `aria-busy` instead, which is what a screen reader
|
| 4360 |
+
* wants and a sighted reader does not need told twice.
|
| 4361 |
+
*/
|
| 4362 |
+
export function skeletonTabs(count = 4): RelatedTab[] {
|
| 4363 |
+
const out: RelatedTab[] = [];
|
| 4364 |
+
for (let i = 0; i < count; i += 1) {
|
| 4365 |
+
out.push({
|
| 4366 |
+
entry: {
|
| 4367 |
+
key: `${SKELETON_TAB_PREFIX}${i}`,
|
| 4368 |
+
label: "",
|
| 4369 |
+
target: "",
|
| 4370 |
+
served: false,
|
| 4371 |
+
via: { direction: "forward", key: `${SKELETON_TAB_PREFIX}${i}` },
|
| 4372 |
+
path: [`${SKELETON_TAB_PREFIX}${i}`],
|
| 4373 |
+
hops: 1,
|
| 4374 |
+
},
|
| 4375 |
+
label: "",
|
| 4376 |
+
subtitle: "",
|
| 4377 |
+
hops: 1,
|
| 4378 |
+
skeleton: true,
|
| 4379 |
+
});
|
| 4380 |
+
}
|
| 4381 |
+
return out;
|
| 4382 |
}
|
| 4383 |
|
| 4384 |
/**
|
|
|
|
| 4473 |
};
|
| 4474 |
if (typeof raw?.table === "string" && raw.table) refusal.table = raw.table;
|
| 4475 |
if (typeof raw?.hop === "string" && raw.hop) refusal.hop = raw.hop;
|
| 4476 |
+
/* ββ W54-T38 β THE DIAGNOSIS, WHEN THE SERVER SENT ONE. Read exactly as `table` and `hop`
|
| 4477 |
+
are: present and non-empty or absent entirely, never `""`, so the render can branch on
|
| 4478 |
+
"is there a disclosure to draw" with a truth test and no second convention.
|
| 4479 |
+
β AND IT IS NEVER SYNTHESISED FROM `message`. A client that cut the sentence at its first
|
| 4480 |
+
full stop would be authoring copy out of a regular expression; the split is the server's,
|
| 4481 |
+
and a refusal that arrives without one shows its sentence alone. */
|
| 4482 |
+
if (typeof raw?.detail === "string" && raw.detail) refusal.detail = raw.detail;
|
| 4483 |
out.push(refusal);
|
| 4484 |
}
|
| 4485 |
return out;
|
web/src/filter-kit/FilterBuilderPanel.tsx
CHANGED
|
@@ -646,6 +646,19 @@ interface LevelContext {
|
|
| 646 |
*/
|
| 647 |
viewChoices: { id: string; name: string }[];
|
| 648 |
choicesFor: ChoicesFor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 649 |
}
|
| 650 |
|
| 651 |
/**
|
|
@@ -789,7 +802,8 @@ function LeafRow({
|
|
| 789 |
onRule: (r: FilterRule) => void;
|
| 790 |
onRemove: () => void;
|
| 791 |
}) {
|
| 792 |
-
const { fields, fieldByKey, measures, measureByKey, lists, viewChoices, choicesFor
|
|
|
|
| 793 |
const isMeasure = isMeasureRule(rule);
|
| 794 |
const isCohort = rule.colId === COHORT_FIELD;
|
| 795 |
const hasCohorts = lists.length > 0;
|
|
@@ -966,10 +980,15 @@ function LeafRow({
|
|
| 966 |
you pick a thing to filter on, and a measure simply also asks for a period. Item 20
|
| 967 |
adds the type MARK to each row and takes NO grouping with it: the marks are what the
|
| 968 |
optgroup was reaching for, and they say it per row instead of splitting the list. */}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 969 |
<FieldSelectButton
|
| 970 |
className={fieldClass}
|
| 971 |
ariaLabel={fieldAria}
|
| 972 |
-
title={goneColumn ? DELETED_FIELD_NOTE :
|
| 973 |
value={rule.colId}
|
| 974 |
onChange={onField}
|
| 975 |
fields={[
|
|
@@ -1253,6 +1272,18 @@ export interface FilterBuilderPanelProps {
|
|
| 1253 |
* serves an admin editor should know about.
|
| 1254 |
*/
|
| 1255 |
footerExtra?: ReactNode;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1256 |
/*
|
| 1257 |
* β W47-T13 (owner instruction 15) DELETED `onClose` FROM THIS TYPE, and the deletion is the
|
| 1258 |
* point. W38-T02 had added a header close button behind an optional `onClose`; the owner has
|
|
@@ -1274,6 +1305,7 @@ export function FilterBuilderPanel({
|
|
| 1274 |
statusValues,
|
| 1275 |
cohortLock,
|
| 1276 |
footerExtra,
|
|
|
|
| 1277 |
}: FilterBuilderPanelProps) {
|
| 1278 |
const nodes = filterTreeNodes(filters);
|
| 1279 |
const conj = filterTreeConj(filters);
|
|
@@ -1304,8 +1336,9 @@ export function FilterBuilderPanel({
|
|
| 1304 |
);
|
| 1305 |
const ctx = useMemo<LevelContext>(
|
| 1306 |
() => ({ fields: condFields, fieldByKey, measures, measureByKey, lists: cohorts,
|
| 1307 |
-
viewChoices, choicesFor }),
|
| 1308 |
-
[condFields, fieldByKey, measures, measureByKey, cohorts, viewChoices, choicesFor
|
|
|
|
| 1309 |
);
|
| 1310 |
|
| 1311 |
return (
|
|
|
|
| 646 |
*/
|
| 647 |
viewChoices: { id: string; name: string }[];
|
| 648 |
choicesFor: ChoicesFor;
|
| 649 |
+
/**
|
| 650 |
+
* ββ W54-T31 (R8) β the HEADING the condition row's field list wears, or nothing.
|
| 651 |
+
*
|
| 652 |
+
* R8: the Fields list appears in exactly two places, and each one is labelled with what it is
|
| 653 |
+
* picking, so several `sales.. metrics` entries are distinguishable. This is the second place;
|
| 654 |
+
* the first is the Aggregate's column list in `sheet/BindingEditor.tsx`.
|
| 655 |
+
*
|
| 656 |
+
* β UNDEFINED IS THE DEFAULT AND IT MUST STAY PIXEL-IDENTICAL. The Data module's inline
|
| 657 |
+
* filter, the admin permission editor and the view builder all pass nothing, and
|
| 658 |
+
* `FieldSelectButton` renders no heading node at all when its `title` is undefined. A hardcoded
|
| 659 |
+
* string here would have put a Sheet sentence into three surfaces that did not ask for one.
|
| 660 |
+
*/
|
| 661 |
+
fieldPickerTitle?: string;
|
| 662 |
}
|
| 663 |
|
| 664 |
/**
|
|
|
|
| 802 |
onRule: (r: FilterRule) => void;
|
| 803 |
onRemove: () => void;
|
| 804 |
}) {
|
| 805 |
+
const { fields, fieldByKey, measures, measureByKey, lists, viewChoices, choicesFor,
|
| 806 |
+
fieldPickerTitle } = ctx;
|
| 807 |
const isMeasure = isMeasureRule(rule);
|
| 808 |
const isCohort = rule.colId === COHORT_FIELD;
|
| 809 |
const hasCohorts = lists.length > 0;
|
|
|
|
| 980 |
you pick a thing to filter on, and a measure simply also asks for a period. Item 20
|
| 981 |
adds the type MARK to each row and takes NO grouping with it: the marks are what the
|
| 982 |
optgroup was reaching for, and they say it per row instead of splitting the list. */}
|
| 983 |
+
{/* ββ W54-T31 (R8) β THE HEADING GOES IN THE ELSE BRANCH, NEVER OVER THE WHOLE
|
| 984 |
+
EXPRESSION. `DELETED_FIELD_NOTE` explains a column that is gone; a heading merely says
|
| 985 |
+
what the list picks. A refusal outranks a label, so the note keeps winning on exactly
|
| 986 |
+
the rows it won on before, and a host that passes no heading gets `undefined` here, the
|
| 987 |
+
same value this expression has always produced. */}
|
| 988 |
<FieldSelectButton
|
| 989 |
className={fieldClass}
|
| 990 |
ariaLabel={fieldAria}
|
| 991 |
+
title={goneColumn ? DELETED_FIELD_NOTE : fieldPickerTitle}
|
| 992 |
value={rule.colId}
|
| 993 |
onChange={onField}
|
| 994 |
fields={[
|
|
|
|
| 1272 |
* serves an admin editor should know about.
|
| 1273 |
*/
|
| 1274 |
footerExtra?: ReactNode;
|
| 1275 |
+
/**
|
| 1276 |
+
* ββ W54-T31 (R8) β a heading for the condition row's FIELD LIST, saying what that list is
|
| 1277 |
+
* picking. R8 asks for it because a tenant can carry several entries reading `sales.. metrics`
|
| 1278 |
+
* and the list itself is where that ambiguity is answered.
|
| 1279 |
+
*
|
| 1280 |
+
* β OPTIONAL, AND ABSENT MEANS NO HEADING NODE AT ALL. Every existing caller (the Data
|
| 1281 |
+
* module's inline filter, the admin permission editor, the view builder) passes nothing and
|
| 1282 |
+
* renders exactly as it did before this prop existed; only the Sheet's centred filter dialog
|
| 1283 |
+
* passes one, because only there is the list floating free of a panel that names it.
|
| 1284 |
+
* The deleted-column note still wins on a row whose column is gone: see `LeafRow`.
|
| 1285 |
+
*/
|
| 1286 |
+
fieldPickerTitle?: string;
|
| 1287 |
/*
|
| 1288 |
* β W47-T13 (owner instruction 15) DELETED `onClose` FROM THIS TYPE, and the deletion is the
|
| 1289 |
* point. W38-T02 had added a header close button behind an optional `onClose`; the owner has
|
|
|
|
| 1305 |
statusValues,
|
| 1306 |
cohortLock,
|
| 1307 |
footerExtra,
|
| 1308 |
+
fieldPickerTitle,
|
| 1309 |
}: FilterBuilderPanelProps) {
|
| 1310 |
const nodes = filterTreeNodes(filters);
|
| 1311 |
const conj = filterTreeConj(filters);
|
|
|
|
| 1336 |
);
|
| 1337 |
const ctx = useMemo<LevelContext>(
|
| 1338 |
() => ({ fields: condFields, fieldByKey, measures, measureByKey, lists: cohorts,
|
| 1339 |
+
viewChoices, choicesFor, fieldPickerTitle }),
|
| 1340 |
+
[condFields, fieldByKey, measures, measureByKey, cohorts, viewChoices, choicesFor,
|
| 1341 |
+
fieldPickerTitle]
|
| 1342 |
);
|
| 1343 |
|
| 1344 |
return (
|
web/src/filter-kit/SheetFilterPopup.tsx
CHANGED
|
@@ -45,10 +45,17 @@
|
|
| 45 |
|
| 46 |
import { useId, useRef } from "react";
|
| 47 |
import { BodyPortal, OverlayProvider, useOverlayLayer } from "../customer-grid/OverlaySurface";
|
| 48 |
-
import type {
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
// Through the barrel, which is how every other consumer of this kit imports the panel.
|
| 51 |
import { FilterBuilderPanel, countConditions } from "./index";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
export interface SheetFilterPopupProps {
|
| 54 |
/** The cell this filter belongs to, e.g. `B4`. Named in the title so the dialog says which
|
|
@@ -71,9 +78,100 @@ export function conditionCountLabel(filters: FilterTree): string {
|
|
| 71 |
return n === 1 ? "1 condition" : `${n} conditions`;
|
| 72 |
}
|
| 73 |
|
| 74 |
-
/**
|
| 75 |
-
*
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
addr, onClose, fields, filters, onChange, statusValues,
|
| 78 |
}: SheetFilterPopupProps) {
|
| 79 |
const panelRef = useRef<HTMLDivElement>(null);
|
|
@@ -139,20 +237,45 @@ function SheetFilterDialog({
|
|
| 139 |
{/* `min-width: 0` so the builder's rows may shrink inside this flex column instead of
|
| 140 |
pushing the dialog wider than the viewport on a small screen. */}
|
| 141 |
<div className="sheet-filter-popup-body" style={{ minWidth: 0 }}>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
<FilterBuilderPanel
|
| 143 |
fields={fields}
|
| 144 |
filters={filters}
|
| 145 |
onChange={onChange}
|
| 146 |
statusValues={statusValues}
|
|
|
|
| 147 |
/>
|
| 148 |
</div>
|
| 149 |
<div className="lp-dialog-actions">
|
| 150 |
-
{/* β NOT "Save", AND
|
| 151 |
-
imply a discard door that cannot exist without a
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
Done
|
| 157 |
</button>
|
| 158 |
</div>
|
|
|
|
| 45 |
|
| 46 |
import { useId, useRef } from "react";
|
| 47 |
import { BodyPortal, OverlayProvider, useOverlayLayer } from "../customer-grid/OverlaySurface";
|
| 48 |
+
import type {
|
| 49 |
+
Conjunction, Field, FilterNode, FilterOp, FilterRule, FilterTree,
|
| 50 |
+
} from "../customer-grid/types";
|
| 51 |
+
import { filterTreeConj, filterTreeNodes, isFilterGroup, isRuleActive } from "../customer-grid/types";
|
| 52 |
// Through the barrel, which is how every other consumer of this kit imports the panel.
|
| 53 |
import { FilterBuilderPanel, countConditions } from "./index";
|
| 54 |
+
// β DIRECT, NOT THROUGH THE BARREL, because `index.ts` re-exports four names from `ops.ts` and
|
| 55 |
+
// `opLabel` is not one of them. Widening the barrel would change what every other consumer of
|
| 56 |
+
// this kit can reach for a sentence only this file writes; a sibling import inside the same
|
| 57 |
+
// directory changes nothing outside it.
|
| 58 |
+
import { opLabel } from "./ops";
|
| 59 |
|
| 60 |
export interface SheetFilterPopupProps {
|
| 61 |
/** The cell this filter belongs to, e.g. `B4`. Named in the title so the dialog says which
|
|
|
|
| 78 |
return n === 1 ? "1 condition" : `${n} conditions`;
|
| 79 |
}
|
| 80 |
|
| 81 |
+
/**
|
| 82 |
+
* ββ W54-T35 (ruling R8, owner instruction 8) β WHAT THE FILTER SAYS, AS A SENTENCE.
|
| 83 |
+
*
|
| 84 |
+
* Owner, verbatim: *"the Filter module itself will show exactly what the filter is when we click
|
| 85 |
+
* 'View row' so its easy for user also to know what this filter is."* A count answers "how many
|
| 86 |
+
* rules are there"; it does not answer "what is this filter". So the drill needs the second
|
| 87 |
+
* thing, and `conditionCountLabel` directly above stays the answer to the first.
|
| 88 |
+
*
|
| 89 |
+
* β IT IS BUILT FROM `opLabel`, NOT FROM A SECOND OPERATOR VOCABULARY. `FilterBuilderPanel`
|
| 90 |
+
* paints each condition row's operator with `opLabel(op, fieldType)`, so the sentence and the
|
| 91 |
+
* builder behind the Edit door say the same words for the same rule. A local table would drift
|
| 92 |
+
* the first time the owner reworded one of them, and the reader would be told two things.
|
| 93 |
+
*
|
| 94 |
+
* β INACTIVE RULES ARE OMITTED, and that is the honest reading rather than a tidy one. A rule
|
| 95 |
+
* with a blank value is IGNORED by the engine (`isRuleActive`, whose Python mirror
|
| 96 |
+
* `filter_sql.is_rule_active` decides the same thing server-side), so the rows on screen were
|
| 97 |
+
* not narrowed by it. Naming it here would describe rows nobody is looking at.
|
| 98 |
+
*
|
| 99 |
+
* β THREE LEAVES AND THEN A COUNT. The band this feeds is one line across the foot of a modal
|
| 100 |
+
* whose job is the rows above it; a filter with nine rules cannot be read there whatever we do, and an ellipsis in the
|
| 101 |
+
* middle of a value is worse than a number. The dialog behind the Edit door is where a long
|
| 102 |
+
* filter is actually read, which is what makes the truncation safe rather than lossy.
|
| 103 |
+
*/
|
| 104 |
+
const MAX_SPOKEN_LEAVES = 3;
|
| 105 |
+
|
| 106 |
+
/** One leaf, in the builder's own words. `fields` is a map so a nested walk stays linear. */
|
| 107 |
+
function ruleSentence(rule: FilterRule, byKey: Map<string, Field>): string {
|
| 108 |
+
const field = byKey.get(rule.colId);
|
| 109 |
+
const name = field?.label || rule.colId;
|
| 110 |
+
// A column whose type is no longer known reads as text, which is what `opsForType` offers a
|
| 111 |
+
// missing column too: the op still has a label, so the rule still has a sentence.
|
| 112 |
+
const phrase = opLabel(rule.op as FilterOp, field?.type ?? "text");
|
| 113 |
+
const listed = rule.values?.length ? rule.values.join(", ") : "";
|
| 114 |
+
const single = typeof rule.value === "string" ? rule.value.trim() : "";
|
| 115 |
+
const operand = listed || single;
|
| 116 |
+
// `value2` is the far end of a `between`, and the builder reads it as a pair.
|
| 117 |
+
const both = rule.value2 ? `${operand} and ${String(rule.value2).trim()}` : operand;
|
| 118 |
+
return both ? `${name} ${phrase} ${both}` : `${name} ${phrase}`;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/** Does this node narrow anything? A group of blanks narrows nothing, same as a blank rule. */
|
| 122 |
+
function nodeIsActive(node: FilterNode): boolean {
|
| 123 |
+
return isFilterGroup(node)
|
| 124 |
+
? node.children.some(nodeIsActive)
|
| 125 |
+
: isRuleActive(node as FilterRule);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
function nodesSentence(nodes: FilterNode[], conj: Conjunction, byKey: Map<string, Field>): string {
|
| 129 |
+
const joiner = conj === "or" ? " or " : " and ";
|
| 130 |
+
const live = nodes.filter(nodeIsActive);
|
| 131 |
+
const spoken = live.slice(0, MAX_SPOKEN_LEAVES).map((node) =>
|
| 132 |
+
isFilterGroup(node)
|
| 133 |
+
? `(${nodesSentence(node.children, node.conj, byKey)})`
|
| 134 |
+
: ruleSentence(node as FilterRule, byKey));
|
| 135 |
+
const rest = live.length - spoken.length;
|
| 136 |
+
if (rest > 0) spoken.push(rest === 1 ? "1 more condition" : `${rest} more conditions`);
|
| 137 |
+
return spoken.join(joiner);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* The filter, in readable terms.
|
| 142 |
+
*
|
| 143 |
+
* β EMPTY MEANS EMPTY: a filter that narrows nothing returns `""` rather than a sentence saying
|
| 144 |
+
* so. The caller is the one that knows what to say instead, and it already has
|
| 145 |
+
* `conditionCountLabel` for exactly that, so returning a phrase here would be a THIRD wording of
|
| 146 |
+
* "nothing yet" for the two surfaces to drift apart on. A caller that wants the count says
|
| 147 |
+
* `filterSentence(t, f) || conditionCountLabel(t)`, which is one line and reads as the rule.
|
| 148 |
+
*/
|
| 149 |
+
export function filterSentence(
|
| 150 |
+
filters: FilterTree | null | undefined, fields: Field[],
|
| 151 |
+
): string {
|
| 152 |
+
const byKey = new Map(fields.map((f) => [f.key, f]));
|
| 153 |
+
return nodesSentence(filterTreeNodes(filters), filterTreeConj(filters), byKey);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
/**
|
| 157 |
+
* The dialog itself. Split from `SheetFilterPopup` ONLY so that `useOverlayLayer` runs BELOW the
|
| 158 |
+
* provider and therefore joins the same stack the value picker will join.
|
| 159 |
+
*
|
| 160 |
+
* ββ W54-T35 β AND THAT IS WHY IT IS NOW EXPORTED. `SheetFilterPopup` brings its OWN
|
| 161 |
+
* `OverlayProvider`, which is exactly right when the dialog is the only surface of its family on
|
| 162 |
+
* screen (the binding panel's case). It is exactly WRONG when the caller already has another
|
| 163 |
+
* body-level overlay open that the dialog must be ranked against: a private provider is a private
|
| 164 |
+
* stack, so the surface underneath would keep answering `isTop` true and would dismiss itself on
|
| 165 |
+
* the first pointerdown inside this dialog. `sheet/DrillModal.tsx` opens this over the linked
|
| 166 |
+
* record grid, and it supplies ONE provider for both, so both join one stack and the outside-click
|
| 167 |
+
* contract can order them. Callers with nothing else open should keep using `SheetFilterPopup`.
|
| 168 |
+
*
|
| 169 |
+
* β ESCAPE IS NOT WHAT THIS FIXES, and confusing the two is how the wrong shape gets shipped.
|
| 170 |
+
* Escape is arbitrated by the module-level stack in `ui/useEscapeClose` (topmost claimant wins,
|
| 171 |
+
* by push order) and has never needed a provider. `OverlayStackContext` orders OUTSIDE CLICKS and
|
| 172 |
+
* the Tab trap, and only for layers that can see each other.
|
| 173 |
+
*/
|
| 174 |
+
export function SheetFilterDialog({
|
| 175 |
addr, onClose, fields, filters, onChange, statusValues,
|
| 176 |
}: SheetFilterPopupProps) {
|
| 177 |
const panelRef = useRef<HTMLDivElement>(null);
|
|
|
|
| 237 |
{/* `min-width: 0` so the builder's rows may shrink inside this flex column instead of
|
| 238 |
pushing the dialog wider than the viewport on a small screen. */}
|
| 239 |
<div className="sheet-filter-popup-body" style={{ minWidth: 0 }}>
|
| 240 |
+
{/* ββ W54-T31 (R8) β THE SECOND OF THE TWO LABELLED FIELDS LISTS. R8: "Each Fields
|
| 241 |
+
list is labelled with what it is picking, so several `sales.. metrics` entries are
|
| 242 |
+
distinguishable." The first is the Aggregate's column list in `BindingEditor`,
|
| 243 |
+
whose heading names the database and the fold; this one names the CELL, in the same
|
| 244 |
+
words this dialog's own title uses, because that is what tells a reader whose
|
| 245 |
+
filter they are choosing a field for. One line, sentence case: a heading says what
|
| 246 |
+
the list is for and then gets out of the way.
|
| 247 |
+
β Passed HERE and nowhere else. The prop is optional, so the Data module's inline
|
| 248 |
+
filter and the admin permission editor keep the picker they have. */}
|
| 249 |
<FilterBuilderPanel
|
| 250 |
fields={fields}
|
| 251 |
filters={filters}
|
| 252 |
onChange={onChange}
|
| 253 |
statusValues={statusValues}
|
| 254 |
+
fieldPickerTitle={`Fields to filter ${addr} by`}
|
| 255 |
/>
|
| 256 |
</div>
|
| 257 |
<div className="lp-dialog-actions">
|
| 258 |
+
{/* β STILL NOT "Save", AND NO LONGER QUIET. The first half of that stands: nothing is
|
| 259 |
+
held back, so a Save button would imply a discard door that cannot exist without a
|
| 260 |
+
draft copy of the tree, and the word stays "Done".
|
| 261 |
+
|
| 262 |
+
β THE SECOND HALF WAS OVERTURNED BY THE OWNER, W54-T30 / instruction 26, verbatim:
|
| 263 |
+
"the Done button under 'Build a filter' is not on brand and is really ugly". The
|
| 264 |
+
argument this comment used to carry β that a filled `lp-dialog-btn-primary` gives a
|
| 265 |
+
control that merely closes the weight of a commit, in a palette the Sheet does not
|
| 266 |
+
otherwise wear β is now a decision that was made and reversed, so it is recorded as
|
| 267 |
+
history rather than left standing over code that contradicts it.
|
| 268 |
+
|
| 269 |
+
What replaces it: `Done` is the only action in this dialog's footer and it is the
|
| 270 |
+
affirmative one, which is the definition `DESIGN.md` gives `--lp-primary` when it
|
| 271 |
+
reserves the #5433CC family for the primary CTA. `lp-dialog-btn-primary` is that
|
| 272 |
+
token pairing already built in `styles/wave51/kit.css`, so this is a class change
|
| 273 |
+
and not one line of new paint: no local override, no hex, nothing for the Sheet to
|
| 274 |
+
keep in sync with the kit. `--lp-primary` measures 7.71:1 against the white it puts
|
| 275 |
+
its label on, so the filled treatment is the more legible one as well as the
|
| 276 |
+
on-brand one. The hairline `lp-dialog-btn-quiet` remains the right treatment for a
|
| 277 |
+
SECONDARY action, and this footer does not have one. */}
|
| 278 |
+
<button type="button" className="lp-dialog-btn lp-dialog-btn-primary" onClick={onClose}>
|
| 279 |
Done
|
| 280 |
</button>
|
| 281 |
</div>
|
web/src/settings/PermsEditor.tsx
CHANGED
|
@@ -70,12 +70,14 @@ import { DatabasePermsPane } from "./DatabasePermsPane";
|
|
| 70 |
// C4: this lane's own stylesheet. `index.css` is B's and nothing here touches it.
|
| 71 |
import "./perms.css";
|
| 72 |
import {
|
|
|
|
| 73 |
getUserPerms,
|
| 74 |
patchUser,
|
|
|
|
| 75 |
putUserPerms,
|
| 76 |
setPassword,
|
| 77 |
} from "./settingsApi";
|
| 78 |
-
import type { AdminUser } from "./settingsApi";
|
| 79 |
import type { PermsModule, PermsPayload, PermsRecord } from "./permsModel";
|
| 80 |
import {
|
| 81 |
accessSummary,
|
|
@@ -182,6 +184,28 @@ export function PermsEditor({
|
|
| 182 |
const [role, setRole] = useState(user.role ?? "user");
|
| 183 |
const [pw, setPw] = useState("");
|
| 184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
useEffect(() => {
|
| 186 |
let dead = false;
|
| 187 |
setLoad({ phase: "loading" });
|
|
@@ -211,6 +235,33 @@ export function PermsEditor({
|
|
| 211 |
};
|
| 212 |
}, [username]);
|
| 213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
const payload = load.phase === "ready" ? load.payload : null;
|
| 215 |
/**
|
| 216 |
* β W40-T14 β the drill-in RESOLVED, which is the only form the render is allowed to trust.
|
|
@@ -270,7 +321,14 @@ export function PermsEditor({
|
|
| 270 |
*/
|
| 271 |
const accountDirty =
|
| 272 |
name.trim() !== (user.name ?? "").trim() || role !== (user.role ?? "user");
|
| 273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
/**
|
| 275 |
* ββ W47-T19 (owner instruction 11) β WHAT THE ONE SAVE SAYS IT SAVES. With the two buttons
|
| 276 |
* merged there is a single control committing two different kinds of work, and a fixed label
|
|
@@ -289,7 +347,9 @@ export function PermsEditor({
|
|
| 289 |
* `saves_show_they_are_working`'s own NC strips to prove leg 1 can still fire. Changing either
|
| 290 |
* word means changing the gate that pins it, in the same commit, on purpose.
|
| 291 |
*/
|
| 292 |
-
|
|
|
|
|
|
|
| 293 |
|
| 294 |
const goBack = useCallback(() => {
|
| 295 |
if (anyDirty) setAsk({ kind: "discard" });
|
|
@@ -400,6 +460,29 @@ export function PermsEditor({
|
|
| 400 |
return;
|
| 401 |
}
|
| 402 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
if (!payload) {
|
| 404 |
setBusy(false);
|
| 405 |
setAsk(null);
|
|
@@ -429,7 +512,7 @@ export function PermsEditor({
|
|
| 429 |
} else {
|
| 430 |
setError(r.message);
|
| 431 |
}
|
| 432 |
-
}, [payload, draft, username, onSaved, accountDirty, name, role]);
|
| 433 |
|
| 434 |
/** The account half's write. β THE PATCH STILL CARRIES NO `bus` (R1), and
|
| 435 |
* that is load-bearing rather than tidy: with the picker gone this form
|
|
@@ -860,6 +943,73 @@ export function PermsEditor({
|
|
| 860 |
</>
|
| 861 |
)}
|
| 862 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 863 |
</div>
|
| 864 |
</>
|
| 865 |
) : null}
|
|
@@ -931,7 +1081,7 @@ export function PermsEditor({
|
|
| 931 |
that only asked about access would be understating what the click does. */}
|
| 932 |
<h4 className="set-h4">Save these changes for {displayName}?</h4>
|
| 933 |
<p className="set-help">
|
| 934 |
-
{unsavedWords(dirty, accountDirty)} are written now, and a change to access takes
|
| 935 |
effect the next time they load a page. {accessSummaryLine(payload, draft)}
|
| 936 |
</p>
|
| 937 |
</>
|
|
@@ -942,7 +1092,7 @@ export function PermsEditor({
|
|
| 942 |
work now, and "your changes" over a form the reader cannot
|
| 943 |
see behind the scrim is a question they cannot answer. */}
|
| 944 |
<p className="set-help">
|
| 945 |
-
{unsavedWords(dirty, accountDirty)} for {displayName} stay as they were.
|
| 946 |
</p>
|
| 947 |
</>
|
| 948 |
)}
|
|
|
|
| 70 |
// C4: this lane's own stylesheet. `index.css` is B's and nothing here touches it.
|
| 71 |
import "./perms.css";
|
| 72 |
import {
|
| 73 |
+
getConnectorGrants,
|
| 74 |
getUserPerms,
|
| 75 |
patchUser,
|
| 76 |
+
putConnectorGrants,
|
| 77 |
putUserPerms,
|
| 78 |
setPassword,
|
| 79 |
} from "./settingsApi";
|
| 80 |
+
import type { AdminUser, ConnectorKind } from "./settingsApi";
|
| 81 |
import type { PermsModule, PermsPayload, PermsRecord } from "./permsModel";
|
| 82 |
import {
|
| 83 |
accessSummary,
|
|
|
|
| 184 |
const [role, setRole] = useState(user.role ?? "user");
|
| 185 |
const [pw, setPw] = useState("");
|
| 186 |
|
| 187 |
+
/**
|
| 188 |
+
* ββ W54-T47 / R4 / contract C4 β THE THIRD AXIS. Owner, verbatim: *"Under Settings, an Admin
|
| 189 |
+
* should grant a user access to add connectors, so access becomes Database / Module /
|
| 190 |
+
* Connector."*
|
| 191 |
+
*
|
| 192 |
+
* β IT IS ITS OWN STATE RATHER THAN A THIRD GROUP OF `draft`, because it is not a registry key.
|
| 193 |
+
* `payload.modules` are databases and surfaces the perms record governs; a connector is a
|
| 194 |
+
* CREDENTIAL KIND out of `core/keychain.py::ENTRY_TYPES`, carried by its own route so the perms
|
| 195 |
+
* PUT body stays exactly the whole-record replace `permsModel.toPutBody` builds. Folding it in
|
| 196 |
+
* would have made every existing perms leg negotiate a key that is not a module.
|
| 197 |
+
*
|
| 198 |
+
* β `kinds` EMPTY IS ALSO THE FAILURE STATE, deliberately. A server that cannot answer, or one
|
| 199 |
+
* that predates this route, leaves the list empty and the section renders NO HEADING at all,
|
| 200 |
+
* which is the same rule the Database and Module groups already follow: a group with no members
|
| 201 |
+
* is not a labelled empty room.
|
| 202 |
+
*/
|
| 203 |
+
const [connKinds, setConnKinds] = useState<ConnectorKind[]>([]);
|
| 204 |
+
/** The grants as the SERVER holds them, and the draft beside it. Same pairing, same reason, as
|
| 205 |
+
* `saved` / `draft` above: without the baseline there is nothing for "unsaved" to mean. */
|
| 206 |
+
const [connSaved, setConnSaved] = useState<string[]>([]);
|
| 207 |
+
const [connDraft, setConnDraft] = useState<string[]>([]);
|
| 208 |
+
|
| 209 |
useEffect(() => {
|
| 210 |
let dead = false;
|
| 211 |
setLoad({ phase: "loading" });
|
|
|
|
| 235 |
};
|
| 236 |
}, [username]);
|
| 237 |
|
| 238 |
+
/**
|
| 239 |
+
* β W54-T47 β THE CONNECTOR AXIS IS READ ON ITS OWN WIRE, AND A FAILURE HERE IS SILENT.
|
| 240 |
+
*
|
| 241 |
+
* β IT MUST NOT BE ABLE TO BREAK THE PAGE. The perms GET above puts the whole editor into an
|
| 242 |
+
* error state when it cannot be read, and rightly: an admin must never be invited to save a
|
| 243 |
+
* record they were not shown. This one is the opposite case. The grants it fetches are the ONLY
|
| 244 |
+
* thing it can affect, absence of a grant is the ordinary state of every account in the product,
|
| 245 |
+
* and the wall is on the server either way. So a refusal leaves `connKinds` empty, the section
|
| 246 |
+
* renders nothing, and Database and Module keep working exactly as they did.
|
| 247 |
+
*/
|
| 248 |
+
useEffect(() => {
|
| 249 |
+
let dead = false;
|
| 250 |
+
setConnKinds([]);
|
| 251 |
+
setConnSaved([]);
|
| 252 |
+
setConnDraft([]);
|
| 253 |
+
void getConnectorGrants(username).then((r) => {
|
| 254 |
+
if (dead || !r.ok) return;
|
| 255 |
+
const granted = Array.isArray(r.data?.granted) ? r.data.granted.map(String) : [];
|
| 256 |
+
setConnKinds(Array.isArray(r.data?.kinds) ? r.data.kinds : []);
|
| 257 |
+
setConnSaved(granted);
|
| 258 |
+
setConnDraft(granted);
|
| 259 |
+
});
|
| 260 |
+
return () => {
|
| 261 |
+
dead = true;
|
| 262 |
+
};
|
| 263 |
+
}, [username]);
|
| 264 |
+
|
| 265 |
const payload = load.phase === "ready" ? load.payload : null;
|
| 266 |
/**
|
| 267 |
* β W40-T14 β the drill-in RESOLVED, which is the only form the render is allowed to trust.
|
|
|
|
| 321 |
*/
|
| 322 |
const accountDirty =
|
| 323 |
name.trim() !== (user.name ?? "").trim() || role !== (user.role ?? "user");
|
| 324 |
+
/**
|
| 325 |
+
* β W54-T47 β the Connector axis's own baseline comparison. Compared as SORTED text rather than
|
| 326 |
+
* by reference or length: the checkbox writes a new array on every click, so identity says
|
| 327 |
+
* nothing, and two lists of the same size can hold different kinds.
|
| 328 |
+
*/
|
| 329 |
+
const connKey = (list: string[]) => [...list].sort().join(" |