Access defaults overridable; unlock admin-only; 2FA target validated

- access.authAccess merges over the injected auth collection's access;
  unlock is admin-only by default
- access.firstUserAdmin (default true) makes the first-register promotion optional
- globalOverrides: object merges access/admin/hooks, function takes over
- form Emails protection is applied before formOverrides.fields, so a
  project can change it there
- 2FA defaults to admin.user and fails at init when the target is not an
  auth collection or differs from admin.user (twoFactor.allowCollectionMismatch)
- buildRolesField, injectRoles, applyGlobalOverrides exported

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-22 17:23:14 +02:00
co-authored by Claude Opus 5.5
parent 14fd2c497f
commit a87742621a
11 changed files with 334 additions and 65 deletions
+7 -3
View File
@@ -35,7 +35,9 @@ const staffAccess = ({ req }: AccessArgs) => hasMinimumRole(req.user as never, '
/**
* Forms stay publicly readable (their fields render the form), but the Emails
* tab — recipient addresses, templates — is for editors and admins only, so
* GET /api/forms doesn't hand out the company's inboxes to spammers.
* GET /api/forms doesn't hand out the company's inboxes to spammers. Applied to
* the default fields BEFORE formOverrides.fields sees them, so a project can
* still change the rule there.
*/
function hideEmails(fields: Field[]): Field[] {
return fields.map((field) =>
@@ -117,8 +119,10 @@ export function buildFormsPlugin(forms: FormsOption): Plugin {
...forms.formOverrides?.access,
},
admin: { ...group, ...forms.formOverrides?.admin },
fields: ({ defaultFields }) =>
hideEmails(forms.formOverrides?.fields ? forms.formOverrides.fields({ defaultFields }) : defaultFields),
fields: ({ defaultFields }) => {
const protectedFields = hideEmails(defaultFields)
return forms.formOverrides?.fields ? forms.formOverrides.fields({ defaultFields: protectedFields }) : protectedFields
},
},
formSubmissionOverrides: {
labels: { plural: 'Submissions', singular: 'Submission' },