feat(supabase): V1-2.1 M4/M5 secure sheet access and review workflow

M4 20261028100000_sheet_access_hardening + M5 20261028110000_sheet_review_workflow
(applied together; no unprotected window). Implements contract §5-§14.

- Catalogue rights table + owner RPCs; has_mfa / has_aal2_session (live
  auth.sessions check); grant_active vs caller_has split; catalogue reader
  predicate; can_edit_sheet on the sheet_editor capability (F14).
- AR-1 B: aal2 required on every platform role change, target verified factor,
  race-free last-owner guard (F18/F19); service_role loses table privileges on
  the catalogue + profiles/profile_roles and EXECUTE on the role RPCs (F12/F17).
- Reviewed lifecycle: version provenance + review columns, content/freeze/
  author triggers, rounds/comments/acknowledgments, save/submit/withdraw/
  comment/acknowledge/decide, atomic publish_sheet_version(review_id) on the
  stored verdict, deprecate/archive/restore, species RPCs, equine working copy,
  uploads with the storage check (F7) + editor INSERT policy + 2 MiB bucket.
  F1-F3,F5,F6,F8,F9,F13,F15,F16 closed. Verdict is a fixture until M6 (V1-2.3).
- O22: SQL business mirror removed, declared status check kept; pgTAP 011 and
  the Rust generator's SQL parts deleted, ledger retargeted.
- Access layer sheets.ts (closed SheetFailure kinds); old client publish gate
  deleted; types regenerated; upload tool reads via get_sheet_asset_state.

Tested on the throwaway sandbox only; DEV untouched. pgTAP 850 (real stack) /
122 (PGlite) green; real-GoTrue AR-1 B + F18 race green; fresh install and
M3->M5 upgrade green; V1-1 regression green; rust:check, typecheck, lint,
build, types drift clean. BDR-084, LRN-095.
This commit is contained in:
bchanot committed 2026-10-28 15:52:49 +01:00
1 parent 9c13bae4bc
commit 77e5fa4cf5
33 files changed
+4613 -1617

No files matched your search

@@ -156,21 +156,24 @@ impl Storage {
Ok(true)
}
/// The row of the asset: absent, another hash, pending or confirmed.
/// The row of the asset: absent, another hash, pending or confirmed. Since
/// V1-2.1 (M5, F12) the service role holds no table privilege, so this
/// reads the narrow operator RPC instead of the table.
pub fn row_state(&self, entry: &AssetEntry) -> Result<RowState, UploadError> {
let url = format!(
"{}/rest/v1/anatomical_sheet_assets?id=eq.{}&select=sha256,uploaded_at",
self.origin, entry.svg_asset_id
);
let reply = self.exchange(MAX_BODY, |agent, me| me.authorised(agent.get(&url)).call())?;
let url = format!("{}/rest/v1/rpc/get_sheet_asset_state", self.origin);
let body = json!({ "asset_id": entry.svg_asset_id });
let reply = self.exchange(MAX_BODY, |agent, me| {
me.authorised(agent.post(&url)).send_json(&body)
})?;
check_access(&reply)?;
expect_status(&reply, 200, "row read")?;
let rows: Vec<Value> = serde_json::from_slice(&reply.body)
.map_err(|_| refuse(UploadKind::Handshake, "the row answer is not a JSON list"))?;
Ok(match rows.first() {
None => RowState::Unknown,
Some(row) => row_state_of(row, &entry.sha256),
})
let row: Value = serde_json::from_slice(&reply.body)
.map_err(|_| refuse(UploadKind::Handshake, "the row answer is not JSON"))?;
// The RPC returns JSON null for an unknown asset (no row yet).
if row.is_null() {
return Ok(RowState::Unknown);
}
Ok(row_state_of(&row, &entry.sha256))
}
/// Marks the asset bytes as present (idempotent on the server, service role only).