Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Cost: project definition-only table reads
Browse files- api/routes_forms.py +9 -1
- api/routes_nav.py +16 -9
- api/routes_templates.py +5 -2
api/routes_forms.py
CHANGED
|
@@ -231,7 +231,15 @@ def _public_form(rt, table_key: str, spec: dict) -> dict:
|
|
| 231 |
import aios_grid
|
| 232 |
import core.user_tables as user_tables
|
| 233 |
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
by_key = {f.get("key"): f for f in (defn.get("fields") or []) if isinstance(f, dict)}
|
| 236 |
required = {str(k) for k in (spec.get("required") or [])}
|
| 237 |
out = []
|
|
|
|
| 231 |
import aios_grid
|
| 232 |
import core.user_tables as user_tables
|
| 233 |
|
| 234 |
+
# A public form renders its declared fields only; no submitted table row belongs on this
|
| 235 |
+
# path. In production `rt` is tenant-bound, so lend the rows-free projection. The `None`
|
| 236 |
+
# fallback preserves the isolated helper fixture used by the form verifier.
|
| 237 |
+
lend_defs = getattr(user_tables, 'lend_defs', None)
|
| 238 |
+
# Some isolated route verifiers supply a deliberately tiny `user_tables` double. Production
|
| 239 |
+
# always has `lend_defs`; preserving the double's direct handle keeps that fixture focused on
|
| 240 |
+
# its public-form contract rather than forcing it to impersonate the entire store API.
|
| 241 |
+
definitions = lend_defs(rt) if rt is not None and callable(lend_defs) else rt
|
| 242 |
+
defn = user_tables.get(table_key, st=definitions) or {}
|
| 243 |
by_key = {f.get("key"): f for f in (defn.get("fields") or []) if isinstance(f, dict)}
|
| 244 |
required = {str(k) for k in (spec.get("required") or [])}
|
| 245 |
out = []
|
api/routes_nav.py
CHANGED
|
@@ -764,10 +764,14 @@ def save_nav_meta(body: dict = Body(default=None),
|
|
| 764 |
# because a user table is not a module. Same split `/nav/schema/{key}` makes.
|
| 765 |
# · everything else — admin only, and icon only. There is no owner of `customer_data` to
|
| 766 |
# defer to, and its label is a compiled registry literal (refused below regardless).
|
| 767 |
-
if key.startswith("ut_"):
|
| 768 |
-
import core.user_tables as user_tables
|
| 769 |
-
|
| 770 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 771 |
raise err(403, "forbidden", "that database belongs to another user")
|
| 772 |
else:
|
| 773 |
if not session.admin:
|
|
@@ -886,11 +890,14 @@ def nav_schema(key: str, session: Session = Depends(require_session)):
|
|
| 886 |
# Wave 18 C3-UT: a user table's schema is its own definition, walled by ITS predicate
|
| 887 |
# (`may_open`) rather than the module grant machinery — `session.require` would 403 every
|
| 888 |
# ut key because a user table is deliberately not a module.
|
| 889 |
-
if key.startswith("ut_"):
|
| 890 |
-
import core.user_tables as user_tables
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
|
|
|
|
|
|
|
|
|
| 894 |
raise err(403, "forbidden", "that database belongs to another user")
|
| 895 |
# ⭐⭐ W38-T18 — THE FIELD WALL ON A `ut_*` DATABASE, WHICH THIS DOOR HAS NEVER RUN.
|
| 896 |
# `may_open` answers *IF* you reach the database and says nothing about WHICH COLUMNS, so
|
|
|
|
| 764 |
# because a user table is not a module. Same split `/nav/schema/{key}` makes.
|
| 765 |
# · everything else — admin only, and icon only. There is no owner of `customer_data` to
|
| 766 |
# defer to, and its label is a compiled registry literal (refused below regardless).
|
| 767 |
+
if key.startswith("ut_"):
|
| 768 |
+
import core.user_tables as user_tables
|
| 769 |
+
# This write edits metadata, never a record. The table wall therefore needs its
|
| 770 |
+
# definition only; lending the rows-free JSONB projection keeps a rename/icon click from
|
| 771 |
+
# copying every table row just to prove the caller owns this database.
|
| 772 |
+
definitions = user_tables.lend_defs(session.runtime)
|
| 773 |
+
if not user_tables.get(key, st=definitions) or not user_tables.may_open(
|
| 774 |
+
key, session.uname, session.admin, st=definitions):
|
| 775 |
raise err(403, "forbidden", "that database belongs to another user")
|
| 776 |
else:
|
| 777 |
if not session.admin:
|
|
|
|
| 890 |
# Wave 18 C3-UT: a user table's schema is its own definition, walled by ITS predicate
|
| 891 |
# (`may_open`) rather than the module grant machinery — `session.require` would 403 every
|
| 892 |
# ut key because a user table is deliberately not a module.
|
| 893 |
+
if key.startswith("ut_"):
|
| 894 |
+
import core.user_tables as user_tables
|
| 895 |
+
# Schema is definition-only by contract. Do not pay a whole `user_tables` read merely
|
| 896 |
+
# to open the drawer; the rows-free projection is also lent to the canonical wall.
|
| 897 |
+
definitions = user_tables.lend_defs(session.runtime)
|
| 898 |
+
defn = user_tables.get(key, st=definitions)
|
| 899 |
+
if not defn or not user_tables.may_open(key, session.uname, session.admin,
|
| 900 |
+
st=definitions):
|
| 901 |
raise err(403, "forbidden", "that database belongs to another user")
|
| 902 |
# ⭐⭐ W38-T18 — THE FIELD WALL ON A `ut_*` DATABASE, WHICH THIS DOOR HAS NEVER RUN.
|
| 903 |
# `may_open` answers *IF* you reach the database and says nothing about WHICH COLUMNS, so
|
api/routes_templates.py
CHANGED
|
@@ -49,10 +49,13 @@ def _target_or_refuse(session, table_key):
|
|
| 49 |
raise err(400, "bad_request", "no database was named")
|
| 50 |
if key.startswith('ut_'):
|
| 51 |
import core.user_tables as user_tables
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
if not defn:
|
| 54 |
raise err(404, "unknown_table", "that database does not exist")
|
| 55 |
-
if not user_tables.may_open(key, session.uname, session.admin, st=
|
| 56 |
raise err(403, "forbidden", "that database belongs to another user")
|
| 57 |
fields = [str(f.get('key')) for f in (defn.get('fields') or []) if f.get('key')]
|
| 58 |
# A user table has no fixed topic. Its SOURCE label is left blank so `offer` gates on
|
|
|
|
| 49 |
raise err(400, "bad_request", "no database was named")
|
| 50 |
if key.startswith('ut_'):
|
| 51 |
import core.user_tables as user_tables
|
| 52 |
+
# A template negotiates a field contract, never record values. Keep the table wall on
|
| 53 |
+
# the same rows-free projection as navigation rather than copying the tenant document.
|
| 54 |
+
definitions = user_tables.lend_defs(session.runtime)
|
| 55 |
+
defn = user_tables.get(key, st=definitions)
|
| 56 |
if not defn:
|
| 57 |
raise err(404, "unknown_table", "that database does not exist")
|
| 58 |
+
if not user_tables.may_open(key, session.uname, session.admin, st=definitions):
|
| 59 |
raise err(403, "forbidden", "that database belongs to another user")
|
| 60 |
fields = [str(f.get('key')) for f in (defn.get('fields') or []) if f.get('key')]
|
| 61 |
# A user table has no fixed topic. Its SOURCE label is left blank so `offer` gates on
|