mirror of
https://github.com/complexcaresolutions/cms.c2sgmbh.git
synced 2026-03-17 18:34:13 +00:00
fix: form submission hooks — tenant propagation + email notification
- FormSubmissionsOverrides: fields must be a function (not array) for the form-builder plugin to merge them with defaultFields - setSubmissionTenant: add overrideAccess for unauthenticated submissions - sendFormNotification: handle populated form object (extract ID), add overrideAccess for tenant SMTP lookup Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5e223cd7fb
commit
d90657c2cf
3 changed files with 30 additions and 17 deletions
|
|
@ -1,29 +1,22 @@
|
||||||
// src/collections/FormSubmissionsOverrides.ts
|
// src/collections/FormSubmissionsOverrides.ts
|
||||||
|
|
||||||
import type { CollectionConfig } from 'payload'
|
import type { CollectionConfig, Field } from 'payload'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FormSubmissions Overrides
|
* FormSubmissions Overrides
|
||||||
*
|
*
|
||||||
* Erweitert die vom formBuilderPlugin erstellte FormSubmissions Collection um:
|
* Erweitert die vom formBuilderPlugin erstellte FormSubmissions Collection um:
|
||||||
|
* - Tenant-Zuweisung (automatisch vom Formular)
|
||||||
* - Status-Workflow (neu → in Bearbeitung → erledigt)
|
* - Status-Workflow (neu → in Bearbeitung → erledigt)
|
||||||
* - Interne Notizen
|
* - Interne Notizen
|
||||||
* - Zuständigkeits-Zuweisung
|
* - Zuständigkeits-Zuweisung
|
||||||
* - Verbesserte Admin-Ansicht
|
* - Verbesserte Admin-Ansicht
|
||||||
|
*
|
||||||
|
* WICHTIG: fields MUSS eine Funktion sein, da das formBuilderPlugin
|
||||||
|
* ein Array stillschweigend ignoriert und nur defaultFields verwendet.
|
||||||
*/
|
*/
|
||||||
export const formSubmissionOverrides: Partial<CollectionConfig> = {
|
|
||||||
admin: {
|
const customFields: Field[] = [
|
||||||
useAsTitle: 'id',
|
|
||||||
group: 'Formulare',
|
|
||||||
defaultColumns: ['id', 'form', 'status', 'assignedTo', 'createdAt'],
|
|
||||||
description: 'Eingegangene Formular-Einsendungen',
|
|
||||||
listSearchableFields: ['id', 'status'],
|
|
||||||
},
|
|
||||||
labels: {
|
|
||||||
singular: 'Formular-Einsendung',
|
|
||||||
plural: 'Formular-Einsendungen',
|
|
||||||
},
|
|
||||||
fields: [
|
|
||||||
// Tenant (automatisch vom Formular übernommen via setSubmissionTenant Hook)
|
// Tenant (automatisch vom Formular übernommen via setSubmissionTenant Hook)
|
||||||
{
|
{
|
||||||
name: 'tenant',
|
name: 'tenant',
|
||||||
|
|
@ -222,5 +215,22 @@ export const formSubmissionOverrides: Partial<CollectionConfig> = {
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
]
|
||||||
|
|
||||||
|
export const formSubmissionOverrides: Partial<CollectionConfig> = {
|
||||||
|
admin: {
|
||||||
|
useAsTitle: 'id',
|
||||||
|
group: 'Formulare',
|
||||||
|
defaultColumns: ['id', 'form', 'tenant', 'status', 'assignedTo', 'createdAt'],
|
||||||
|
description: 'Eingegangene Formular-Einsendungen',
|
||||||
|
listSearchableFields: ['id', 'status'],
|
||||||
|
},
|
||||||
|
labels: {
|
||||||
|
singular: 'Formular-Einsendung',
|
||||||
|
plural: 'Formular-Einsendungen',
|
||||||
|
},
|
||||||
|
fields: (({ defaultFields }: { defaultFields: Field[] }) => [
|
||||||
|
...defaultFields,
|
||||||
|
...customFields,
|
||||||
|
]) as unknown as Field[],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,13 @@ export const sendFormNotification: CollectionAfterChangeHook = async ({
|
||||||
const { payload } = req
|
const { payload } = req
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Form laden mit Details
|
// Form laden mit Details — doc.form kann bereits populated sein (Objekt statt ID)
|
||||||
|
const formId = typeof doc.form === 'object' ? doc.form?.id : doc.form
|
||||||
const form = (await payload.findByID({
|
const form = (await payload.findByID({
|
||||||
collection: 'forms',
|
collection: 'forms',
|
||||||
id: doc.form,
|
id: formId,
|
||||||
depth: 1,
|
depth: 1,
|
||||||
|
overrideAccess: true,
|
||||||
})) as FormDocument | null
|
})) as FormDocument | null
|
||||||
|
|
||||||
if (!form) {
|
if (!form) {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ export const setSubmissionTenant: CollectionBeforeChangeHook = async ({
|
||||||
collection: 'forms',
|
collection: 'forms',
|
||||||
id: formId,
|
id: formId,
|
||||||
depth: 0,
|
depth: 0,
|
||||||
|
overrideAccess: true,
|
||||||
})) as unknown as FormWithTenant
|
})) as unknown as FormWithTenant
|
||||||
|
|
||||||
if (form?.tenant) {
|
if (form?.tenant) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue