ZDDC/zddc/internal/handler/virtualviewhandler.go
ZDDC db110665f0 feat(server): flat top-level party peers + pure-WORM archive (impl)
Reshape the project layout from "archive/ is the only physical dir + six
virtual aggregators" to a flat set of physical, party-partitioned peers:

  archive/<party>/{received,issued}   pure WORM (one rule, no exceptions)
  incoming|reviewing|working|staging/<party>/   workspaces
  mdl|rsk/<party>/*.yaml              registers (cross-party aggregate at the
                                      peer root, $party from the real subdir)
  ssr/<party>.yaml                    submittal status register AND the
                                      authoritative party registry

A party exists iff ssr/<party>.yaml exists; the new `party_source: ssr`
cascade key gates party-folder creation under every other peer (archive
included) — create <peer>/<party> only when the registry row exists, else
409. Registration is a plain create of ssr/<party>.yaml (no WORM gymnastics),
so archive/ stays purely WORM.

Server core:
- defaults.zddc.yaml rewritten to the flat-peer + WORM-archive + party_source
  shape; every virtual: removed; mdl/rsk get document_controller rwcd.
- slots.go: projectPeers/IsProjectPeer; perPartySlots={received,issued}.
- party_source key end-to-end (file.go/walker/lookups/cascade) + PartyRegistered.
- ensure.go canonical-ancestors generalized to peers; virtual reject removed.
- virtualviews.go: deleted the virtual-URL resolver/types/regex; kept
  ListParties (reads ssr/*) + repointed ListRollupRows (physical <peer>/*/*).
- fs/tree.go: mdl/rsk peer-root listing aggregates physical party subdirs
  (replaces the subdir folder-nav); ssr flat; spec entries advertised.
- fileapi.go: deleted virtual PUT/DELETE rewrites; mkdir allowlist → peers;
  partySourceGate on mkdir/PUT/move.
- virtualviewhandler.go → ServeInjectedRow ($party/name injected on read so
  the tables client renders the column unchanged).
- ssr/form/table handlers repointed to real paths (SSR create writes
  ssr/<party>.yaml; rollup create writes mdl|rsk/<party>/<file>.yaml; SSR
  rename is registry-only); IsDefaultSpec recognizes the new spec locations.
- accept-transmittal source incoming/<party>/<txn> (+ PartyRegistered guard);
  plan-review scaffolds top-level reviewing/<party> + staging/<party>.
- main.go dispatch: removed virtual-row GET + folder-nav 302; injects the
  source column on register-row reads.

Non-test build is green. Test suites still assert the OLD layout (verified:
all current failures are stale expectations, not bugs) — the test rewrite,
browse/tables client updates, and the data-migration script follow.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 11:40:09 -05:00

74 lines
2.4 KiB
Go

// Package handler — virtualviewhandler.go: GET dispatch for the
// aggregate register rows (mdl/<party>/*.yaml, rsk/<party>/*.yaml,
// ssr/<party>.yaml).
//
// In the flat-peer layout these are REAL files at their own paths; the
// only thing the on-disk bytes lack is the path-derived source column
// the aggregate table renders:
//
// - MDL / RSK rows get `$party: <party>` so the cross-party rollup
// can show which party each row came from. The `$` sigil marks the
// field system-synthesised: the tables tool renders it read-only and
// the form client strips it before submit, so a user-defined `party`
// field never collides with the synthetic source-party column.
// - SSR rows get `name: <party>` (the party = the filename) so the
// register table has an identity column to sort on and the form edit
// pre-fills the party name.
//
// Both fields are path-derived and stripped before write-back by the
// tables/form JS (the schema's additionalProperties:false also rejects
// `$party` on submit). Listings: see fs/tree.go.
package handler
import (
"net/http"
"os"
"strconv"
"gopkg.in/yaml.v3"
)
// ServeInjectedRow serves a GET/HEAD for a real register row file with a
// single path-derived field injected (field=value). Used by dispatch for
// the aggregate register rows; ACL is evaluated by the caller against the
// file's own chain. Returns 404 if the file doesn't exist.
func ServeInjectedRow(w http.ResponseWriter, r *http.Request, abs, field, value string) {
raw, err := os.ReadFile(abs)
if err != nil {
if os.IsNotExist(err) {
http.NotFound(w, r)
return
}
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
var data map[string]any
if len(raw) > 0 {
if err := yaml.Unmarshal(raw, &data); err != nil {
http.Error(w, "parse row yaml: "+err.Error(), http.StatusInternalServerError)
return
}
}
if data == nil {
data = make(map[string]any)
}
data[field] = value
out, err := yaml.Marshal(data)
if err != nil {
http.Error(w, "marshal row: "+err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/yaml; charset=utf-8")
w.Header().Set("Cache-Control", "no-store")
w.Header().Set("X-ZDDC-Source", "register-row")
w.Header().Set("Content-Length", strconv.Itoa(len(out)))
if r.Method == http.MethodHead {
w.WriteHeader(http.StatusOK)
return
}
_, _ = w.Write(out)
}