readPublished on version history: readPublishedVersions, and the documented form works (1.17.2)

readVersions: readPublished(), as access.md showed, answered every version read with 500 on
MongoDB, Postgres and SQLite: the rule returns the document's `_status` path, a version query
runs on the versions collection where the status is `version._status` (SQL: "Cannot find field
for path at _status"; MongoDB: TypeError in sanitizeQueryValue). Reported by a client project
upgrading to 1.17.1.

- readPublishedVersions(minimum): the version form, for readVersions.
- readPublished() carries a symbol mark (READ_PUBLISHED); iapl() swaps it on readVersions of the
  collections and globals it sees (withVersionReadRules, exported for plugins listed after it).
- Tests on the three adapters: the version list (REST, depth 0/2, Local API, GraphQL), one version
  by id, the count, a global, an explicit role; the 1.17.1 HTTP test now checks the status too.
- access.md says where each rule goes; AGENT.md, iapl-collection and iapl-audit skills.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 10:39:41 +01:00
co-authored by Claude Opus 5.5
parent fc70a34f3e
commit 4b17254135
10 changed files with 252 additions and 12 deletions
+18 -2
View File
@@ -195,10 +195,26 @@ access: { update: requireRole('editor') }
// a collection with drafts: editors (or the role you name) read everything; visitors, plain `user` accounts and a
// session that still owes its second factor read published documents only — by id, in lists, with ?draft=true and
// over GraphQL. Payload's open `read: () => true` answers ?draft=true with the draft itself (1.17.1).
access: { read: readPublished(), readVersions: readPublished() }
access: { read: readPublished('admin') }
// Version history asks for the status at another path: readPublishedVersions() goes on readVersions (1.17.2).
access: { read: readPublished(), readVersions: readPublishedVersions() }
access: { read: readPublished('admin'), readVersions: readPublishedVersions('admin') }
```
**Where each rule may be used.**
| Rule | Where | What a visitor gets |
|---|---|---|
| `readPublished()` | `access.read` of a collection or global with `versions: { drafts: true }` | published documents: by id, lists, `?draft=true`, GraphQL |
| `readPublishedVersions()` | `access.readVersions` of the same collection or global | published versions: the version list, one version by id (a draft one: `403`), the count, GraphQL, the panel's version view |
The two answer with different paths: a document has `_status`, a version has `version._status`. In 1.17.1,
`readVersions: readPublished()` (the form these docs showed) answered every version read with **500** on MongoDB,
Postgres and SQLite. Since 1.17.2, iapl() swaps a `readPublished()` it finds on `readVersions` of a collection or
global for `readPublishedVersions()` with the same role, so that form works too. A collection added by a plugin
listed **after** iapl() is not seen: use `readPublishedVersions()` there, or `withVersionReadRules(collections)`.
Neither rule belongs on a collection without drafts (no `_status`: every read would fail). Check: without a session,
`GET /api/<slug>/versions?limit=10` → `200` with published versions only, never `500`.
A role name the plugin does not know (`requireRole('Admin')`, `readPublished('superadmin')`) throws where the rule
is written; `hasMinimumRole` / `userMeetsRole` answer `false` for it (before 1.17.1 every staff account met it).
`readPublished` with `?draft=true` on a page whose newest version is a draft answers a visitor `404` (Payload applies