feat(cabana): mail templates list grouped by template with per-locale status

Gap G-35-1 (supersedes D-05; D-06 reset and D-07 drift per locale):
- the templates list keeps one row per template (the base row, or the
  lowest variant when only variants ship) with a Customized locales
  column (Default, then locale codes, at most three then +N);
- row states and the status filter aggregate over the template's
  locale versions; the locale filter is removed;
- a not-customized locale without a file shows the base row's current
  subject, body and layout; its info partial says so, its file version
  compares with the base file, and Reset returns it to the base file
  (postcard.ResetOverride accepts a fallback-locale code);
- copy: mail.template.customized_locales, mail.info_locale_default,
  mail.info_locale_fallback (en/pl);
- tests: TestMailScreensSmoke/locales_list, templates and drift updated,
  TestMailDrift on the grouped row, TestMailTemplateFilterScopes.
This commit is contained in:
Jakub Zych
2026-11-13 20:39:45 +01:00
parent 52c9c7eb18
commit 67f7164302
14 changed files with 460 additions and 118 deletions

View File

@@ -360,7 +360,7 @@ A draft is rendered by the code that renders a send, with the mailer's CSS and t
`postcard.EnsureLocaleRows` adds the rows of the locales a template ships no file for: for every base template and every given locale except the default one, the row `<template>-<locale>` with that locale, the template as `base_code`, and the template file's subject, body, layout and hash. Such a row sends the default-locale version until it is customized (see "Locale variants"); its `file_hash` follows the template's file, so a customized one shows as outdated when that file changes. The default locale gets no row: the template's own file is its version. Like `postcard.SyncIndex` it writes nothing for a matching row, deletes nothing and is safe to run in several processes at once; it can be limited to some templates.
`postcard.ResetOverride` returns one row to its file version and clears `is_custom`, `base_hash` and `customized_at`. A database-only layout has no file version and is refused.
`postcard.ResetOverride` returns one row to its file version and clears `is_custom`, `base_hash` and `customized_at`. The file version of a locale row without a file of its own is the base template's file, so its reset makes it send the default-locale version again. A database-only layout has no file version and is refused.
`postcard.FormatTemplate`, `postcard.FormatLayout` and `postcard.FormatPartial` write content in the file format, so a file version and an override can be compared line by line. `postcard.TemplateLocale` reads the locale from a name such as `acme.blog::mail.welcome-en`, given the application's locales.

View File

@@ -564,8 +564,10 @@ func rowName(title, full string) string {
// ResetOverride returns one file-backed row to its file version: the content
// columns mirror the file again and is_custom, base_hash and customized_at
// are cleared. kind is KindTemplate, KindLayout or KindPartial and code the
// row's code. A database-only layout has no file version: it is refused, and
// so is a code cat does not hold.
// row's code. The file version of a fallback-locale template row (a
// <template>-<locale> code whose locale ships no file) is the base
// template's file (Catalog.TemplateFor). A database-only layout has no file
// version: it is refused, and so is a code cat does not hold.
func ResetOverride(ctx context.Context, db *gorm.DB, cat *Catalog, kind Kind, code string) error {
if db == nil {
return fmt.Errorf("postcard: reset %s: database is nil", code)
@@ -577,7 +579,8 @@ func ResetOverride(ctx context.Context, db *gorm.DB, cat *Catalog, kind Kind, co
var res *gorm.DB
switch kind {
case KindTemplate:
f, ok := cat.Template(code)
// A fallback-locale row returns to the base template's file.
f, ok := cat.TemplateFor(code)
if !ok {
return fmt.Errorf("postcard: reset %s: no file version", code)
}