M1 review round 3: a built-site e2e for a late staff collection (both bundlers); docs follow

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 00:39:24 +01:00
co-authored by Claude Fable 5.2
parent 6e0ad26b2c
commit 8a01c72c2a
22 changed files with 216 additions and 32 deletions
+2 -1
View File
@@ -106,7 +106,8 @@ through this procedure. Ask only when you are missing something you cannot get y
| 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` |
| the site does not start: `[ipal] access names "…" as a staff collection, but this config has no auth collection with that slug` | a slug in `access.staffCollections` / `access.authCollection` is not an auth collection (a typo, a removed collection) | fix the slug or add the collection |
| `/api/health` answers 503, the panel and `/api/*` 500 after a deploy; log: `[ipal] access names "…" as a staff collection, but this config has no auth collection with that slug` | a slug in `access.staffCollections` / `access.authCollection` is not an auth collection (a typo, a removed collection): Payload does not start, the process stays up (with a health check Coolify keeps the old container) | fix the slug or add the collection |
| a collection added by a plugin listed after ipalKit refuses what its own access rule allows | it is in `access.staffCollections`: the plugin's account rules are put in front of its rules and both must allow (the log at start lists what was put) | `custom: { ipal: { accountRules: false } }` on that collection, or list that plugin before ipalKit |
| a fresh site with `access.firstUserAdmin: false`: the first account sees "Unauthorized", or the start fails with `leaves a fresh site with nobody who can open the panel` | the first account gets the default role, below the panel role | `access.defaultRole: 'editor'`, or `accounts: { panelRole: false }`, or drop `firstUserAdmin: false` |
| saving Site integrations fails on the password field: "Enter the password again…" | the server, port or user name changed and the stored SMTP password is kept only for the settings it was saved with — also when the transport says Microsoft Graph | type the password again; or "Remove the stored value" for a server without one; a seed with the Local API is not asked; `secrets: { reenterOnChange: false }` |
| creating an account / changing a password fails with "The password must have at least 12 characters." | `accounts.password` (applies to new passwords of staff accounts, in scripts too) | a longer password; `accounts: { password: { minLength } }` or `false` |
@@ -35,7 +35,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip
| `accounts.panelRole` | `'editor'` | the lowest role that may open the admin panel (Payload's `access.admin` on the collection with the roles): an account with only `user` sees "Unauthorized"; the API is not touched; the role decides, not the second factor. First start logs `N account(s) … cannot open the admin panel` (an error when it is everyone). Needs `access` | `'user'` / `false` = everyone, as before; `'admin'`; your own `access.admin` / `access.authAccess.admin` wins |
| `accounts.adminOnlyCreate` | on | a staff collection (panel login collection, `access.authCollection`, `access.staffCollections`) without a `create` rule gets one instead of Payload's "any logged-in user" — also the project's own collection. With the plugin's roles (`access.authCollection`, or a `roles` select with only `user` / `editor` / `admin`): an admin, fully signed in. With roles of its own, or none: an account of that same collection, or a plugin admin of another staff collection | `false` = Payload's default; a `create` rule you wrote always wins |
| `accounts.adminOnlyWrite` | on | the same for `update`, `delete` and `unlock`: with the plugin's roles — update: an admin or the account itself; delete, unlock: an admin; otherwise an account of that same collection, or a plugin admin. With it the collection's `roles` field (when it has no `access.update`) is closed for self-promotion: with the plugin's roles only an admin changes roles; with role values of the project's own an account never changes its own (the plugin cannot rank them — write that collection's rules). Closes Payload's default, under which a visitor account could change a staff account's password | `false` = Payload's default, the `roles` field left alone; rules you wrote always win |
| `accounts.staffOnlyRead` | on | `read` on a staff collection without a `read` rule: a fully signed-in account of a staff collection (Payload's default let a visitor account list the staff accounts) | `false` = Payload's default; a `read` rule you wrote wins |
| `accounts.staffOnlyRead` | on | `read` and `readVersions` on a staff collection without those rules: a fully signed-in account of a staff collection (Payload's default let a visitor account list the staff accounts) | `false` = Payload's default; a `read` rule you wrote wins |
| `accounts.firstUserRoute` | `'panel'` | which auth collections `POST /api/<slug>/first-register` answers for while they are empty: only the one the panel logs in with (the first account of a site → admin). Others get `403`, a second staff collection included, in any spelling of the URL (the plugin's own endpoint sits in front of Payload's); a collection whose own `create` allows an anonymous request keeps its route. With `access.firstUserAdmin: false` and a default role below the panel role, the default `panelRole` is not applied (logged) and an explicit one is refused at start | a list of slugs; `'all'` = Payload's behaviour |
| `accounts.password` | `{ minLength: 12 }` | when a password is SET on a staff collection (create, first-user screen, change, reset by e-mail; panel, API and Local API): at least `minLength` characters, not the account's e-mail address. Existing passwords are never checked — a shorter one keeps logging in | `{ minLength }`; `false` = Payload's rule (3 characters) |
| `secrets.writeOnly` | on | `smtpPassword` and `turnstileSecretKey` (Site integrations) are never returned: REST, GraphQL and the panel get `'********'` when a value is stored; a save with nothing / empty / the mask keeps it, a new value replaces it, `'[[clear]]'` removes it; the Local API with access control off reads the real value. The panel is the source of these secrets — no env variable. A restore of a version is masked too | `false` = returned to whoever may read the global, as before |
@@ -68,7 +68,7 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT
| `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)`, `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`); 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(payload, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `unknownStaffCollections(payload, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)` | `@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; `'<slug>:<operation>'` 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` gives auth collections that a plugin listed after ipalKit added the same rules on the live config (called by the plugin at start and on a dev reload; returns the slugs); `unknownStaffCollections` lists staff slugs that are not auth collections (the plugin stops the start on any). |
| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)` | `@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; `'<slug>:<operation>'` 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). |
| `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. |
@@ -81,7 +81,7 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT
| `buildRolesField(defaultRole?, { firstUserAdmin? })` | `@intecion/ipal-kit` | The `roles` select field the plugin injects (only admins set roles; `firstUserAdmin` default `true` = the account made on "Create first user" gets `admin`). The plugin wires it itself — use it only for an auth collection the plugin does not manage. |
| `injectRoles(config, accessOption)` | `@intecion/ipal-kit` | Adds `roles` to `accessOption.authCollection` in a config. The plugin calls it itself with `access` — do not call. |
**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`, `firstUserRoute`, `password`), `StaffAccountAccessOptions` (`{ create?, write?, read?, pluginRoles? }`), `StaffAccountRules` (what the plugin put on a staff collection, in `custom.ipalAccountRules`: `{ applied, ownRoles }`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`).
**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`, `firstUserRoute`, `password`), `StaffAccountAccessOptions` (`{ create?, write?, read?, pluginRoles? }`), `LateAdoption` (`{ slug, applied, password, firstUser }`), `StaffAccountRules` (what the plugin put on a staff collection, in `custom.ipalAccountRules`: `{ applied, ownRoles }`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`).
## Accessibility — widget (`accessibility`) — details: `node_modules/@intecion/ipal-kit/docs/accessibility.md`
+3 -1
View File
@@ -257,7 +257,9 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo
account with any role — **write its `create` / `update` / `delete` rules and the field access of its `roles`
field yourself** (`ipal-doctor --url` → `staff-own-roles`). Give every staff collection a `roles` field: without
one each of its accounts is an admin to the plugin. Every slug in `access.staffCollections` must be an auth
collection of the config, or the site does not start; Payload's first-user route answers only for the
collection of the config, or Payload does not start (`/api/health` 503, the slug in the log); a staff collection
from a plugin listed after ipalKit gets the rules in front of its own (`custom: { ipal: { accountRules: false } }`
on it keeps its own as they are); Payload's first-user route answers only for the
panel's login collection (`firstUserRoute`) — so **create the first account right after the first deploy**, it
becomes the admin; a new password has at least 12 characters (`password`). A customer collection with
sign-up: write its own `create: () => true`; the rules do not touch it. Do not combine
@@ -427,7 +427,8 @@ account → "Two-step verification: Set up." and the reset button; delete the ac
1. Update the package, `pnpm install`, `pnpm ipal:skills`, `pnpm payload generate:types`. No import-map change, **no
schema change and no migration** on any database (the verify count uses Payload's own `payload-kv`
collection). `grep -n "staffCollections\|authCollection" src/payload.config.ts`: every slug there must be an
auth collection of the config — a wrong one now stops the start with the slug in the message.
auth collection of the config — with a wrong one Payload does not start (the slug is in the log; `/api/health`
answers 503, so with a health check Coolify keeps the old container).
2. **Panel access by role.** After the first start read the log: `[ipal] N account(s) of "users" are below the
role "editor" and cannot open the admin panel`. Those accounts (role `user`, or no role) now see
"Unauthorized" in the panel. Give the people who work in the panel `editor`, or set
@@ -466,7 +467,9 @@ account → "Two-step verification: Set up." and the reset button; delete the ac
- `read`: only staff accounts read a staff collection. **Check:** does the front end show staff accounts
(an author box) to logged-in visitors with the visitor's session? Then write that collection's `read` rule,
or `accounts: { staffOnlyRead: false }`. Anonymous visitors never could.
A staff collection added by a plugin listed after ipalKit gets the same rules at start.
A staff collection added by a plugin listed after ipalKit gets the same rules at start, put in FRONT of the
rules it has (both must allow). If that plugin's collection needs a rule wider than the plugin's default,
set `custom: { ipal: { accountRules: false } }` on it.
`first-register` on any auth collection other than the panel's login collection answers `403` unless that
collection allows sign-up. `access.firstUserAdmin: false` with a default role below `editor`: the panel role
is not applied (a warning at start), or — with `accounts.panelRole` set — the start fails with the fix in the
+8
View File
@@ -21,6 +21,14 @@ Production check: `pnpm build && pnpm payload run e2e/create-test-admin.ts && AL
(Playwright starts the built site on port 3100 itself; another port: `E2E_BASE_URL=http://localhost:3200`, built with
the same `NEXT_PUBLIC_SERVER_URL`; a server you started yourself: `E2E_REUSE_SERVER=1`).
Access rules on a built site, both bundlers (a staff collection that a plugin listed after ipalKit adds — unit tests
run unminified code and cannot see what a bundle renames):
```bash
E2E_LATE_STAFF=1 pnpm build && pnpm payload run e2e/create-test-admin.ts && E2E_LATE_STAFF=1 ALLOW_LOCAL_MEDIA=1 pnpm exec playwright test late-staff
E2E_LATE_STAFF=1 pnpm exec next build --turbopack && pnpm payload run e2e/create-test-admin.ts && E2E_LATE_STAFF=1 ALLOW_LOCAL_MEDIA=1 pnpm exec playwright test late-staff
```
Without `E2E_LATE_STAFF=1` the fixture adds nothing and the spec is skipped.
## What is where
| Convention | Files |
|---|---|
+23
View File
@@ -0,0 +1,23 @@
import type { Config, Plugin } from 'payload'
/**
* Test fixture, on only with E2E_LATE_STAFF=1 (e2e/late-staff.spec.ts): a plugin listed AFTER ipalKit that adds
* a staff collection (`late-staff`, named in `access.staffCollections`) and a visitor collection with open
* sign-up. ipalKit has already run when these collections appear, so it must give them its account rules when
* the config goes live — and it must do so in a BUILT site too, where bundlers rename every function.
* Never part of a real site: the starter drops `e2e/` and the lines that use this file.
*/
export const E2E_LATE_STAFF = process.env.E2E_LATE_STAFF === '1'
export const e2eLateStaff: Plugin = (config: Config) =>
E2E_LATE_STAFF
? {
...config,
collections: [
...(config.collections ?? []),
// no access rules at all: Payload's defaults ("any logged-in user") are what ipalKit must replace
{ slug: 'late-staff', auth: true, fields: [{ name: 'roles', type: 'select', hasMany: true, options: ['user', 'editor', 'admin'], saveToJWT: true }], versions: true },
{ slug: 'e2e-visitors', access: { create: () => true }, auth: true, fields: [] },
],
}
: config
+78
View File
@@ -0,0 +1,78 @@
import { type APIRequestContext, expect, test } from '@playwright/test'
import { randomUUID } from 'node:crypto'
import { totp } from './totp'
/**
* The account rules on a BUILT site, for a staff collection that a plugin listed after ipalKit adds
* (e2e/late-staff-fixture.ts). Unit tests run unminified code; a production bundle renames every function, and a
* rule that told Payload's default access function by its name was silently skipped there. Run it against both
* bundlers (README "Production check"):
* E2E_LATE_STAFF=1 pnpm build && … pnpm exec playwright test late-staff (webpack)
* E2E_LATE_STAFF=1 pnpm next build --turbopack && … the same (Turbopack)
*/
const { E2E_ADMIN_EMAIL: email, E2E_ADMIN_PASSWORD: password, E2E_LATE_STAFF: on, E2E_TOTP_SECRET: secret } = process.env
const PASSWORD = `T-${randomUUID()}`
test.describe('a late staff collection on a built site', () => {
test.skip(on !== '1', 'E2E_LATE_STAFF=1 not set (build and start the site with it)')
test.skip(!email || !password || !secret, 'E2E_* test admin not configured')
const context = (playwright: { request: { newContext: (o: object) => Promise<APIRequestContext> } }, baseURL: string) =>
playwright.request.newContext({ baseURL, extraHTTPHeaders: { origin: baseURL } })
test('a visitor account and an anonymous request get nothing; nobody raises its own role', async ({ baseURL, playwright }) => {
const tag = randomUUID().slice(0, 8)
// a fully signed-in admin of the panel's collection
const admin = await context(playwright, baseURL!)
expect((await admin.post('/api/users/login', { data: { email, password } })).status()).toBe(200)
expect((await (await admin.post('/api/verify-totp', { data: { token: totp(secret!) } })).json()).ok).toBe(true)
// anonymous: the first-user route of the (possibly empty) late collection, in two spellings
const nobody = await context(playwright, baseURL!)
for (const spelling of ['first-register', 'First-Register']) {
const res = await nobody.post(`/api/late-staff/${spelling}`, { data: { email: `first-${tag}@example.com`, password: PASSWORD, roles: ['admin'] } })
expect(res.status(), spelling).toBe(403)
}
expect((await nobody.get('/api/late-staff')).status()).toBe(403)
// the admin makes an account there (the rules let an admin through)
const made = await admin.post('/api/late-staff', { data: { email: `low-${tag}@example.com`, password: PASSWORD, roles: ['user'] } })
expect(made.status()).toBe(201)
const id = (await made.json()).doc.id as string
// a visitor account, signed up by itself
const visitor = await context(playwright, baseURL!)
expect((await visitor.post('/api/e2e-visitors', { data: { email: `v-${tag}@example.com`, password: PASSWORD } })).status()).toBe(201)
expect((await visitor.post('/api/e2e-visitors/login', { data: { email: `v-${tag}@example.com`, password: PASSWORD } })).status()).toBe(200)
const got = {
create: (await visitor.post('/api/late-staff', { data: { email: `x-${tag}@example.com`, password: PASSWORD, roles: ['admin'] } })).status(),
patch: (await visitor.patch(`/api/late-staff/${id}`, { data: { password: `taken-${PASSWORD}` } })).status(),
read: (await visitor.get('/api/late-staff')).status(),
unlock: (await visitor.post('/api/late-staff/unlock', { data: { email: `low-${tag}@example.com` } })).status(),
versions: (await visitor.get('/api/late-staff/versions')).status(),
// last: it would remove the account the other checks use
delete: (await visitor.delete(`/api/late-staff/${id}`)).status(),
}
expect(got).toEqual({ create: 403, delete: 403, patch: 403, read: 403, unlock: 403, versions: 403 })
// nothing an admin opens, either
expect((await visitor.get('/api/globals/site-integrations')).status()).toBe(403)
// the account itself (2FA covers the panel's collection only): its own password yes, its own roles no
const low = await context(playwright, baseURL!)
expect((await low.post('/api/late-staff/login', { data: { email: `low-${tag}@example.com`, password: PASSWORD } })).status()).toBe(200)
await low.patch(`/api/late-staff/${id}`, { data: { roles: ['admin'] } })
const after = await (await admin.get(`/api/late-staff/${id}`)).json()
expect(after.roles).toEqual(['user'])
expect((await low.get('/api/globals/site-integrations')).status()).toBe(403)
expect((await low.post('/api/late-staff/unlock', { data: { email: `low-${tag}@example.com` } })).status()).toBe(403)
// a short password is refused there too (the password rule)
expect((await admin.post('/api/late-staff', { data: { email: `s-${tag}@example.com`, password: 'tooshort', roles: ['user'] } })).status()).toBe(400)
// an admin: everything, and it cleans up
expect((await admin.get('/api/late-staff/versions')).status()).toBe(200)
expect((await admin.post('/api/late-staff/unlock', { data: { email: `low-${tag}@example.com` } })).status()).toBe(200)
expect((await admin.delete(`/api/late-staff/${id}`)).status()).toBe(200)
for (const api of [admin, nobody, visitor, low]) {await api.dispose()}
})
})
+12 -1
View File
@@ -18,6 +18,9 @@ import { Pages } from './collections/Pages'
// @starter:if posts
import { Posts } from './collections/Posts'
// @starter:endif
// @starter:if demo
import { E2E_LATE_STAFF, e2eLateStaff } from '../e2e/late-staff-fixture'
// @starter:endif
import { contentConfig } from './content.config'
import { db } from './db'
import { Company } from './globals/Company'
@@ -55,7 +58,12 @@ export default buildConfig({
plugins: [
ipalKit({
i18n: i18nConfig,
access: { authCollection: 'users' },
// @starter:if demo
// (the staffCollections entry exists only for e2e/late-staff.spec.ts, with E2E_LATE_STAFF=1)
access: { authCollection: 'users', ...(E2E_LATE_STAFF ? { staffCollections: ['late-staff'] } : {}) },
// @starter:else
//: access: { authCollection: 'users' },
// @starter:endif
pages: { slug: 'pages' },
content: contentConfig,
seo: {
@@ -105,5 +113,8 @@ export default buildConfig({
revalidatePath,
}),
buildR2Storage(['media'], { s3Storage }), // R2 with the full R2_* set, local disk without it
// @starter:if demo
e2eLateStaff, // a test fixture, a no-op without E2E_LATE_STAFF=1 (e2e/late-staff-fixture.ts)
// @starter:endif
],
})