Merge main (security-perf + SEO) into docs; finish English docs and agent guide
- Resolve conflicts in analytics, consent, content, i18n, mcp and stats, keeping the docs fixes and the new code behaviour, verified against src - Translate the remaining 14 module pages, ipal-seo-check skill and script - Integrate the security-perf and SEO agent-guide text: getRobots, isPathVisible, Search & AI (DNS verification first, meta fields optional), sitemap index/cache/503, consentMode basic/advanced, policyVersion, globalOverrides, revalidatePath / buildGlobalRevalidateHook, authAccess, firstUserAdmin, allowCollectionMismatch, unknown-IP rate limit; stale claims fixed across AGENT.md, skills, frontend, developer guide, vibe - docsConsistency: pending list removed (all docs English); relative links now also check #anchors Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+90
-24
@@ -1,45 +1,87 @@
|
||||
# access
|
||||
|
||||
Kontrola dostępu oparta na rolach: hierarchia **admin > editor > user**.
|
||||
Plugin wstrzykuje sztywne pole `roles` do klienckiej kolekcji auth i dostarcza
|
||||
predykaty oraz gotowe funkcje dostępu (collection-level i field-level).
|
||||
Role-based access control: hierarchy **admin > editor > user**.
|
||||
The plugin injects a fixed `roles` field into the client's auth collection and provides
|
||||
predicates and ready access functions (collection-level and field-level).
|
||||
|
||||
## Config (payload.config.ts)
|
||||
|
||||
```ts
|
||||
ipalKit({
|
||||
access: {
|
||||
authCollection: 'users', // slug Twojej kolekcji auth
|
||||
// defaultRole: 'user', // rola nowych użytkowników, domyślnie 'user'
|
||||
authCollection: 'users', // slug of your auth collection (required)
|
||||
// defaultRole: 'user', // role of new accounts
|
||||
// firstUserAdmin: true, // the account from "Create first user" → admin
|
||||
// authAccess: { … }, // access of the injected auth collection (your keys win)
|
||||
},
|
||||
// globalOverrides: { … }, // access / admin / hooks / fields of the plugin's globals
|
||||
})
|
||||
```
|
||||
|
||||
| Option | Default | What it does |
|
||||
|---|---|---|
|
||||
| `access.authCollection` | — (required) | the auth collection that gets the `roles` field |
|
||||
| `access.defaultRole` | `'user'` | role of a new account when an admin did not set one |
|
||||
| `access.firstUserAdmin` | `true` | the account from the "Create first user" screen (`…/first-register` on an empty collection) gets `['admin']`, even when the form picked `user`; `false` = it gets what was submitted |
|
||||
| `access.authAccess` | see the table below | `access` of the **injected** auth collection, merged over the default (your keys win) |
|
||||
| `globalOverrides` | — | changes to the plugin's globals: an object merges `access` / `admin` key by key (your keys win) and appends `hooks` (yours run after the plugin's), other keys (label, fields, …) replace; a function `(global) => global` takes over the whole global |
|
||||
|
||||
The `roles` field (select hasMany, required, `saveToJWT`): readable without limits; only an admin
|
||||
can set and change it — also on account creation, so an open sign-up cannot
|
||||
push `roles: ['admin']` through. The first-user screen and the Local API (seed) run with
|
||||
`overrideAccess`. An account without roles meets no threshold (not even `'user'`); `authenticated`
|
||||
only checks that someone is logged in.
|
||||
|
||||
**Auth collection when the project has none.** The plugin adds a minimal collection (`auth: true`,
|
||||
`admin.useAsTitle: 'email'`) with the slug `access.authCollection` (or `twoFactor.collectionSlug`,
|
||||
`admin.user`, `'users'`). The project's own collection with that slug always wins whole.
|
||||
|
||||
## What the plugin locks down by itself
|
||||
|
||||
| Resource | Read | Write | How to change |
|
||||
|---|---|---|---|
|
||||
| auth collection **injected** by the plugin, with roles | admin: everyone; others: only themselves | `create` / `delete` / `unlock`: admin; `update`: admin or self | `access.authAccess`, or your own collection |
|
||||
| Site Settings, Cookie Settings, Notifications | public | `editor+` | `globalOverrides` |
|
||||
| Site Integrations | admin | admin | `globalOverrides` |
|
||||
| Forms | public (Emails tab only `editor+`) | `editor+` | `forms.formOverrides.access`, the Emails field in `formOverrides.fields` |
|
||||
| Form submissions | `editor+` | REST `create`: logged-in users; `delete`: admin | `forms.formSubmissionOverrides.access` |
|
||||
|
||||
```ts
|
||||
import { authenticated } from '@intecion/ipal-kit'
|
||||
ipalKit({
|
||||
access: { authCollection: 'users', authAccess: { read: authenticated } }, // editors see the account list
|
||||
globalOverrides: {
|
||||
notifications: { access: { update: authenticated } }, // any logged-in account edits the texts
|
||||
'site-settings': (g) => ({ ...g, admin: { ...g.admin, group: 'Configuration' } }),
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
Wstrzykuje pole `roles` (select hasMany, `saveToJWT`, tylko admin może
|
||||
nadawać i zmieniać role — także przy tworzeniu konta, więc otwarta rejestracja nie
|
||||
przepuści `roles: ['admin']`; nie-admin dostaje `defaultRole`) do wskazanej kolekcji.
|
||||
Ekran pierwszego użytkownika i Local API (seed) działają z `overrideAccess`, więc
|
||||
pierwszego admina nadal da się utworzyć. Kolekcja należy do Ciebie
|
||||
(create-payload-app) — plugin tylko dokłada pole.
|
||||
The project's own auth collection keeps its own `access` — the plugin only adds the
|
||||
`roles` field. Give it at least `update: adminOrSelf`, `delete: adminOnly`, `create: adminOnly`,
|
||||
`unlock: adminOnly`: Payload's default lets any logged-in account change the email and password
|
||||
of another account and unlock any account. A collection injected **without** `access` (no roles)
|
||||
keeps Payload's default rules — without roles all accounts are equal.
|
||||
|
||||
> Po dodaniu: zadbaj, by seed / pierwszy user miał `roles: ['admin']`, inaczej
|
||||
> stracisz dostęp do zasobów admin-only (np. SiteIntegrations).
|
||||
> **Without `access` there is no `roles` field**, so `isAdmin` always returns `false`: the Site
|
||||
> Integrations global and the `/api/ipal/test-email` endpoint then work only through the Local API
|
||||
> (`overrideAccess`). The seed / first user must have `roles: ['admin']`.
|
||||
|
||||
## Predykaty (front / hooki / access)
|
||||
## Predicates (front end / hooks / access)
|
||||
|
||||
```ts
|
||||
import { isAdmin, isEditor, hasMinimumRole } from '@intecion/ipal-kit'
|
||||
|
||||
isAdmin(user) // admin?
|
||||
isEditor(user) // editor lub admin (hierarchia)
|
||||
hasMinimumRole(user, 'editor') // co najmniej editor
|
||||
isEditor(user) // editor or admin (hierarchy)
|
||||
hasMinimumRole(user, 'editor') // at least editor
|
||||
```
|
||||
|
||||
Przyjmują luźno typowanego usera (jak `req.user`), czytają `roles` defensywnie.
|
||||
They take a loosely typed user (like `req.user`) and read `roles` defensively.
|
||||
|
||||
## Gotowe funkcje dostępu
|
||||
## Ready access functions
|
||||
|
||||
### Collection-level (zwracają boolean | Where)
|
||||
### Collection-level (return boolean | Where)
|
||||
|
||||
```ts
|
||||
import { adminOnly, adminOrEditor, adminOrSelf, requireRole, authenticated } from '@intecion/ipal-kit'
|
||||
@@ -55,14 +97,14 @@ export const Articles = {
|
||||
// ...
|
||||
}
|
||||
|
||||
// Users: każdy widzi siebie, admin widzi wszystkich
|
||||
// Users: everyone sees themselves, an admin sees everyone
|
||||
access: { read: adminOrSelf }
|
||||
|
||||
// dowolny minimalny próg
|
||||
// any minimum threshold
|
||||
access: { update: requireRole('editor') }
|
||||
```
|
||||
|
||||
### Field-level (zwracają boolean)
|
||||
### Field-level (return boolean)
|
||||
|
||||
```ts
|
||||
import { adminOnlyField, adminOrEditorField, requireRoleField } from '@intecion/ipal-kit'
|
||||
@@ -74,9 +116,33 @@ import { adminOnlyField, adminOrEditorField, requireRoleField } from '@intecion/
|
||||
}
|
||||
```
|
||||
|
||||
## Hierarchia
|
||||
## Hierarchy
|
||||
|
||||
```ts
|
||||
import { ROLE_HIERARCHY } from '@intecion/ipal-kit'
|
||||
// ['user', 'editor', 'admin'] — wyższa rola spełnia wymóg niższej
|
||||
// ['user', 'editor', 'admin'] — a higher role meets a lower role's requirement
|
||||
```
|
||||
|
||||
## Building blocks: buildRolesField, injectRoles, applyGlobalOverrides
|
||||
|
||||
```ts
|
||||
import { applyGlobalOverrides, buildRolesField, injectRoles } from '@intecion/ipal-kit'
|
||||
|
||||
buildRolesField('user', { firstUserAdmin: true }) // just the roles field — for your own collection
|
||||
injectRoles(config, { authCollection: 'members' }) // add the field to a collection in a finished config
|
||||
applyGlobalOverrides(globals, { notifications: { … } }) // the same logic as the globalOverrides option
|
||||
```
|
||||
|
||||
Types: `AccessOption`, `Role`, `GlobalOverride`, `GlobalOverrides`, `IpalGlobalSlug`.
|
||||
|
||||
## Turn off, override, extend
|
||||
|
||||
- **Turn off:** leave out `access` — no `roles` field, the auth collection keeps Payload's rules
|
||||
(or yours). `access.firstUserAdmin: false` stops giving admin to the first account.
|
||||
- **Override:** `access.authAccess` (injected collection), your own auth collection (wins whole),
|
||||
`globalOverrides` (globals), `forms.formOverrides` / `formSubmissionOverrides` (forms),
|
||||
`defaultRole`. The role hierarchy (`ROLE_HIERARCHY`) is fixed.
|
||||
- **Extend:** `requireRole` / `requireRoleField`, predicates, `buildRolesField`, `injectRoles`,
|
||||
`applyGlobalOverrides` in your own collections and globals.
|
||||
- **Check:** log in with a `user` account → `PATCH /api/globals/site-settings` = 403,
|
||||
`DELETE /api/users/<admin id>` = 403; the account from "Create first user" has the `admin` role.
|
||||
|
||||
Reference in New Issue
Block a user