diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0ebc86e..533e103 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -13,7 +13,8 @@ once there are more than 20. > **Read before upgrading.** No option, schema, migration or import-map change. Two points: > **What can stop people:** on a project's own staff collection **without access rules of its own** whose > accounts can hold `editor` or `admin` although its roles are not just the plugin's — a `roles` select such as -> `user, editor, admin, boss` or `viewer, editor`, or a `roles` field that is text or json — an account that is +> `user, editor, admin, boss` or `viewer, editor`, or a `roles` field that is text, json or a relationship (all +> with `hasMany`, i.e. holding a list; a single-valued field is not affected) — an account that is > not an admin can no longer create, delete or unlock accounts there, change another account, or change > anybody's roles. If **no** staff account holds `admin`, nobody can (the start log says so; the way out is > below). And a site **built with Turbopack** (`next build` without `--webpack`): see Security. @@ -26,7 +27,8 @@ once there are more than 20. collection" could create, change and delete accounts. So with roles `user, editor, admin, boss` an account with the role `user` created an `admin` there (or set the admin's password) and then read Site integrations, changed other staff collections' roles and listed the panel's accounts; with `viewer, editor` a `viewer` made - an `editor` who saves Site settings; the same with a `roles` field that is text or json. In 1.16.7 and, wider, + an `editor` who saves Site settings; the same with a `roles` field that is text or a relationship with + `hasMany`, or json (a relationship to documents with text ids holds those ids). In 1.16.7 and, wider, before it. Now such a collection — in the config or added by a later plugin — gets: create, delete, unlock — an admin; update — an admin or the account itself; roles — only an admin. Not affected: `access.authCollection`, collections with rules of their own, a `roles` select whose values hold neither `editor` nor `admin`. No known @@ -42,16 +44,18 @@ once there are more than 20. disk at run time. ### Added -- A start-log warning when staff collections run on the admin rules and no staff account holds `admin`. +- A start-log warning when staff collections run on the admin rules and no staff account holds `admin` + (checked collection by collection; "could not check" where it cannot tell). - `pnpm e2e:built` (plugin repository): builds the reference site with webpack and with Turbopack and checks, on each, the account rules on a built site and that no package manifest is among the public files. Part of the release gate (PROGRAMISTA §8.1). The reference site's Playwright runs reset the test admins first (`e2e/global-setup.ts`), so a spec no longer fails because of what ran before it. -- Exports: `canHoldStaffRole`, `staffCollectionsNobodyManages`. +- Exports: `canHoldStaffRole`, `rolesAreAList`, `staffCollectionsNobodyManages`. ### Requires project changes - **A staff collection of your own, without access rules, whose accounts can hold `editor` or `admin`** (a - `roles` select with one of them next to values of your own, or a text / json `roles` field): only an admin + `roles` select with `hasMany` and one of them next to values of your own, or a `roles` field that is text or a + relationship with `hasMany`, or json): only an admin creates, deletes and unlocks accounts there and changes roles; another account is changed by an admin or by itself. If accounts with a role of your own (`boss`, `viewer`) managed accounts there, write that as the collection's own rules (`access.create` / `update` / `delete`, field access on `roles`) — the plugin gives @@ -67,13 +71,31 @@ once there are more than 20. webpack build. - `pnpm ipal:skills`. +### Changed +- **A single-valued `roles` field no longer brings the admin rules.** The plugin counts roles only from an array, + so an account whose `roles` is one value (`'admin'` in a select without `hasMany`, a radio) was never a plugin + admin. Yet in 1.16.7 a project's own staff collection whose single select offered only `user` / `editor` / + `admin` got the admin rules — and then nobody in it could create, delete or unlock accounts, unless a plugin + admin existed in another staff collection. Such a collection now gets "an account of this collection", like any + collection whose roles are not the plugin's: its accounts manage each other again. Nothing of the plugin's opens: + the value still grants nothing. + ### Known limitations +- **Copied staff collections behave as in 1.16.7**: a plugin listed after ipalKit that spreads a staff collection + into a new slug (`{ ...staff, slug: 'copy' }`) keeps the rules written for the original, so with numeric ids + (Postgres, SQLite) the original's account with the same id can change the copy's account. Not changed in this + release; no known site copies a staff collection. - A staff collection **without a `roles` field** is unchanged: every account of it is an admin to the plugin. - A `roles` select of your own whose values hold neither `editor` nor `admin` is unchanged: inside it every account may create, change and delete accounts (`ipal-doctor --url` → `staff-own-roles`). -- The warning counts accounts whose `roles` hold `admin`; where a `roles` field cannot be queried it says nothing. -- **Not run for this change:** the starter built with Turbopack (it is generated from the reference site and uses - the same plugin code; the reference site was built with both bundlers). +- The plugin judges a collection by its declared `roles` field. A value that a hook of the project's own puts + into `roles` is not seen, and a rule of the project's own (`access.create`, field access on `roles`) replaces + the protection for that operation. +- A relationship `roles` field makes a plugin admin only where the related documents' ids are the role names; over + REST such an account's roles arrive as documents and do not count, over GraphQL and the Local API at depth 0 + they do. The admin rules apply to the collection either way. +- The start-log check reads up to 1000 accounts of a collection whose `roles` field the database cannot be asked + about; with more it says "could not check" for that collection. ## 1.16.7 — hardening diff --git a/docs/access.md b/docs/access.md index 8d731fa..d666d25 100644 --- a/docs/access.md +++ b/docs/access.md @@ -290,21 +290,22 @@ list the staff accounts, and lift the lock after failed logins. | The collection | `create`, `delete`, `unlock` | `update` | the `roles` field (when it has no `access.update`) | `read`, `readVersions` | |---|---|---|---|---| -| carries **the plugin's roles**: it is `access.authCollection`, or has a `roles` select whose values are all `user` / `editor` / `admin` (`hasPluginRoles`), **or one whose accounts can hold `editor` or `admin`**, whatever else its `roles` field offers (`canHoldStaffRole`, below) | an admin (`staffCreateAccess`) | an admin, or the account itself (`staffUpdateAccess(slug)`) | only an admin changes it (`rolesByAdminOnly`) | a staff account (`staffReadAccess`) | +| carries **the plugin's roles**: it is `access.authCollection`, or has a `roles` select **with `hasMany`** whose values are all `user` / `editor` / `admin` (`hasPluginRoles`), **or one whose accounts can hold `editor` or `admin`**, whatever else its `roles` field offers (`canHoldStaffRole`, below) | an admin (`staffCreateAccess`) | an admin, or the account itself (`staffUpdateAccess(slug)`) | only an admin changes it (`rolesByAdminOnly`) | a staff account (`staffReadAccess`) | | has **roles of its own that hold neither `editor` nor `admin`** (`superadmin`, `writer`, …) or no `roles` field — the plugin cannot tell who its admins are | an account of that same collection, or a plugin admin of another staff collection (`sameStaffCollectionAccess(slug)`) | the same | an account never changes its **own** (`rolesNotOwn(slug)`) | a staff account | Always "fully signed in": a session that still owes its second factor passes none of them. **A `roles` field that can hold `editor` or `admin`.** The plugin's checks go by the **value on the account** -(`isAdmin`, `isEditor`): an account of a staff collection whose `roles` hold `admin` is a plugin admin, one that -holds `editor` edits the site's settings — whatever else the field offers. So wherever an account of the -collection **can** hold one of the two, the collection gets the admin rules (`canHoldStaffRole`): +(`isAdmin`, `isEditor`): an account of a staff collection whose `roles` — an **array** — holds `admin` is a plugin +admin, one that holds `editor` edits the site's settings, whatever else the field offers. So wherever an account +of the collection **can** hold one of the two, the collection gets the admin rules (`canHoldStaffRole`): | The collection's `roles` field | Rules | |---|---| -| a select with `editor` or `admin` among its values — `user, editor, admin, boss`; `viewer, editor` | the admin rules (first row above) | -| a field whose values cannot be listed — text, json, a select without options: anything can be written there | the admin rules | -| a select whose values are all your own and hold neither — `lead, member` | "an account of that same collection" (second row) | +| a select **with `hasMany`** and `editor` or `admin` among its values — `user, editor, admin, boss`; `viewer, editor` | the admin rules (first row above) | +| a field that holds a list whose values cannot be listed — text with `hasMany`, json, a relationship with `hasMany` (to documents whose ids are text, the ids are the roles), a select without options, a type the plugin does not know: anything can be written there | the admin rules | +| a select with `hasMany` whose values are all your own and hold neither — `lead, member` | "an account of that same collection" (second row) | +| a field that holds **one** value — a select, text or relationship without `hasMany`, a radio, a number (`rolesAreAList` is false) | second row. The plugin counts roles only from an array: an account whose `roles` is the single value `admin` is **not** a plugin admin, so there is nothing of the plugin's to protect and the collection's accounts keep managing each other | | no `roles` field | second row; every account of it is an admin to the plugin (below) | Otherwise any account of such a collection could hand the value out: create an `admin` and be in Site @@ -315,10 +316,20 @@ plugin's — such an account no longer creates, deletes or unlocks accounts ther anybody's roles. Give it what it needs with rules of your own (`access.create` / `update` / `delete`, field access on `roles`), which win as always. In a collection where nobody can be an `admin` (`viewer, editor`) the accounts are managed by an admin of another staff collection — the panel's. + +**A rule of your own replaces the protection for that operation.** The plugin fills only what you left open: with +your own `create: ({ req }) => Boolean(req.user)` any account still creates an `admin` there; with your own +`access.update: () => true` on the `roles` field an account still raises itself. And the plugin sees the field's +declared values, not your code: a value that a hook of yours puts into `roles` (an `afterRead` that returns +`['admin']` from a checkbox, a virtual field) is not seen — such a collection is judged by its declared field. + **If no staff account holds `admin` at all**, nobody can create, delete or unlock accounts in such a collection. The start log says so: `[ipal] No staff account holds the role "admin", so NOBODY can create, delete or unlock accounts in "…"`. Way out: give one account the role with a script (`payload.update`, Local API), or write the -collection's own rules. +collection's own rules. The check asks each staff collection in the way its field allows (a count for a select, +reading the accounts for text / json / relationship fields, up to 1000 of them); where it cannot check a +collection it says `[ipal] Could not check whether an account of "…" holds the role "admin"` instead and claims +nothing. **Roles of your own — what the plugin does and does not hold.** It cannot rank `superadmin` against `writer`, so inside such a collection it enforces one thing only: an account does not change its own roles. Everything diff --git a/docs/agent/AGENT.md b/docs/agent/AGENT.md index 49f0e11..437d281 100644 --- a/docs/agent/AGENT.md +++ b/docs/agent/AGENT.md @@ -1172,7 +1172,7 @@ add missing hosts with flags / `extra`; (3) change `mode` to `'enforce'` in both | Stored secrets are write-only: `smtpPassword` and `turnstileSecretKey` come back as `'********'` over REST, GraphQL and in the panel; an empty save keeps the value, `'[[clear]]'` removes it; server code reads the real value with the Local API. **The panel is the source — never add an env variable for them** (`TURNSTILE_SECRET_KEY` is deprecated) | `secrets: { writeOnly: false }` | `writeOnlySecret(field)` / `writeOnlySecrets(fields, names)` for your own secret fields; with versions on the entity add `hooks.afterRead: [maskSecretsOnRestore]` | | The SMTP password stays with its server: a save in the panel or over the API that changes the server, port or user name without the password is refused (`400` "Enter the password again…"), whatever the transport says — otherwise an admin session points the server at its own machine and a test e-mail hands the password over. A change of the transport alone asks for nothing. Seeds and scripts (Local API, access control off) are not asked | `secrets: { reenterOnChange: false }` | `writeOnlySecret(field, { boundTo: [...] })`, `buildKeepSecret`, `SMTP_PASSWORD_BOUND_TO` | | The admin panel opens for `editor` and above; an account with only `user` sees "Unauthorized" (the API is not touched). First start logs how many accounts are below the role | `accounts: { panelRole: 'user' }` (or `false`) | `panelRole: 'admin'`; your own `access.admin`; `panelAccess(role)` | -| Nobody creates an account for themselves, or takes one over. A staff collection (also the project's own, also one a later plugin adds) without a `create` / `update` / `delete` / `unlock` / `read` / `readVersions` rule gets one (on a collection a later plugin adds the plugin's rule is put in front of its own and both must allow; `custom: { ipal: { accountRules: false } }` on it keeps its own): with the plugin's roles, or wherever an account of it can hold `editor` or `admin` (`user, editor, admin, boss`; `viewer, editor`; a `roles` field that is text or json — the value on the account makes a plugin admin or editor) — create, delete, unlock: an admin; update: an admin or the account itself; the `roles` field: only an admin. With roles of its own that hold neither `editor` nor `admin`, or none: an account of that same collection, or a plugin admin, and an account never changes its own roles — **the plugin cannot rank a project's own roles: write that collection's rules** (`ipal-doctor` → `staff-own-roles`). `read`: a staff account. Payload's first-user route answers only for the panel's login collection (the first account, which becomes admin), in any spelling of the URL. `access.firstUserAdmin: false` with a default role below the panel role: the default panel role is not applied (logged), an explicit one is refused at start. With a slug in `access.staffCollections` that is not an auth collection Payload does not start (`/api/health` 503) | `accounts: { adminOnlyCreate: false, adminOnlyWrite: false, staffOnlyRead: false, firstUserRoute: 'all' }` | your own rule wins; `firstUserRoute: ['users', 'partners']`; a collection with open sign-up keeps its routes; `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles`, `applyStaffAccountAccess`, `adoptLateAuthCollections`, `buildFirstUserEndpoint` | +| Nobody creates an account for themselves, or takes one over. A staff collection (also the project's own, also one a later plugin adds) without a `create` / `update` / `delete` / `unlock` / `read` / `readVersions` rule gets one (on a collection a later plugin adds the plugin's rule is put in front of its own and both must allow; `custom: { ipal: { accountRules: false } }` on it keeps its own): with the plugin's roles, or wherever an account of it can hold `editor` or `admin` (`user, editor, admin, boss`; `viewer, editor`; a `roles` field that is text, json or a relationship holding a list — the value in the account's `roles` array makes a plugin admin or editor; a single-valued `roles` field is not affected: its value never counts) — create, delete, unlock: an admin; update: an admin or the account itself; the `roles` field: only an admin. With roles of its own that hold neither `editor` nor `admin`, or none: an account of that same collection, or a plugin admin, and an account never changes its own roles — **the plugin cannot rank a project's own roles: write that collection's rules** (`ipal-doctor` → `staff-own-roles`). `read`: a staff account. Payload's first-user route answers only for the panel's login collection (the first account, which becomes admin), in any spelling of the URL. `access.firstUserAdmin: false` with a default role below the panel role: the default panel role is not applied (logged), an explicit one is refused at start. With a slug in `access.staffCollections` that is not an auth collection Payload does not start (`/api/health` 503) | `accounts: { adminOnlyCreate: false, adminOnlyWrite: false, staffOnlyRead: false, firstUserRoute: 'all' }` | your own rule wins; `firstUserRoute: ['users', 'partners']`; a collection with open sign-up keeps its routes; `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles`, `applyStaffAccountAccess`, `adoptLateAuthCollections`, `buildFirstUserEndpoint` | | A password set on a staff account has at least 12 characters and is not the e-mail address; existing passwords are not checked | `accounts: { password: false }` | `password: { minLength }`; `checkPassword`, `buildPasswordRuleHook` | | While Turnstile cannot check (wrong secret, Cloudflare down): a text form is accepted, a form with files is refused | `forms: { turnstileOnConfigError: 'allow' }` | `'reject'`, `{ text, files }`; `turnstileOnConfigError` at a call site wins | | Dashboard alerts by role: integration details for admins, a neutral line for editors, nothing for others; cookie alerts for editors and above. `'all'` checks nothing — no role, no second factor | `dashboardAlerts: { integrations: 'all', cookies: 'all' }` | `integrations: 'editor'`; the components' `details` / `audience` props | diff --git a/docs/agent/skills/ipal-debug/SKILL.md b/docs/agent/skills/ipal-debug/SKILL.md index 3b68f31..c0268f2 100644 --- a/docs/agent/skills/ipal-debug/SKILL.md +++ b/docs/agent/skills/ipal-debug/SKILL.md @@ -104,7 +104,8 @@ through this procedure. Ask only when you are missing something you cannot get y | `POST /api//first-register` answers `403` on an empty collection | `accounts.firstUserRoute`: only the panel's login collection may register its first account that way (the plugin's own endpoint sits in front of Payload's) | an admin creates the account; or the collection's own `create: () => true` (sign-up); or `accounts: { firstUserRoute: [''] }` | | an editor (or a script with its token) gets `403` creating an account in the project's own `users` | `accounts.adminOnlyCreate`: only admins create staff accounts where the roles are the plugin's | create as an admin; or write the collection's `create` rule; or `adminOnlyCreate: false` | | log at start: `[ipal] No staff account holds the role "admin", so NOBODY can create, delete or unlock accounts in "…"` | a staff collection whose accounts can hold `editor` or `admin` runs on the admin rules, and no staff account is an admin | give one account `admin` with a script (`payload.update`, Local API); or write the collection's own `access.create` / `update` / `delete` | -| an account with a role of the project's own (`boss`, `viewer`) gets `403` creating or editing accounts in its staff collection (it worked on 1.16.7) | the collection's `roles` can hold `editor` or `admin` (a select with one of them, or a text / json field): the admin rules apply | do it as an admin; or write the collection's own rules for that role | +| an account with a role of the project's own (`boss`, `viewer`) gets `403` creating or editing accounts in its staff collection (it worked on 1.16.7) | the collection's `roles` can hold `editor` or `admin` (a select with `hasMany` and one of them, or a text / relationship field with `hasMany`, or json; a single-valued field is not affected): the admin rules apply | do it as an admin; or write the collection's own rules for that role | +| log at start: `[ipal] Could not check whether an account of "…" holds the role "admin"` | the accounts of that staff collection could not be read or are more than 1000, and no other staff account is an admin | make sure one account holds `admin`; nothing is wrong if one does | | an account gets `403` changing or deleting ANOTHER account of a staff collection (it worked before) | `accounts.adminOnlyWrite`: an admin, or the account itself (update only); on a collection with roles of its own: accounts of that collection | do it as an admin; or write the collection's `update` / `delete` rule; or `adminOnlyWrite: false` | | an account saves its own profile and its `roles` do not change (no error) | `accounts.adminOnlyWrite`: nobody changes its own roles; with the plugin's roles only an admin changes roles | an admin changes the role; or give the `roles` field its own `access.update` | | a logged-in visitor (customer) gets `403` reading a staff collection — an author box went empty | `accounts.staffOnlyRead`: only staff accounts read a staff collection without a `read` rule | write that collection's `read` rule; or `staffOnlyRead: false` | diff --git a/docs/agent/skills/ipal-reference/resources/api.md b/docs/agent/skills/ipal-reference/resources/api.md index dccc47d..ada3950 100644 --- a/docs/agent/skills/ipal-reference/resources/api.md +++ b/docs/agent/skills/ipal-reference/resources/api.md @@ -67,8 +67,8 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `isAdmin(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with the `admin` role (see `hasMinimumRole`). In hooks and endpoints: `isAdmin(req.user, req.payload)`; in a client component: `isAdmin(user, config)` from `/client` — the main entry does not build there with webpack (`'server-only' cannot be imported…`). | | `isEditor(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with `editor` or higher. | | `panelAccess(minimum?)`, `applyPanelRole(config, slug, role)`, `resolvePanelRole(option)`, `countBelowPanelRole(payload, slug, role)`, `DEFAULT_PANEL_ROLE` | `@intecion/ipal-kit` | `accounts.panelRole`: an `access.admin` function ("holds at least `minimum`", default `'editor'`; role only, not the second factor); the applier (skips a collection that has its own `access.admin`); the option → role or `null` when off; `{ all, below }` counts for the start-up line; `'editor'`. | -| `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles(collection)`, `canHoldStaffRole(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, read?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead`: the access functions — "an admin, fully signed in" (create, delete, unlock); "an admin, or the account itself" (update; self = an account of THAT collection); "a fully signed-in account of a staff collection" (read); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); the two field-access functions for a `roles` field (`update`: only an admin / never the account itself); whether a collection carries the plugin's roles (a `roles` select at the top level of the data with only `user` / `editor` / `admin`); whether an account of it can hold `editor` or `admin` whatever else the field offers (a select with one of them among its values, or a `roles` field whose values cannot be listed — text, json) — then the admin rules apply too; the applier — puts the rules on the named staff collections for the operations that have none and closes the `roles` field where the plugin's `update` rule is in force, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | -| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)`, `staffCollectionsNobodyManages(payload, staffSlugs, except?)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | `staffCollectionsNobodyManages` (async): staff collections on the admin rules while no staff account is a plugin admin — nobody can create, delete or unlock accounts there (the plugin warns at start). +| `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles(collection)`, `canHoldStaffRole(collection)`, `rolesAreAList(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, read?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead`: the access functions — "an admin, fully signed in" (create, delete, unlock); "an admin, or the account itself" (update; self = an account of THAT collection); "a fully signed-in account of a staff collection" (read); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); the two field-access functions for a `roles` field (`update`: only an admin / never the account itself); whether a collection carries the plugin's roles (a `roles` select with `hasMany` at the top level of the data with only `user` / `editor` / `admin`); whether an account of it can hold `editor` or `admin` whatever else the field offers (a select with one of them among its values, or a `roles` field whose values cannot be listed — text, json, a relationship) — then the admin rules apply too; whether the `roles` field can put an ARRAY on the account at all (select / text / relationship need `hasMany`; radio, number, date, checkbox never do) — the plugin counts roles only from an array, so a single-valued field brings no admin rules; the applier — puts the rules on the named staff collections for the operations that have none and closes the `roles` field where the plugin's `update` rule is in force, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | +| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)`, `staffCollectionsNobodyManages(payload, staffSlugs, except?)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | `staffCollectionsNobodyManages` (async) → `{ stuck, unchecked }`: `stuck` — staff collections on the admin rules while no staff account is a plugin admin (nobody can create, delete or unlock accounts there; the plugin warns at start); `unchecked` — staff collections whose accounts could not be checked, in which case nothing is claimed. Each collection is asked in the way its field allows. | `checkPassword(password, { email?, minLength? })`, `buildPasswordRuleHook({ minLength? })`, `applyPasswordRule(config, slugs, rule)`, `resolvePasswordRule(option)`, `DEFAULT_PASSWORD_MIN_LENGTH` | `@intecion/ipal-kit` | `accounts.password`: `'short' \| 'email' \| null` for a new password (length in characters); the `beforeOperation` hook for `create` / `update` / `resetPassword` (throws Payload's `ValidationError` on `password`, text in the panel's language; the account's address is looked up by id, reset token or bulk query when the request carries none; a password that is not text is refused; login is never checked); the applier; the option → `{ minLength }` or `null`; `12`. | | `writeOnlySecret(field, options?)`, `writeOnlySecrets(fields, names, optionsByName?)`, `maskSecretAfterRead`, `keepSecretBeforeValidate`, `buildKeepSecret(options?)`, `SECRET_MASK`, `SECRET_CLEAR`, `isSecretMask(value)`, `INTEGRATION_SECRET_FIELDS`, `SMTP_PASSWORD_BOUND_TO` | `@intecion/ipal-kit` | Write-only secret fields (`secrets.writeOnly`): the wrapper for one field and for named fields anywhere in a tree (tabs, rows, groups); the two field hooks (reads through access control get `'********'`, the Local API with access control off gets the value; a save with nothing / empty / the mask keeps the stored value, `'[[clear]]'` removes it); the hook builder with options — `{ boundTo: ['siblingField'], appliesWhen?: (siblingData) => boolean }`: a save through access control that changes a bound sibling field without sending the secret throws a `ValidationError` on the secret (`secrets.reenterOnChange`); the two constants; the plugin's own secret field names (`smtpPassword`, `turnstileSecretKey`); the fields the SMTP password is bound to (`smtpHost`, `smtpPort`, `smtpUser` — not the transport: the mail adapter may fall back to SMTP). | | `maskSecretsOnRestore`, `maskWriteOnlySecrets(data, fields)` | `@intecion/ipal-kit` | Versions and write-only secrets: the `afterRead` hook for a global or a collection (a restore answers with the version document, fields under `version`, where field hooks do not run — it masks them there for reads through access control); the walker it uses (masks every write-only field in `data`, following tabs, rows, groups, arrays and blocks). On Site integrations by default; add the hook to your own entity that has both. | diff --git a/docs/agent/skills/ipal-upgrade/SKILL.md b/docs/agent/skills/ipal-upgrade/SKILL.md index dee04a5..3966a74 100644 --- a/docs/agent/skills/ipal-upgrade/SKILL.md +++ b/docs/agent/skills/ipal-upgrade/SKILL.md @@ -460,7 +460,8 @@ account → "Two-step verification: Set up." and the reset button; delete the ac `roles` field — only an admin (when the field has no `access.update` of its own). **Check:** does a non-admin create or edit other accounts, or change roles, there today? Then write the rule you want; - an account of the collection **can hold `editor` or `admin`** although its roles are not just the plugin's - (`user, editor, admin, boss`; `viewer, editor`; a `roles` field that is text or json): the admin rules too, + (`user, editor, admin, boss`; `viewer, editor`; a `roles` field that is text, json or a relationship) — the + field must hold a LIST (`hasMany`; a single-valued `roles` is not affected, its value never counts): the admin rules too, since the release after 1.16.7 (the value on the account makes a plugin admin or editor). **Check:** do accounts with one of your own roles (`boss`, `viewer`) manage accounts there? Then write that as the collection's own rules. Read the start log: `No staff account holds the role "admin", so NOBODY can create, diff --git a/reference/.agents/skills/ipal-debug/SKILL.md b/reference/.agents/skills/ipal-debug/SKILL.md index 3b68f31..c0268f2 100644 --- a/reference/.agents/skills/ipal-debug/SKILL.md +++ b/reference/.agents/skills/ipal-debug/SKILL.md @@ -104,7 +104,8 @@ through this procedure. Ask only when you are missing something you cannot get y | `POST /api//first-register` answers `403` on an empty collection | `accounts.firstUserRoute`: only the panel's login collection may register its first account that way (the plugin's own endpoint sits in front of Payload's) | an admin creates the account; or the collection's own `create: () => true` (sign-up); or `accounts: { firstUserRoute: [''] }` | | an editor (or a script with its token) gets `403` creating an account in the project's own `users` | `accounts.adminOnlyCreate`: only admins create staff accounts where the roles are the plugin's | create as an admin; or write the collection's `create` rule; or `adminOnlyCreate: false` | | log at start: `[ipal] No staff account holds the role "admin", so NOBODY can create, delete or unlock accounts in "…"` | a staff collection whose accounts can hold `editor` or `admin` runs on the admin rules, and no staff account is an admin | give one account `admin` with a script (`payload.update`, Local API); or write the collection's own `access.create` / `update` / `delete` | -| an account with a role of the project's own (`boss`, `viewer`) gets `403` creating or editing accounts in its staff collection (it worked on 1.16.7) | the collection's `roles` can hold `editor` or `admin` (a select with one of them, or a text / json field): the admin rules apply | do it as an admin; or write the collection's own rules for that role | +| an account with a role of the project's own (`boss`, `viewer`) gets `403` creating or editing accounts in its staff collection (it worked on 1.16.7) | the collection's `roles` can hold `editor` or `admin` (a select with `hasMany` and one of them, or a text / relationship field with `hasMany`, or json; a single-valued field is not affected): the admin rules apply | do it as an admin; or write the collection's own rules for that role | +| log at start: `[ipal] Could not check whether an account of "…" holds the role "admin"` | the accounts of that staff collection could not be read or are more than 1000, and no other staff account is an admin | make sure one account holds `admin`; nothing is wrong if one does | | an account gets `403` changing or deleting ANOTHER account of a staff collection (it worked before) | `accounts.adminOnlyWrite`: an admin, or the account itself (update only); on a collection with roles of its own: accounts of that collection | do it as an admin; or write the collection's `update` / `delete` rule; or `adminOnlyWrite: false` | | an account saves its own profile and its `roles` do not change (no error) | `accounts.adminOnlyWrite`: nobody changes its own roles; with the plugin's roles only an admin changes roles | an admin changes the role; or give the `roles` field its own `access.update` | | a logged-in visitor (customer) gets `403` reading a staff collection — an author box went empty | `accounts.staffOnlyRead`: only staff accounts read a staff collection without a `read` rule | write that collection's `read` rule; or `staffOnlyRead: false` | diff --git a/reference/.agents/skills/ipal-reference/resources/api.md b/reference/.agents/skills/ipal-reference/resources/api.md index dccc47d..ada3950 100644 --- a/reference/.agents/skills/ipal-reference/resources/api.md +++ b/reference/.agents/skills/ipal-reference/resources/api.md @@ -67,8 +67,8 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `isAdmin(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with the `admin` role (see `hasMinimumRole`). In hooks and endpoints: `isAdmin(req.user, req.payload)`; in a client component: `isAdmin(user, config)` from `/client` — the main entry does not build there with webpack (`'server-only' cannot be imported…`). | | `isEditor(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with `editor` or higher. | | `panelAccess(minimum?)`, `applyPanelRole(config, slug, role)`, `resolvePanelRole(option)`, `countBelowPanelRole(payload, slug, role)`, `DEFAULT_PANEL_ROLE` | `@intecion/ipal-kit` | `accounts.panelRole`: an `access.admin` function ("holds at least `minimum`", default `'editor'`; role only, not the second factor); the applier (skips a collection that has its own `access.admin`); the option → role or `null` when off; `{ all, below }` counts for the start-up line; `'editor'`. | -| `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles(collection)`, `canHoldStaffRole(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, read?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead`: the access functions — "an admin, fully signed in" (create, delete, unlock); "an admin, or the account itself" (update; self = an account of THAT collection); "a fully signed-in account of a staff collection" (read); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); the two field-access functions for a `roles` field (`update`: only an admin / never the account itself); whether a collection carries the plugin's roles (a `roles` select at the top level of the data with only `user` / `editor` / `admin`); whether an account of it can hold `editor` or `admin` whatever else the field offers (a select with one of them among its values, or a `roles` field whose values cannot be listed — text, json) — then the admin rules apply too; the applier — puts the rules on the named staff collections for the operations that have none and closes the `roles` field where the plugin's `update` rule is in force, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | -| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)`, `staffCollectionsNobodyManages(payload, staffSlugs, except?)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | `staffCollectionsNobodyManages` (async): staff collections on the admin rules while no staff account is a plugin admin — nobody can create, delete or unlock accounts there (the plugin warns at start). +| `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles(collection)`, `canHoldStaffRole(collection)`, `rolesAreAList(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, read?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead`: the access functions — "an admin, fully signed in" (create, delete, unlock); "an admin, or the account itself" (update; self = an account of THAT collection); "a fully signed-in account of a staff collection" (read); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); the two field-access functions for a `roles` field (`update`: only an admin / never the account itself); whether a collection carries the plugin's roles (a `roles` select with `hasMany` at the top level of the data with only `user` / `editor` / `admin`); whether an account of it can hold `editor` or `admin` whatever else the field offers (a select with one of them among its values, or a `roles` field whose values cannot be listed — text, json, a relationship) — then the admin rules apply too; whether the `roles` field can put an ARRAY on the account at all (select / text / relationship need `hasMany`; radio, number, date, checkbox never do) — the plugin counts roles only from an array, so a single-valued field brings no admin rules; the applier — puts the rules on the named staff collections for the operations that have none and closes the `roles` field where the plugin's `update` rule is in force, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | +| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)`, `staffCollectionsNobodyManages(payload, staffSlugs, except?)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | `staffCollectionsNobodyManages` (async) → `{ stuck, unchecked }`: `stuck` — staff collections on the admin rules while no staff account is a plugin admin (nobody can create, delete or unlock accounts there; the plugin warns at start); `unchecked` — staff collections whose accounts could not be checked, in which case nothing is claimed. Each collection is asked in the way its field allows. | `checkPassword(password, { email?, minLength? })`, `buildPasswordRuleHook({ minLength? })`, `applyPasswordRule(config, slugs, rule)`, `resolvePasswordRule(option)`, `DEFAULT_PASSWORD_MIN_LENGTH` | `@intecion/ipal-kit` | `accounts.password`: `'short' \| 'email' \| null` for a new password (length in characters); the `beforeOperation` hook for `create` / `update` / `resetPassword` (throws Payload's `ValidationError` on `password`, text in the panel's language; the account's address is looked up by id, reset token or bulk query when the request carries none; a password that is not text is refused; login is never checked); the applier; the option → `{ minLength }` or `null`; `12`. | | `writeOnlySecret(field, options?)`, `writeOnlySecrets(fields, names, optionsByName?)`, `maskSecretAfterRead`, `keepSecretBeforeValidate`, `buildKeepSecret(options?)`, `SECRET_MASK`, `SECRET_CLEAR`, `isSecretMask(value)`, `INTEGRATION_SECRET_FIELDS`, `SMTP_PASSWORD_BOUND_TO` | `@intecion/ipal-kit` | Write-only secret fields (`secrets.writeOnly`): the wrapper for one field and for named fields anywhere in a tree (tabs, rows, groups); the two field hooks (reads through access control get `'********'`, the Local API with access control off gets the value; a save with nothing / empty / the mask keeps the stored value, `'[[clear]]'` removes it); the hook builder with options — `{ boundTo: ['siblingField'], appliesWhen?: (siblingData) => boolean }`: a save through access control that changes a bound sibling field without sending the secret throws a `ValidationError` on the secret (`secrets.reenterOnChange`); the two constants; the plugin's own secret field names (`smtpPassword`, `turnstileSecretKey`); the fields the SMTP password is bound to (`smtpHost`, `smtpPort`, `smtpUser` — not the transport: the mail adapter may fall back to SMTP). | | `maskSecretsOnRestore`, `maskWriteOnlySecrets(data, fields)` | `@intecion/ipal-kit` | Versions and write-only secrets: the `afterRead` hook for a global or a collection (a restore answers with the version document, fields under `version`, where field hooks do not run — it masks them there for reads through access control); the walker it uses (masks every write-only field in `data`, following tabs, rows, groups, arrays and blocks). On Site integrations by default; add the hook to your own entity that has both. | diff --git a/reference/.agents/skills/ipal-upgrade/SKILL.md b/reference/.agents/skills/ipal-upgrade/SKILL.md index dee04a5..3966a74 100644 --- a/reference/.agents/skills/ipal-upgrade/SKILL.md +++ b/reference/.agents/skills/ipal-upgrade/SKILL.md @@ -460,7 +460,8 @@ account → "Two-step verification: Set up." and the reset button; delete the ac `roles` field — only an admin (when the field has no `access.update` of its own). **Check:** does a non-admin create or edit other accounts, or change roles, there today? Then write the rule you want; - an account of the collection **can hold `editor` or `admin`** although its roles are not just the plugin's - (`user, editor, admin, boss`; `viewer, editor`; a `roles` field that is text or json): the admin rules too, + (`user, editor, admin, boss`; `viewer, editor`; a `roles` field that is text, json or a relationship) — the + field must hold a LIST (`hasMany`; a single-valued `roles` is not affected, its value never counts): the admin rules too, since the release after 1.16.7 (the value on the account makes a plugin admin or editor). **Check:** do accounts with one of your own roles (`boss`, `viewer`) manage accounts there? Then write that as the collection's own rules. Read the start log: `No staff account holds the role "admin", so NOBODY can create,