M1 review round 2: the transport is no way round, nobody raises its own role, late staff collections
R2-1 the SMTP password is bound to server, port and user whatever the transport says; the transport alone is not bound.
R2-2 where the plugin's update rule is in force the roles field is closed for the account itself
(the plugin's roles: only an admin; roles of the project's own: never one's own).
R2-3 auth collections a later plugin adds get the account rules, the password rule and the first-user endpoint when
the config goes live; a staff slug that is not an auth collection stops the start.
R2-4 smtpRequireTls is taken out: the branch adds no field, column or collection.
Also: read (a staff account) and unlock (an admin) defaults on staff collections (accounts.staffOnlyRead);
doctor staff-own-roles and read / unlock in staff-accounts-open; r1 NULL against the default, also inside a row;
r2 bound values compared exactly.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
a32329fbb4
commit
7002ebbfa6
+28
-7
@@ -14,8 +14,8 @@ import { buildSiteIntegrations } from './globals/SiteIntegrations/index.js'
|
||||
import { buildSiteSettings } from './globals/SiteSettings/index.js'
|
||||
import { adminOnly, adminOrSelfIn, injectRoles, registerStaffCollections, staffCollectionSlugs } from './modules/access/index.js'
|
||||
import { applyPanelRole, countBelowPanelRole, resolvePanelRole } from './modules/access/panelRole.js'
|
||||
import { applyPasswordRule, resolvePasswordRule } from './modules/access/passwordRule.js'
|
||||
import { applyFirstUserRoute, applyStaffAccountAccess } from './modules/access/selfRegistration.js'
|
||||
import { applyPasswordRule, buildPasswordRuleHook, resolvePasswordRule } from './modules/access/passwordRule.js'
|
||||
import { adoptLateAuthCollections, applyFirstUserRoute, applyStaffAccountAccess, markSeenAuthCollections, unknownStaffCollections } from './modules/access/selfRegistration.js'
|
||||
import { ROLE_HIERARCHY } from './modules/access/types.js'
|
||||
import { applyAdminI18n } from './modules/admin-i18n/apply.js'
|
||||
import { buildAdminImageEndpoints } from './modules/branding/adminImages.js'
|
||||
@@ -193,6 +193,17 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
const adoptConfig = (payload: BasePayload) => {
|
||||
const token = (payload.config.custom as { ipal?: { staffToken?: object } } | undefined)?.ipal?.staffToken
|
||||
registerStaffCollections(payload, staffCollectionSlugs(payload), token)
|
||||
// Auth collections a plugin listed after ipalKit added: the account rules for them too — BEFORE the
|
||||
// 2FA guard below wraps their access (it needs the rule inside its wrapper).
|
||||
if (accounts) {
|
||||
const rule = resolvePasswordRule(accounts.password)
|
||||
const lateAccounts = adoptLateAuthCollections(payload as never, staffCollectionSlugs(payload), {
|
||||
access: { ...accountAccess, pluginRoles: [] },
|
||||
beforeOperation: rule ? buildPasswordRuleHook(rule) : undefined,
|
||||
firstUserRoute: accounts.firstUserRoute,
|
||||
})
|
||||
if (lateAccounts.length) {payload.logger.info(`[ipal] Account rules also put on auth collections added after ipalKit: ${lateAccounts.join(', ')}.`)}
|
||||
}
|
||||
if (!secondFactorGuard) {return}
|
||||
const late = ensurePayloadGuarded(payload)
|
||||
if (late?.length) {payload.logger.info(`[ipal] 2FA also enforced on entities added after ipalKit: ${late.join(', ')}.`)}
|
||||
@@ -206,6 +217,8 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
let panelRoleSkipped: null | string = null
|
||||
/** `accounts: false` turns every account rule off. */
|
||||
const accounts: AccountsOptions | null = options.accounts === false ? null : (options.accounts ?? {})
|
||||
/** Which of the staff defaults are on (accounts.adminOnlyCreate / adminOnlyWrite / staffOnlyRead). */
|
||||
const accountAccess = { create: accounts?.adminOnlyCreate !== false, read: accounts?.staffOnlyRead !== false, write: accounts?.adminOnlyWrite !== false }
|
||||
/** requireSetup.setupNotice / statusField (on unless switched off). */
|
||||
let setupNotice = true
|
||||
let statusField = false
|
||||
@@ -215,11 +228,7 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
if (accounts) {
|
||||
const panelSlug = config.admin?.user ?? (config.collections ?? []).find((c) => c.auth)?.slug
|
||||
const staffSlugs = [...new Set([panelSlug, options.access?.authCollection, ...(options.access?.staffCollections ?? [])].filter((s): s is string => Boolean(s)))]
|
||||
config = applyStaffAccountAccess(config, staffSlugs, {
|
||||
create: accounts.adminOnlyCreate !== false,
|
||||
pluginRoles: options.access?.authCollection ? [options.access.authCollection] : [],
|
||||
write: accounts.adminOnlyWrite !== false,
|
||||
})
|
||||
config = applyStaffAccountAccess(config, staffSlugs, { ...accountAccess, pluginRoles: options.access?.authCollection ? [options.access.authCollection] : [] })
|
||||
}
|
||||
if (options.twoFactor !== false) {
|
||||
const tf = options.twoFactor
|
||||
@@ -883,6 +892,16 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
const incomingOnInit = config.onInit
|
||||
config.onInit = async (payload) => {
|
||||
if (incomingOnInit) {await incomingOnInit(payload)}
|
||||
// A staff collection that does not exist protects nothing and hides a typo: its accounts would not be staff,
|
||||
// or — worse — a collection of that name added later would be, without anyone having decided it.
|
||||
const unknownStaff = unknownStaffCollections(payload as never, [...new Set([options.access?.authCollection, ...(options.access?.staffCollections ?? [])].filter((s): s is string => Boolean(s)))])
|
||||
if (unknownStaff.length) {
|
||||
throw new Error(
|
||||
`[ipal] access names ${unknownStaff.map((s) => `"${s}"`).join(', ')} as a staff collection, but this config has no auth collection with that slug ` +
|
||||
`(auth collections: ${Object.values(payload.collections).filter((c) => c.config.auth).map((c) => c.config.slug).join(', ') || 'none'}). ` +
|
||||
'Fix the slug in access.authCollection / access.staffCollections, or add the collection (docs/access.md "Who is staff").',
|
||||
)
|
||||
}
|
||||
adoptConfig(payload)
|
||||
// Payload's dev reload swaps `payload.config` and runs no onInit: adopt the new config at once.
|
||||
watchPayloadConfig(payload, adoptConfig)
|
||||
@@ -945,6 +964,8 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
payload.logger.info('[ipal] Plugin initialized.')
|
||||
}
|
||||
|
||||
// Every auth collection of this config has been seen: what appears later is a late one (adoptConfig).
|
||||
if (accounts) {config = markSeenAuthCollections(config)}
|
||||
return config
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user