Add authorized document registration (#17) #50
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
primatekuntech/rag-rust!50
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/17-document-registration"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #17.
What this adds
Authorized document registration. A custodian with an
Uploadgrant registers UTF-8 text or Markdown with a full marking; every accepted version is quarantined and nothing is searchable yet (extraction/publication is #18).POST /api/v1/documents,POST /api/v1/documents/{id}/versions,GET /api/v1/documents/{id}(201 / 200 replay / 400 / 401 / 403 / 404 / 409 / 413 / 503; no-store).Idempotency-Keyis mandatory.bytea, INSERT-only), ingestion job, outbox eventdocument.version.registered(ids only) and an audit row (version/size/hash only; no titles, labels or content).quarantinedversions and can only selectactiveones.rag-domaingains theDocumentRegistryport; new craterag-ingestionholds validation and the service;rag-storage-postgresimplements the registry;rag-apiadds routes and an oracle-safeDocumentLoader.0008_documents.sql: composite org FKs, FORCE RLS, INSERT-only grants on originals/jobs/audit_events/ingestion_outbox; the startup privilege check now covers column-level grants.docs/operations/documents.md, plan indocs/superpowers/plans/2026-10-23-document-registration.md, evidence sentences indocs/decisions.mdOD-07/OD-13 (status unchanged, still proposals).Verification
cargo fmt --check,clippy --workspace --all-targets -D warnings,cargo test --workspace --lockedpass, and all 12 real-PostgreSQL suites pass viabash scripts/test-postgres.sh --local(new: schema 11, registry 14, api 18). The coverage script was not run locally; CI will run it (it now includes the three new suites).Disclosure: on one full run, two tests in
documents_registry_postgresfailed once (refused_writes_one_audit_row_with_reason_only,active_attributes_hides_quarantined_and_returns_latest_active). The output was not captured and I could not reproduce it (about ten reruns, standalone and in the full script, all green). Cause unexplained.Rulings made during implementation
document_submissionsalso stores version, size and content hash so a replay rebuilds the receipt without reading quarantined rows. Cost if wrong: additive migration.replayedis computed at read time, never stored.DOCUMENT_MAX_BYTES(default 2097152) is validated only when identity is enabled, since the routes mount only then.Bodyand reading after session and key checks.groupreturns the uniform 404 (policy denial), not 400. Documented; nothing stored.Also from the plan: dev grant defaults/policy gain
Upload(placeholder until #14); revisions are owner-only; originals live in PostgreSQL rather than a filesystem/object store.Deferred minors
No-group 404 vs 400;
ActiveDocumentDebug includes the title; originals/jobs RLS bind org only (owner bound in the registry transaction);next_versioncan be set backwards by the owner; column-privilege hardening for older tables (pre-existing); a few test-coverage gaps.Synthetic data only; no production or approval claims.
🤖 Generated with Claude Code
POST /api/v1/documents and /api/v1/documents/{id}/versions register quarantined versions through the ingestion service after origin, CSRF, session and Idempotency-Key checks; GET /api/v1/documents/{id} returns the latest active version's metadata through the Enforcer with the new database-backed DocumentLoader, building the body from the same read the decision was made on. Absent, foreign, quarantined and corrupt documents are the uniform 404; store failures are 503 for every id alike. main.rs mounts the routes with identity, reads DOCUMENT_MAX_BYTES (default 2097152, invalid stops startup) and adds Upload to the development grants and policy. Real-PostgreSQL suite documents_api_postgres is registered in scripts/test-postgres.sh. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>