K-1, K-2: only a roles field that holds a LIST counts; the start-up check asks each collection its own way

K-1 the plugin counts roles only from an array (getRoles). A single-valued roles field — a select, text or
    relationship without hasMany, a radio — never makes a plugin admin, yet canHoldStaffRole said true: on a
    project's own login collection with a single role select nobody could create, change, delete or unlock accounts,
    the account holding admin included. rolesAreAList(collection) is now a precondition of the admin rules. The same
    for hasPluginRoles: a single select whose values are all the plugin's had the admin rules already in 1.16.7 and
    gets 'an account of this collection' now — its accounts manage each other again; the value still grants nothing.
    A relationship with hasMany counts (ids that are text).
K-2 staffCollectionsNobodyManages returns { stuck, unchecked } and checks collection by collection: no query where
    the field cannot hold admin; a count for a select with hasMany; for text / json / relationship the accounts are
    read and the plugin's own test is applied. Where it cannot check it says so and claims nothing.
Tests: the reviewer's shapes over HTTP and the warning's table against a running Payload, 2FA off and on.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 03:44:25 +01:00
co-authored by Claude Fable 5.2
parent ccc6f85924
commit c3d95988e1
11 changed files with 406 additions and 47 deletions
+6 -1
View File
@@ -937,13 +937,18 @@ export const ipalKit = (options: IpalOptions): Plugin => {
}
// Staff collections on the admin rules while no staff account is an admin: nobody can manage their accounts.
if (accounts) {
const stuck = await staffCollectionsNobodyManages(payload as never, staffCollectionSlugs(payload), options.access?.authCollection)
const { stuck, unchecked } = await staffCollectionsNobodyManages(payload as never, staffCollectionSlugs(payload), options.access?.authCollection)
if (stuck.length) {
payload.logger.warn(
`[ipal] No staff account holds the role "admin", so NOBODY can create, delete or unlock accounts in ${stuck.map((s) => `"${s}"`).join(', ')} ` +
"(only an admin does there: the collection's roles can hold \"editor\" or \"admin\"). Give one account the role with a script " +
'(payload.update, Local API), or write the collection\'s own access.create / update / delete rules (docs/access.md "Account rules").',
)
} else if (unchecked.length) {
payload.logger.warn(
`[ipal] Could not check whether an account of ${unchecked.map((s) => `"${s}"`).join(', ')} holds the role "admin" (no other staff account does). ` +
'If none does, nobody can create, delete or unlock accounts in the staff collections that are managed by admins only (docs/access.md "Account rules").',
)
}
}
// The panel role: tell a site how many of its accounts the rule keeps out of the panel.