M1 (5): the lowest role stays out of the admin panel (accounts.panelRole)

The panel opens for editor and above by default: Payload's access.admin on the
collection that carries the roles. An account that holds only `user` sees
"Unauthorized" there; the API is not touched. The rule looks at the role, not
at the second factor, so the 2FA screens stay reachable. accounts.panelRole:
'user' | false (everyone, as before) | 'admin'; accounts: false turns the account
rules off; the project's own access.admin wins. At start the log says how many
accounts the rule keeps out, and is an error when it keeps everyone out.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 00:39:12 +01:00
co-authored by Claude Fable 5.2
parent 463fd5d664
commit cd60b73685
7 changed files with 259 additions and 2 deletions
+9 -1
View File
@@ -48,7 +48,15 @@ describe('injected auth collection', () => {
const config = await ipalKit({ access: { authCollection: 'users' }, i18n, twoFactor: false })(
empty({ collections: [own] as CollectionConfig[] }),
)
expect(config.collections?.find((c) => c.slug === 'users')?.access).toBe(own.access)
const access = config.collections?.find((c) => c.slug === 'users')?.access
// what the project wrote stays its own…
expect(access?.read).toBe(own.access.read)
// …and the account rules fill in only what it left out (accounts.*; `accounts: false` = nothing added)
expect(access?.admin).toBeTypeOf('function')
const untouched = await ipalKit({ access: { authCollection: 'users' }, accounts: false, i18n, twoFactor: false })(
empty({ collections: [own] as CollectionConfig[] }),
)
expect(untouched.collections?.find((c) => c.slug === 'users')?.access).toBe(own.access)
})
})