Repository navigation
Conversation
An author or admin publishes one of their saved reports as a public page showing one succeeded run of its report, edits the page's summary, authors, tags and content, moves it to newer runs as versions, and withdraws it. Anyone reads the published page by the saved report's ID, with the run of its newest version, or an earlier one while the author shows past versions. The database deletes the page with its saved report or account, refuses to repoint a published saved report, and keeps every run a page has shown. These tests fail until the published_reports package, tables and routes exist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An author or admin publishes one of their saved reports as a public,
read-only page linked by the saved report's ID: POST
/v2/user-reports/{id}/publication with the run it shows (a report run, or
a budget window's budget-window run, which must have succeeded), a summary,
author IDs from the website's authors.json, tags and content (Markdown and
output-card blocks; a card left out is removed). The owner reads the page
with every version, edits its fields, moves it to another succeeded run as
a new version, and withdraws it. Publishing, editing and moving need author
or above; reading and withdrawing need only ownership. Anyone reads a
published report at GET /v2/published-reports/{id}, with the run of its
newest version, or an earlier one while the author shows past versions,
the saved report's presentation as a shared report shows it, and the report
as GET /v2/reports/{id}?run_id= answers it, without the owner or the
owner's notes.
The revision adds published_reports and published_report_versions, and a
unique constraint on user_report_associations (id, report_id) for the
published report's composite foreign key: deleting the saved report or the
owner's account deletes the page, and repointing a published saved report
is refused. The user-report PATCH refuses it with 409 first. The generated
revision created that unique constraint after the table that references
it, which PostgreSQL refuses, so its order is corrected and documented.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A page read while its withdrawal commits finds no versions, and answers not found. A published saved report's name, the page's title, can't be cleared. A page within the content limits written in three-byte characters fits the request limit. The PostgreSQL refusals name the constraint they rely on, and the keys that refuse a second publish or a second version of one run are tested, as is a succeeded forced run. The service's reads hand the routes typed content blocks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A published report read while its page is withdrawn, or its saved report deleted, finds no versions; the public read now answers 404 and the owner's reads not found, where the empty list raised IndexError and answered 500. A published saved report's name is its page's title, so the user-report PATCH refuses to clear it (409), as it refuses repointing. The service hands the routes typed content blocks. The request limit is 16 MiB, which fits a page at the content limits whatever its characters. The user-report PATCH and DELETE descriptions say what publishing changes, the publication routes' 403 text says which need an author, and the Alembic skill documents the revision and its one correction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A saved report named only blanks has no title, so it can't be published, and a published saved report's name can't be blanked. Each write locks the row it checks: a publish and a saved report's edit lock the saved report, and a page's edit, move and withdrawal lock the page. An edit sends at least one field, and the edit schema shows no field as nullable. Each owner route lists only its own failures. Tests also cover a signed-out browser on the owner routes and a budget window published on PostgreSQL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A saved report's name made only of blanks counts as none: it can't be published, and a published saved report's name can't be blanked. A publish and the saved report's PATCH now lock the saved report's row, so a name can't be cleared while a publish reads it, and a page's edit, move and withdrawal lock the page's row, so an edit no longer runs on a page just withdrawn (it answered 503 when its UPDATE matched no row); it now waits, then answers 404. An edit must send at least one field, and its schema shows no field as nullable. Each owner route lists only its own failures. The two empty-versions guards are one. The downgrade test grants the roles' privileges again after it upgrades, and the migration document says the export doesn't include published pages yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A summary or Markdown block holding a NUL character, which PostgreSQL can't store, is refused as malformed. Each write route lists only its own 404 and 409 causes, the edit none of a publish's or a move's, and the edit schema needs at least one property. A budget window's published page is read through the report service on PostgreSQL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A summary or Markdown block holding a NUL character, which PostgreSQL can't store, is refused as malformed (422); it answered 503 when the database refused the write. The publish, the edit and the move each list their own 404 and 409 causes, the edit none, and the edit schema needs at least one property. The publish locks the saved report through the user-report connector instead of a copy of it, the saved report's PATCH asks the published-report connector whether it is published, and one check decides a blank name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4356
Summary
Authors and admins can publish one of their saved reports as a public, read-only page that research posts can link to, and anyone can read it without signing in (tracker task D6 · 1 of the detailed-save API migration).
Owner routes (
/v2/user-reports/{id}/publication, the user-report routes' credentials):POSTpublishes the saved report, showing one succeeded run of the detailed-save report it names: a report run, or a budget window's budget-window run. It takes a summary (1–300 characters), author IDs from the website'sauthors.json(1–10), tags (up to 20), content andshow_past_versions. Content is an ordered list of at most 100 Markdown blocks (each at most 20,000 characters, with no NUL character) and output-card blocks, keyed by v3's names; a card left out is removed. Request bodies are at most 16 MiB.PATCHedits the page's fields: at least one, none as null.POST …/publication/versionsmoves the page to another succeeded run as a new version.GETreads the page with every version.DELETEwithdraws it.Public read:
GET /v2/published-reports/{id}?country_id=&version_id=needs no credential and never provisions a user. It answers:/v2/shared-reportsshows it;show_past_versionsis on, else only the newest);GET /v2/reports/{id}?run_id=answers it.It never exposes the owner, the saved report's
description(the owner's notes) or the owner's saved-reform IDs.Tables (one autogenerated v2 revision,
8c867f67f87f):published_reports, keyed by the saved report's ID.published_report_versions, which names exactly one run per row; a run a page has shown can't be deleted.user_report_associations (id, report_id). It backs the published report's composite foreign key (ON DELETE CASCADE,ON UPDATE RESTRICT): deleting the saved report or the owner's account deletes the page, and repointing a published saved report is refused.Repointing and the title: the user-report
PATCHanswers 409 when it would repoint a published saved report, or clear or blank its name, the page's title.Locks: a publish and the saved report's
PATCHlock the saved report's row; a page's edit, move and withdrawal lock the page's row. Each write waits for another write of the same row.Revision correction: Alembic generated the unique constraint after the table that references it, which PostgreSQL refuses. The upgrade creates it first and the downgrade drops it last. The revision's docstring records this, and an integration test downgrades and upgrades.
Privileges: API v1's runtime role gets
SELECT, INSERT, UPDATE, DELETEonpublished_reportsandSELECT, INSERT, DELETEonpublished_report_versions; no other role gets access.Migration notes:
published-reportsjoins thereportroute group;docs/generated/migration_contracts.jsonanddocs/engineering/migration-contracts.mdare regenerated.# noqa: E402, on the new model module's import inpolicyengine_api/data/v2/models/__init__.py. Like the package's other model imports, it must follow the naming convention set at the top of the module.Testing
5c8aa3173), then the change (e587842cd). Three rounds of adversarial review followed, each fixed test-first (failing tests, then fixes).alembic -c alembic-v2.ini check,lint-imports,python -m scripts.rules validate,python scripts/run_quality_guards.py, ruff, ruff format and mypy all pass.🤖 Generated with Claude Code