mirror of
https://github.com/complexcaresolutions/cms.c2sgmbh.git
synced 2026-03-17 19:44:12 +00:00
fix: unblock tenant SMTP saves in admin
This commit is contained in:
parent
4386ac5d8d
commit
5f45cc820d
2 changed files with 28 additions and 29 deletions
|
|
@ -1,15 +1,12 @@
|
|||
import type { CollectionConfig, FieldHook } from 'payload'
|
||||
import { invalidateEmailCacheHook } from '../hooks/invalidateEmailCache'
|
||||
import { auditTenantAfterChange, auditTenantAfterDelete } from '../hooks/auditTenantChanges'
|
||||
import { neverReadable } from '../lib/access'
|
||||
|
||||
/**
|
||||
* Validiert SMTP Host Format
|
||||
*/
|
||||
const validateSmtpHost: FieldHook = ({ value, siblingData }) => {
|
||||
// Nur validieren wenn useCustomSmtp aktiv ist und ein Wert vorhanden
|
||||
const emailData = siblingData as { useCustomSmtp?: boolean }
|
||||
if (!emailData?.useCustomSmtp) return value
|
||||
const validateSmtpHost: FieldHook = ({ value }) => {
|
||||
// Nur validieren, wenn ein Wert gesetzt ist
|
||||
if (!value) return value
|
||||
|
||||
// Basis-Validierung: Keine Protokoll-Präfixe erlaubt
|
||||
|
|
@ -23,9 +20,8 @@ const validateSmtpHost: FieldHook = ({ value, siblingData }) => {
|
|||
/**
|
||||
* Validiert SMTP Port
|
||||
*/
|
||||
const validateSmtpPort: FieldHook = ({ value, siblingData }) => {
|
||||
const emailData = siblingData as { useCustomSmtp?: boolean }
|
||||
if (!emailData?.useCustomSmtp) return value
|
||||
const validateSmtpPort: FieldHook = ({ value }) => {
|
||||
if (!value) return value
|
||||
|
||||
const port = Number(value)
|
||||
if (port && (port < 1 || port > 65535)) {
|
||||
|
|
@ -138,6 +134,22 @@ export const Tenants: CollectionConfig = {
|
|||
description:
|
||||
'Hinweis: Stellen Sie sicher, dass SPF- und DKIM-Einträge für Ihre Domain konfiguriert sind, um eine optimale E-Mail-Zustellung zu gewährleisten.',
|
||||
},
|
||||
validate: (value, { siblingData }) => {
|
||||
const emailData = siblingData as { useCustomSmtp?: boolean }
|
||||
if (!emailData?.useCustomSmtp) return true
|
||||
|
||||
const smtpData = (value || {}) as { host?: string; user?: string }
|
||||
|
||||
if (!smtpData.host?.trim()) {
|
||||
return 'SMTP Host ist erforderlich'
|
||||
}
|
||||
|
||||
if (!smtpData.user?.trim()) {
|
||||
return 'SMTP Benutzername ist erforderlich'
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
type: 'row',
|
||||
|
|
@ -146,7 +158,6 @@ export const Tenants: CollectionConfig = {
|
|||
name: 'host',
|
||||
type: 'text',
|
||||
label: 'SMTP Host',
|
||||
required: true,
|
||||
admin: {
|
||||
placeholder: 'smtp.example.com',
|
||||
width: '50%',
|
||||
|
|
@ -155,13 +166,6 @@ export const Tenants: CollectionConfig = {
|
|||
hooks: {
|
||||
beforeValidate: [validateSmtpHost],
|
||||
},
|
||||
validate: (value: string | undefined | null, { siblingData }: { siblingData: Record<string, unknown> }) => {
|
||||
const emailData = siblingData as { useCustomSmtp?: boolean }
|
||||
if (emailData?.useCustomSmtp && !value) {
|
||||
return 'SMTP Host ist erforderlich'
|
||||
}
|
||||
return true
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'port',
|
||||
|
|
@ -197,19 +201,10 @@ export const Tenants: CollectionConfig = {
|
|||
name: 'user',
|
||||
type: 'text',
|
||||
label: 'SMTP Benutzername',
|
||||
required: true,
|
||||
admin: {
|
||||
width: '50%',
|
||||
description: 'Meist die E-Mail-Adresse',
|
||||
},
|
||||
validate: (value: string | undefined | null, { siblingData }: { siblingData: Record<string, unknown> }) => {
|
||||
const smtpData = siblingData as { host?: string }
|
||||
// Nur validieren wenn host gesetzt ist (d.h. SMTP aktiv)
|
||||
if (smtpData?.host && !value) {
|
||||
return 'SMTP Benutzername ist erforderlich'
|
||||
}
|
||||
return true
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'pass',
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ export const auditTenantAfterChange: CollectionAfterChangeHook = async ({
|
|||
|
||||
if (!user) return doc
|
||||
|
||||
await logTenantChange(
|
||||
logTenantChange(
|
||||
req.payload,
|
||||
doc.id,
|
||||
operation,
|
||||
|
|
@ -55,7 +55,9 @@ export const auditTenantAfterChange: CollectionAfterChangeHook = async ({
|
|||
sanitizeTenantDoc(previousDoc),
|
||||
sanitizeTenantDoc(doc),
|
||||
req,
|
||||
)
|
||||
).catch((error) => {
|
||||
console.error('[AuditHook] Error logging tenant change:', error)
|
||||
})
|
||||
|
||||
return doc
|
||||
}
|
||||
|
|
@ -70,7 +72,7 @@ export const auditTenantAfterDelete: CollectionAfterDeleteHook = async ({ doc, r
|
|||
if (!user) return doc
|
||||
|
||||
// WICHTIG: Auch bei Löschung das Dokument sanitizen!
|
||||
await logTenantChange(
|
||||
logTenantChange(
|
||||
req.payload,
|
||||
doc.id,
|
||||
'delete',
|
||||
|
|
@ -79,7 +81,9 @@ export const auditTenantAfterDelete: CollectionAfterDeleteHook = async ({ doc, r
|
|||
sanitizeTenantDoc(doc),
|
||||
undefined,
|
||||
req,
|
||||
)
|
||||
).catch((error) => {
|
||||
console.error('[AuditHook] Error logging tenant delete:', error)
|
||||
})
|
||||
|
||||
return doc
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue