fsanyoto commited on
Commit
1d3d42c
·
verified ·
1 Parent(s): 5a72520

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
RELEASES.json CHANGED
@@ -1,4 +1,4 @@
1
  {
2
- "current": "e7aa88be1",
3
  "releases": []
4
  }
 
1
  {
2
+ "current": "aaa78f5201",
3
  "releases": []
4
  }
VERSION CHANGED
@@ -1 +1 @@
1
- e7aa88be1
 
1
+ aaa78f5201
api/routes_sheet.py CHANGED
@@ -1547,42 +1547,25 @@ def activity_read_policy(session: Session, object):
1547
  memo = getattr(session, "_sheet_read_memo", None)
1548
  books = memo.setdefault("activity_workbooks", {}) if isinstance(memo, dict) else {}
1549
  identity = (session.tenant, session.uname, id(session.runtime), workbook)
1550
- if identity not in books:
1551
- # A refused workbook stays refused for this principal and request only.
1552
- books[identity] = None
1553
- book = sheets.get_workbook(_store(session), workbook)
1554
- _require_reader(session, book)
1555
- claims = session.claims or {}
1556
- access, databases = external_access.scope_of({"access": claims.get("external_access"),
1557
- "databases": claims.get("external_databases")})
1558
- if access == external_access.ACCESS_REFRESH and workbook not in claims.get("external_workbooks", []):
1559
- return False
1560
- books[identity] = {"tabs": {tab["id"]: tab for tab in book.get("sheets", [])},
1561
- "databases": databases}
1562
- context = books[identity]
1563
- if context is None:
1564
  return False
1565
- tabs = context["tabs"]
1566
- databases = context["databases"]
1567
- for address in addresses:
1568
- if not isinstance(address, str) or "!" not in address:
1569
- return False
1570
- tab_id, addr = address.rsplit("!", 1)
1571
- tab = tabs.get(tab_id)
1572
- match = re.fullmatch(r"([A-Z]+)([1-9][0-9]*)", addr)
1573
- if tab is None or match is None:
1574
- return False
1575
- column = 0
1576
- for letter in match[1]:
1577
- column = column * 26 + ord(letter) - ord("A") + 1
1578
- if column > int(tab.get("cols", 0)) or int(match[2]) > int(tab.get("rows", 0)):
1579
- return False
1580
-
1581
- # Addresses stay event-specific even when all current and historical cells are admitted once.
1582
- if "values_allowed" in context:
1583
- return context["values_allowed"]
1584
- context["values_allowed"] = False
1585
- admitted = {}
1586
 
1587
  def cell_allowed(cell):
1588
  if cell is None:
@@ -1596,20 +1579,23 @@ def activity_read_policy(session: Session, object):
1596
  return False
1597
  database = str(binding.get("database") or "")
1598
  if database not in admitted:
 
1599
  _require_database(session, database)
1600
  if not external_access.database_allowed(databases, database):
1601
  return False
1602
  # Historical answers cannot be recalculated into a narrower row or field scope.
1603
- if perm_scope.row_scope_applies(session.user, database, st=session.runtime):
1604
  return False
1605
  if database in {"customer_data", "product_data"} and any(
1606
  perm_scope.derive_pool_scope(session.user, database)):
1607
  return False
1608
- grid = _registry_assembly(session, database, with_rows=False)
1609
  fields = (grid.get("defn") or {}).get("fields", grid.get("fields", []))
1610
- if grid.get("hidden") or perm_scope.hidden_keys(session.user, database, fields, st=session.runtime):
1611
  return False
1612
  admitted[database] = {field["key"] for field in grid["fields"]}
 
 
1613
  def fields_allowed(value):
1614
  if isinstance(value, list):
1615
  return all(fields_allowed(item) for item in value)
@@ -1630,34 +1616,61 @@ def activity_read_policy(session: Session, object):
1630
  _binding_filter_nodes(session, database, dict(binding))[0])
1631
  return fields_allowed(binding) and fields_allowed(nodes)
1632
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1633
  # Formula history may depend on another cell, including a binding that was later removed.
1634
  if not all(cell_allowed(cell) for tab in tabs.values() for cell in tab.get("cells", {}).values()):
1635
  return False
1636
- position = None
1637
- remaining = activity_log.MAX_SCAN
1638
- while remaining > 0:
1639
- page = activity_log.read(session.runtime,
1640
- can_read_object=lambda obj: obj.get("workbook") == workbook,
1641
- object={"workbook": workbook}, cursor=position,
1642
- limit=min(activity_log.MAX_PAGE, remaining), scan_limit=remaining)
1643
- for event in page["records"]:
1644
- if event.get("changes_truncated"):
1645
- return False
1646
- if set(event.get("changes", {})) != set(event.get("object", {}).get("id", [])):
1647
- return False
1648
- for pair in event.get("changes", {}).values():
1649
- if not all(cell_allowed(pair.get(side)) for side in ("before", "after")):
1650
- return False
1651
- position = page.get("next_cursor")
1652
- if position is None:
1653
- context["values_allowed"] = True
1654
- return True
1655
- remaining -= min(activity_log.MAX_PAGE, remaining)
1656
- return False
1657
  except (HTTPException, sheets.SheetRefusal, PermissionError, ValueError, TypeError, KeyError, AttributeError):
1658
  return False
1659
 
1660
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1661
  def _index_for(session: Session):
1662
  """C2: every list response uses the index's sole visibility filter and role helper."""
1663
  from core import sheets
 
1547
  memo = getattr(session, "_sheet_read_memo", None)
1548
  books = memo.setdefault("activity_workbooks", {}) if isinstance(memo, dict) else {}
1549
  identity = (session.tenant, session.uname, id(session.runtime), workbook)
1550
+ if isinstance(memo, dict) and memo.setdefault("activity_permission_identity", identity[:3]) != identity[:3]:
 
 
 
 
 
 
 
 
 
 
 
 
 
1551
  return False
1552
+ context = books.get(identity)
1553
+ if identity in books:
1554
+ return _activity_addresses_allowed(context, addresses)
1555
+ # A refused workbook stays refused for this principal and request only.
1556
+ books[identity] = None
1557
+ claims = session.claims or {}
1558
+ access, databases = external_access.scope_of({"access": claims.get("external_access"),
1559
+ "databases": claims.get("external_databases")})
1560
+ if access == external_access.ACCESS_REFRESH and workbook not in claims.get("external_workbooks", []):
1561
+ return False
1562
+ from copy import copy
1563
+ reader = _sheet_permission_reader(session)
1564
+ borrowed = copy(session)
1565
+ borrowed.runtime = reader
1566
+ source_identity = identity[:3] + (databases,)
1567
+ sources = memo.setdefault("activity_sources", {}) if isinstance(memo, dict) else {}
1568
+ admitted = sources.setdefault(source_identity, {})
 
 
 
 
1569
 
1570
  def cell_allowed(cell):
1571
  if cell is None:
 
1579
  return False
1580
  database = str(binding.get("database") or "")
1581
  if database not in admitted:
1582
+ admitted[database] = None
1583
  _require_database(session, database)
1584
  if not external_access.database_allowed(databases, database):
1585
  return False
1586
  # Historical answers cannot be recalculated into a narrower row or field scope.
1587
+ if perm_scope.row_scope_applies(session.user, database, st=reader):
1588
  return False
1589
  if database in {"customer_data", "product_data"} and any(
1590
  perm_scope.derive_pool_scope(session.user, database)):
1591
  return False
1592
+ grid = _registry_assembly(borrowed, database, with_rows=False)
1593
  fields = (grid.get("defn") or {}).get("fields", grid.get("fields", []))
1594
+ if grid.get("hidden") or perm_scope.hidden_keys(session.user, database, fields, st=reader):
1595
  return False
1596
  admitted[database] = {field["key"] for field in grid["fields"]}
1597
+ if admitted[database] is None:
1598
+ return False
1599
  def fields_allowed(value):
1600
  if isinstance(value, list):
1601
  return all(fields_allowed(item) for item in value)
 
1616
  _binding_filter_nodes(session, database, dict(binding))[0])
1617
  return fields_allowed(binding) and fields_allowed(nodes)
1618
 
1619
+ def admit_history():
1620
+ position = None
1621
+ remaining = activity_log.MAX_SCAN
1622
+ while remaining > 0:
1623
+ page = activity_log.read(session.runtime,
1624
+ can_read_object=lambda obj: obj.get("workbook") == workbook,
1625
+ object={"workbook": workbook}, cursor=position,
1626
+ limit=min(activity_log.MAX_PAGE, remaining), scan_limit=remaining)
1627
+ for event in page["records"]:
1628
+ if (event.get("changes_truncated") or
1629
+ set(event.get("changes", {})) != set(event.get("object", {}).get("id", []))):
1630
+ raise PermissionError("Workbook history is incomplete.")
1631
+ for pair in event.get("changes", {}).values():
1632
+ if not all(cell_allowed(pair.get(side)) for side in ("before", "after")):
1633
+ raise PermissionError("Workbook history is unreadable.")
1634
+ position = page.get("next_cursor")
1635
+ if position is None:
1636
+ return
1637
+ remaining -= min(activity_log.MAX_PAGE, remaining)
1638
+ raise PermissionError("Workbook history is incomplete.")
1639
+
1640
+ # Refused history needs no workbook read; admitted documents still receive every cleaner.
1641
+ admit_history()
1642
+ book = sheets.get_workbook(_store(session), workbook,
1643
+ before_normalize=lambda doc: _require_reader(borrowed, doc))
1644
+ tabs = {tab["id"]: tab for tab in book.get("sheets", [])}
1645
  # Formula history may depend on another cell, including a binding that was later removed.
1646
  if not all(cell_allowed(cell) for tab in tabs.values() for cell in tab.get("cells", {}).values()):
1647
  return False
1648
+ context = books[identity] = {"tabs": tabs}
1649
+ return _activity_addresses_allowed(context, addresses)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1650
  except (HTTPException, sheets.SheetRefusal, PermissionError, ValueError, TypeError, KeyError, AttributeError):
1651
  return False
1652
 
1653
 
1654
+ def _activity_addresses_allowed(context, addresses):
1655
+ """Check each event's addresses against its request's fully admitted workbook."""
1656
+ if context is None:
1657
+ return False
1658
+ for address in addresses:
1659
+ if not isinstance(address, str) or "!" not in address:
1660
+ return False
1661
+ tab_id, addr = address.rsplit("!", 1)
1662
+ tab = context["tabs"].get(tab_id)
1663
+ match = re.fullmatch(r"([A-Z]+)([1-9][0-9]*)", addr)
1664
+ if tab is None or match is None:
1665
+ return False
1666
+ column = 0
1667
+ for letter in match[1]:
1668
+ column = column * 26 + ord(letter) - ord("A") + 1
1669
+ if column > int(tab.get("cols", 0)) or int(match[2]) > int(tab.get("rows", 0)):
1670
+ return False
1671
+ return True
1672
+
1673
+
1674
  def _index_for(session: Session):
1675
  """C2: every list response uses the index's sole visibility filter and role helper."""
1676
  from core import sheets
api/routes_tables.py CHANGED
@@ -525,6 +525,10 @@ def _query_activity_page(session: Session, *, object=None, by=None, since=None,
525
  key = activity_log.DATABASE_KEY
526
  # Borrow definitions and grants for this call only; each cursor request rebuilds them.
527
  context_store = _table_lend(session.runtime, key, defs_only=True)
 
 
 
 
528
  own = _defn_or_refuse(session, key, st=context_store, defs_only=True, scope_applied=True)
529
  own_grid = _compute_ut_assembly(session, key, st=context_store, with_rows=False, fields_only=True,
530
  include_usage=False, include_measures=False)
@@ -540,6 +544,7 @@ def _query_activity_page(session: Session, *, object=None, by=None, since=None,
540
  source_pids = {}
541
  partners = {}
542
  connected = set()
 
543
 
544
  def source(database):
545
  if database not in contexts:
@@ -573,6 +578,7 @@ def _query_activity_page(session: Session, *, object=None, by=None, since=None,
573
  return contexts[database]
574
 
575
  def partner(obj):
 
576
  identity = json.dumps(obj, sort_keys=True)
577
  if identity in partners:
578
  return partners[identity]
@@ -580,8 +586,10 @@ def _query_activity_page(session: Session, *, object=None, by=None, since=None,
580
  try:
581
  if 'app' in obj:
582
  from routes_assets import application_index
583
- admitted = any(app['id'] == obj['app'] for app in
584
- application_index(session=session)['applications'])
 
 
585
  elif 'workbook' in obj:
586
  import routes_sheet
587
  # Historical bound cells need the Sheet's source and address policy too.
@@ -606,7 +614,7 @@ def _query_activity_page(session: Session, *, object=None, by=None, since=None,
606
  try:
607
  raw = activity_log.read(session.runtime, can_read_object=can_read_object,
608
  object=object, by=by, since=since, until=until,
609
- cursor=position, limit=min(max(1000, limit), scan_limit), scan_limit=scan_limit)
610
  position = raw['next_cursor']
611
  # Resolve only this page's source ids through the connected grid's existing SQL wall.
612
  # Whole-pool admission would hide all record events once a source exceeds its window.
 
525
  key = activity_log.DATABASE_KEY
526
  # Borrow definitions and grants for this call only; each cursor request rebuilds them.
527
  context_store = _table_lend(session.runtime, key, defs_only=True)
528
+ memo = getattr(session, '_sheet_read_memo', None)
529
+ if isinstance(memo, dict):
530
+ memo['permission_reader'] = context_store
531
+ memo['activity_permission_identity'] = (session.tenant, session.uname, id(session.runtime))
532
  own = _defn_or_refuse(session, key, st=context_store, defs_only=True, scope_applied=True)
533
  own_grid = _compute_ut_assembly(session, key, st=context_store, with_rows=False, fields_only=True,
534
  include_usage=False, include_measures=False)
 
544
  source_pids = {}
545
  partners = {}
546
  connected = set()
547
+ applications = None
548
 
549
  def source(database):
550
  if database not in contexts:
 
578
  return contexts[database]
579
 
580
  def partner(obj):
581
+ nonlocal applications
582
  identity = json.dumps(obj, sort_keys=True)
583
  if identity in partners:
584
  return partners[identity]
 
586
  try:
587
  if 'app' in obj:
588
  from routes_assets import application_index
589
+ if applications is None:
590
+ applications = {app['id'] for app in
591
+ application_index(session=session)['applications']}
592
+ admitted = obj['app'] in applications
593
  elif 'workbook' in obj:
594
  import routes_sheet
595
  # Historical bound cells need the Sheet's source and address policy too.
 
614
  try:
615
  raw = activity_log.read(session.runtime, can_read_object=can_read_object,
616
  object=object, by=by, since=since, until=until,
617
+ cursor=position, limit=limit, scan_limit=scan_limit)
618
  position = raw['next_cursor']
619
  # Resolve only this page's source ids through the connected grid's existing SQL wall.
620
  # Whole-pool admission would hide all record events once a source exceeds its window.
platform/core/sheets.py CHANGED
@@ -2124,13 +2124,15 @@ def _validated_workbook_text(raw_text):
2124
  return json.dumps(migrate_workbook(json.loads(raw_text)), separators=(",", ":"))
2125
 
2126
 
2127
- def get_workbook(st, workbook_id):
2128
- """One workbook, or a named refusal when the document is not there."""
2129
  wid = _slug_id(workbook_id)
2130
  doc = _read_workbook_doc(st, workbook_key(wid))
2131
  if not doc or not doc.get("id"):
2132
  raise SheetRefusal("workbook_missing",
2133
  "That workbook no longer exists.")
 
 
2134
  try:
2135
  raw_text = json.dumps(doc, separators=(",", ":"))
2136
  except (TypeError, ValueError):
 
2124
  return json.dumps(migrate_workbook(json.loads(raw_text)), separators=(",", ":"))
2125
 
2126
 
2127
+ def get_workbook(st, workbook_id, *, before_normalize=None):
2128
+ """Read an independent normalized workbook after any caller-supplied admission check."""
2129
  wid = _slug_id(workbook_id)
2130
  doc = _read_workbook_doc(st, workbook_key(wid))
2131
  if not doc or not doc.get("id"):
2132
  raise SheetRefusal("workbook_missing",
2133
  "That workbook no longer exists.")
2134
+ if before_normalize is not None:
2135
+ before_normalize(doc)
2136
  try:
2137
  raw_text = json.dumps(doc, separators=(",", ":"))
2138
  except (TypeError, ValueError):
web/public/AIOS_DEPLOY_RECEIPT CHANGED
@@ -1 +1 @@
1
- 02a11b588d633739fa714937a4f10d7b746424ef63fb5c49c525ddd524a3cf60
 
1
+ 683cf59e6a4de1f79003e4b7c7fd7d716dabadf377b986a040083f1aece25472