feat(mail): one admin record per mail template with a locale switcher
Gap G-35-1 (supersedes D-05), tracer slice: - postcard: migration 202611130001_mail_template_base_code (base_code column and index); SyncIndex writes base_code; EnsureLocaleRows creates the <template>-<locale> rows of locales that ship no file; TemplateBase and Catalog.TemplateFor; send, preview and validation resolve a missing <template>-<locale> to the locale's customization, else the base's customization, else the base file. Names with their own file send as before. - cabana: mail locales are the translator's plus the TranslationWriter's enabled locales; sync ensures the locale rows and re-syncs when the locale set changes; record lookups admit fallback-locale rows; the record title is the base code; RecordMeta.LocaleVariants (RecordLocaleVariant) on the show and update responses. - admin: LocaleVariantSwitcher in the update form header, from meta.localeVariants, behind the unsaved-changes confirm. - tests: TestMailOverrideSmoke/locale_fallback, TestMailScreensSmoke/locales, LocaleVariantSwitcher.test.ts.
This commit is contained in:
@@ -64,11 +64,14 @@ func NewMailer(cat *Catalog, driver Driver, opts Options) Mailer {
|
||||
return &mailer{catalog: cat, driver: driver, opts: opts, source: opts.Overrides}
|
||||
}
|
||||
|
||||
// Send renders msg.Template and delivers it. It performs no locale selection;
|
||||
// the caller must pass the full dotted name, including any -en suffix. A
|
||||
// database override of the template is applied when the mailer has an
|
||||
// OverrideSource; an override that cannot be read or does not render is
|
||||
// logged and the file version is sent instead.
|
||||
// Send renders msg.Template and delivers it. It picks no locale: the caller
|
||||
// passes the full dotted name, including any -en suffix. A <template>-<locale>
|
||||
// name whose locale ships no file resolves to the default-locale version:
|
||||
// that name's customized row when there is one, else the base template's
|
||||
// customized row, else the base template's file. A database override of the
|
||||
// template is applied when the mailer has an OverrideSource; an override
|
||||
// that cannot be read or does not render is logged and the file version is
|
||||
// sent instead.
|
||||
func (m *mailer) Send(ctx context.Context, msg Message) error {
|
||||
if m == nil {
|
||||
return fmt.Errorf("postcard: mailer is nil")
|
||||
@@ -101,10 +104,17 @@ func (m *mailer) Send(ctx context.Context, msg Message) error {
|
||||
// overrides, or overrides that fail to render or to pass the safety checks,
|
||||
// it renders the file version.
|
||||
func (m *mailer) render(ctx context.Context, msg Message) (RenderedMessage, error) {
|
||||
if _, err := m.catalog.lookupTemplate(msg.Template); err != nil {
|
||||
t, err := m.catalog.resolveTemplate(msg.Template)
|
||||
if err != nil {
|
||||
return RenderedMessage{}, err
|
||||
}
|
||||
ov := m.overrides(ctx, msg.Template)
|
||||
if t.name != msg.Template && ov.Template == nil {
|
||||
// A fallback-locale name with no customization of its own sends the
|
||||
// base's. Layouts, partials and Branding are the same in both
|
||||
// answers; only the template override is taken.
|
||||
ov.Template = m.overrides(ctx, t.name).Template
|
||||
}
|
||||
// The file version carries the Branding too: it is not an override of a
|
||||
// file, and a failing override must not change how the mail looks.
|
||||
file := m.options(ov.Brand)
|
||||
|
||||
Reference in New Issue
Block a user