Fix turnstile
This commit is contained in:
@@ -1,37 +1,60 @@
|
||||
import type { Plugin } from 'payload'
|
||||
|
||||
import { formBuilderPlugin } from '@payloadcms/plugin-form-builder'
|
||||
|
||||
import type { Plugin } from 'payload'
|
||||
import type { FormsOption } from './types.js'
|
||||
|
||||
/** REST/GraphQL: only logged-in users. Local API (submitForm) is unaffected. */
|
||||
const submissionsCreateAccess = ({ req }: { req: { user?: unknown } }) => Boolean(req.user)
|
||||
|
||||
/**
|
||||
* Configures @payloadcms/plugin-form-builder from IPAL's FormsOption.
|
||||
*
|
||||
* Provides the form/form-submissions collections and field types. Email
|
||||
* delivery is intentionally NOT handled here — the plugin's own SMTP-from-panel
|
||||
* sender (submitForm) does that, so the form-builder's built-in email (which
|
||||
* needs a Payload email adapter) is left unused.
|
||||
* Provides the forms / form-submissions collections and field types. E-mails
|
||||
* after a submission are the form-builder's own (Forms → Emails), sent through
|
||||
* the project's email adapter (mailAdapter()).
|
||||
*
|
||||
* SECURITY: form-builder defaults form-submissions to `create: () => true`, i.e.
|
||||
* anyone can POST /api/form-submissions and skip everything submitForm enforces
|
||||
* (rate limit, Turnstile, GDPR consent, schema validation). Here REST/GraphQL
|
||||
* creation is limited to logged-in users; the site submits through submitForm
|
||||
* (server action → Local API, which bypasses access by design). A project that
|
||||
* really needs public REST submissions can override `formSubmissionOverrides.access.create`.
|
||||
*/
|
||||
export function buildFormsPlugin(forms: FormsOption): Plugin {
|
||||
const adminGroup = forms.adminGroup === undefined ? 'Forms' : forms.adminGroup
|
||||
const group = adminGroup ? { group: adminGroup } : {}
|
||||
return formBuilderPlugin({
|
||||
fields: {
|
||||
checkbox: true,
|
||||
email: true,
|
||||
message: true,
|
||||
number: true,
|
||||
payment: false,
|
||||
select: true,
|
||||
text: true,
|
||||
textarea: true,
|
||||
email: true,
|
||||
number: true,
|
||||
select: true,
|
||||
checkbox: true,
|
||||
message: true,
|
||||
payment: false,
|
||||
...forms.fields,
|
||||
},
|
||||
...(forms.redirectRelationships ? { redirectRelationships: forms.redirectRelationships } : {}),
|
||||
...(forms.redirectRelationships
|
||||
? { redirectRelationships: forms.redirectRelationships }
|
||||
: {}),
|
||||
// Client-supplied collection overrides (e.g. a per-form notification
|
||||
// address). The plugin provides the hook, not the opinion about which
|
||||
// extra fields a form should carry.
|
||||
...(forms.formOverrides ? { formOverrides: forms.formOverrides } : {}),
|
||||
...(forms.formSubmissionOverrides
|
||||
? { formSubmissionOverrides: forms.formSubmissionOverrides }
|
||||
: {}),
|
||||
// Tidy panel by default: both collections under one sidebar group with plain
|
||||
// labels — no per-project overrides needed just to sort the sidebar.
|
||||
formOverrides: {
|
||||
labels: { singular: 'Form', plural: 'Forms' },
|
||||
...forms.formOverrides,
|
||||
admin: { ...group, ...forms.formOverrides?.admin },
|
||||
},
|
||||
formSubmissionOverrides: {
|
||||
labels: { singular: 'Submission', plural: 'Submissions' },
|
||||
...forms.formSubmissionOverrides,
|
||||
admin: { ...group, defaultColumns: ['form', 'createdAt'], ...forms.formSubmissionOverrides?.admin },
|
||||
access: {
|
||||
create: submissionsCreateAccess,
|
||||
...forms.formSubmissionOverrides?.access,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user