Admin panel in English and Polish, reworded per docs/dev/admin-ux.md
- admin-i18n module: AdminText { en, pl }, component texts under the ipal
namespace (project translations win), en + pl admin languages when the
project sets none (project's supportedLanguages wins)
- every plugin label, description, option, tab and group as { en, pl };
explicit labels instead of auto-labels; sentence case; glossary terms
- visible renames (slugs, names, data unchanged): Cookie banner, Form
messages, Privacy group, Search engines, Maintenance, Spam protection,
E-mail sending, stats nav link Overview (hidden without access)
- Polish visitor defaults by page locale: cookie banner, form messages,
validators, lightbox, accessibility widget; {field} uses the label
- fixes: e-mail status banner used Turnstile wording; developer words and
env var names out of editor messages; stats numbers/dates in the admin
language; test e-mail no longer says ipal-kit
- test/adminUx.test.ts: length limits, en + pl present, no developer words
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
eeac33ed2f
commit
6b46bc0c14
@@ -112,7 +112,11 @@ export const graphAdapter =
|
||||
payload.logger.error(
|
||||
'[ipal] Email not sent: Graph is not configured. Set GRAPH_TENANT_ID, GRAPH_CLIENT_ID, GRAPH_CLIENT_SECRET, GRAPH_SENDER.',
|
||||
)
|
||||
return { error: 'Graph is not configured (missing env vars).', sent: false }
|
||||
return {
|
||||
code: 'graph-not-configured',
|
||||
error: 'Microsoft Graph is not set up on the server. Ask your administrator.',
|
||||
sent: false,
|
||||
}
|
||||
}
|
||||
|
||||
// Display name on the From, WITHOUT triggering Send-As.
|
||||
@@ -132,7 +136,7 @@ export const graphAdapter =
|
||||
const to = toRecipients(message.to)
|
||||
if (to.length === 0) {
|
||||
payload.logger.error('[ipal] Email not sent: no valid recipient.')
|
||||
return { error: 'No valid recipient.', sent: false }
|
||||
return { error: 'Enter a valid recipient address.', sent: false }
|
||||
}
|
||||
|
||||
// Graph accepts either HTML or Text; Payload gives us html and/or text.
|
||||
@@ -183,11 +187,11 @@ export const graphAdapter =
|
||||
}
|
||||
const detail = await res.text()
|
||||
payload.logger.error(`[ipal] Graph sendMail failed (${res.status}): ${detail}`)
|
||||
return { error: `Graph sendMail failed (${res.status}).`, sent: false }
|
||||
return { detail: `Microsoft Graph refused the e-mail (${res.status}).`, error: 'The e-mail was not sent.', sent: false }
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : String(err)
|
||||
payload.logger.error(`[ipal] Graph send error: ${msg}`)
|
||||
return { error: 'Graph send error.', sent: false }
|
||||
return { detail: msg, error: 'The e-mail was not sent.', sent: false }
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -122,7 +122,8 @@ export const mailAdapter =
|
||||
graphFallback
|
||||
? {
|
||||
code: 'graph-unavailable',
|
||||
message: 'Microsoft Graph is selected but not configured on the server — e-mails are sent over SMTP.',
|
||||
message:
|
||||
'Microsoft Graph is selected but not set up on the server, so e-mails go over SMTP. Ask your administrator.',
|
||||
state: 'degraded',
|
||||
}
|
||||
: { state: 'ok' },
|
||||
|
||||
@@ -60,9 +60,9 @@ export const panelSmtpAdapter =
|
||||
|
||||
if (!host || !user || !pass) {
|
||||
payload.logger.error(
|
||||
'[ipal] Email not sent: SMTP is not configured in Site Integrations.',
|
||||
'[ipal] Email not sent: SMTP host, user or password is empty in Site integrations → E-mail sending.',
|
||||
)
|
||||
return { error: 'SMTP is not configured in Site Integrations.', sent: false }
|
||||
return { code: 'not-configured', error: 'Fill in the server, user name and password.', sent: false }
|
||||
}
|
||||
|
||||
// The panel is the source of truth for the sender; fall back to whatever
|
||||
@@ -102,7 +102,7 @@ export const panelSmtpAdapter =
|
||||
// shouldn't fail loudly because the mailbox is misconfigured.
|
||||
payload.logger.error(`[ipal] Email send failed: ${(err as Error).message}`)
|
||||
// `detail` is for the panel status (mailAdapter), not for end users.
|
||||
return { detail: (err as Error).message, error: 'Failed to send email.', sent: false }
|
||||
return { detail: (err as Error).message, error: 'The e-mail was not sent.', sent: false }
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -60,12 +60,12 @@ export async function sendEmail({
|
||||
const pass = smtp.smtpPassword
|
||||
|
||||
if (!host || !user || !pass) {
|
||||
return { error: 'SMTP is not configured in Site Integrations.', sent: false }
|
||||
return { error: 'Fill in the server, user name and password.', sent: false }
|
||||
}
|
||||
|
||||
const fromAddress = from ?? smtp.smtpFromAddress
|
||||
if (!fromAddress) {
|
||||
return { error: 'No from-address configured.', sent: false }
|
||||
return { error: 'Fill in the sender address.', sent: false }
|
||||
}
|
||||
|
||||
const fromName = smtp.smtpFromName
|
||||
@@ -90,6 +90,6 @@ export async function sendEmail({
|
||||
return { messageId: info.messageId, sent: true }
|
||||
} catch (err) {
|
||||
payload.logger.error(`[ipal] Email send failed: ${(err as Error).message}`)
|
||||
return { error: 'Failed to send email.', sent: false }
|
||||
return { error: 'The e-mail was not sent.', sent: false }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Endpoint, PayloadRequest } from 'payload'
|
||||
import { addDataAndFileToRequest } from 'payload'
|
||||
|
||||
import { userMeetsRole } from '../../access/predicates.js'
|
||||
import { serverText } from '../../integrations/texts.js'
|
||||
|
||||
/**
|
||||
* Custom endpoint: send a test email to a given address through whatever
|
||||
@@ -17,56 +18,74 @@ import { userMeetsRole } from '../../access/predicates.js'
|
||||
* Returns the adapter's own result so the panel can show exactly what happened,
|
||||
* including the transport-specific error (SMTP auth failure, Graph 401, etc.).
|
||||
*/
|
||||
/** The site name from Site settings (in the request's locale), or '' when unavailable. */
|
||||
async function siteName(req: PayloadRequest): Promise<string> {
|
||||
try {
|
||||
const doc = (await req.payload.findGlobal({ slug: 'site-settings' as never, depth: 0, req })) as { siteName?: unknown }
|
||||
return typeof doc?.siteName === 'string' ? doc.siteName.trim() : ''
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
const escapeHtml = (v: string) =>
|
||||
v.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"')
|
||||
|
||||
export const testEmailEndpoint: Endpoint = {
|
||||
handler: async (req: PayloadRequest) => {
|
||||
// Messages in the language of the admin user who clicked the button.
|
||||
const i18n = req.i18n as Parameters<typeof serverText>[0]
|
||||
// Auth: only admins may trigger a send — the same gate as the
|
||||
// SiteIntegrations global that holds the transport settings.
|
||||
if (!req.user) {
|
||||
return Response.json({ error: 'Unauthorized', ok: false }, { status: 401 })
|
||||
return Response.json({ error: serverText(i18n, 'testEmailLoggedOut'), ok: false }, { status: 401 })
|
||||
}
|
||||
if (!userMeetsRole(req, 'admin')) {
|
||||
return Response.json({ error: 'Forbidden', ok: false }, { status: 403 })
|
||||
return Response.json({ error: serverText(i18n, 'testEmailForbidden'), ok: false }, { status: 403 })
|
||||
}
|
||||
|
||||
await addDataAndFileToRequest(req)
|
||||
const to = (req.data?.to as string | undefined)?.trim()
|
||||
|
||||
if (!to || !/^[^@\s]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(to)) {
|
||||
return Response.json(
|
||||
{ error: 'Provide a valid recipient address.', ok: false },
|
||||
{ status: 400 },
|
||||
)
|
||||
return Response.json({ error: serverText(i18n, 'testEmailInvalidRecipient'), ok: false }, { status: 400 })
|
||||
}
|
||||
|
||||
const site = await siteName(req)
|
||||
const subject = site ? serverText(i18n, 'testEmailSubject', { site }) : serverText(i18n, 'testEmailSubjectGeneric')
|
||||
const text = site ? serverText(i18n, 'testEmailBody', { site }) : serverText(i18n, 'testEmailBodyGeneric')
|
||||
|
||||
try {
|
||||
const info = await req.payload.sendEmail({
|
||||
html: '<p>This is a test message from <strong>ipal-kit</strong>. If you received it, outbound email is configured correctly.</p>',
|
||||
subject: 'ipal-kit — test email',
|
||||
text: 'This is a test message from ipal-kit. If you received it, outbound email is configured correctly.',
|
||||
html: `<p>${escapeHtml(text)}</p>`,
|
||||
subject,
|
||||
text,
|
||||
to,
|
||||
})
|
||||
|
||||
// Payload's sendEmail resolves with the adapter's result. Our adapters
|
||||
// return { sent: boolean, error?: string }; nodemailer returns info with
|
||||
// messageId. Normalize to a simple ok/message for the panel.
|
||||
// return { sent: boolean, error?: string, code?: string }; nodemailer
|
||||
// returns info with messageId. Normalize to a simple ok/message for the panel.
|
||||
const sent =
|
||||
info && typeof info === 'object' && 'sent' in info
|
||||
? (info as { sent?: boolean }).sent !== false
|
||||
: true
|
||||
|
||||
if (!sent) {
|
||||
const error = (info as { error?: string })?.error ?? 'Send failed (see server logs).'
|
||||
const failed = info as { code?: string; detail?: string; error?: string }
|
||||
req.payload.logger.error(`[ipal] Test email not sent: ${failed?.detail ?? failed?.error ?? 'unknown reason'}`)
|
||||
const error =
|
||||
failed?.code === 'not-configured'
|
||||
? serverText(i18n, 'testEmailNotConfigured')
|
||||
: serverText(i18n, 'testEmailFailed')
|
||||
return Response.json({ error, ok: false }, { status: 502 })
|
||||
}
|
||||
|
||||
return Response.json({ message: `Test email sent to ${to}.`, ok: true })
|
||||
return Response.json({ message: serverText(i18n, 'testEmailSent', { to }), ok: true })
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err)
|
||||
req.payload.logger.error(`[ipal] Test email failed: ${message}`)
|
||||
return Response.json(
|
||||
{ error: 'Send failed. Check transport settings and server logs.', ok: false },
|
||||
{ status: 502 },
|
||||
)
|
||||
return Response.json({ error: serverText(i18n, 'testEmailFailed'), ok: false }, { status: 502 })
|
||||
}
|
||||
},
|
||||
method: 'post',
|
||||
|
||||
Reference in New Issue
Block a user