feat(postcard): finished default layout with logo header, footer and site name

- default.htm ports WinterCMS's default layout: wrapper, header row with
  the Branding logo (or the site name), the inner-body card and a
  copyright footer; its text wrapper ends with the footer
- built-in header and footer partials (logo/body/url, body)
- layouts get siteName (Branding site name, else the display name of
  mail.from) and year; Brand.SiteName and migration
  202611130002_mail_brand_site_name
- cabana Branding form gets site_name (trimmed, max 255), mapped into the
  Branding preview draft; en/pl copy; img.logo brand CSS
- 35-06 Task 1 (G-35-8)
This commit is contained in:
Jakub Zych
2026-11-13 20:52:52 +01:00
parent fdc2094ffc
commit 093529d45c
24 changed files with 266 additions and 30 deletions

File diff suppressed because one or more lines are too long

View File

@@ -4,6 +4,11 @@ fields:
comment: backend::lang.mail.brand.logo_comment
type: mailimage
span: full
site_name:
label: backend::lang.mail.brand.site_name
comment: backend::lang.mail.brand.site_name_comment
type: text
span: left
body_bg:
label: backend::lang.mail.brand.body_bg
type: colorpicker

View File

@@ -1745,6 +1745,7 @@ func partialUsage(code, sections string) string {
type MailBrandSetting struct {
ID uint `gorm:"column:id;primaryKey"`
LogoFileID *uint `gorm:"column:logo_file_id"`
SiteName string `gorm:"column:site_name"`
BodyBg string `gorm:"column:body_bg"`
ContentBg string `gorm:"column:content_bg"`
HeaderColor string `gorm:"column:header_color"`
@@ -1766,7 +1767,7 @@ func (MailBrandSetting) TableName() string { return postcard.BrandTable }
func (MailBrandSetting) Fillable() []string {
return []string{
"logo_file_id", "body_bg", "content_bg", "header_color", "footer_color",
"logo_file_id", "site_name", "body_bg", "content_bg", "header_color", "footer_color",
"heading_color", "text_color", "link_color", "button_text_color",
"button_primary_bg", "button_positive_bg", "button_negative_bg",
"panel_bg", "table_border_color",
@@ -1776,6 +1777,7 @@ func (MailBrandSetting) Fillable() []string {
func (MailBrandSetting) Rules() map[string]string {
return map[string]string{
"logo_file_id": "nullable",
"site_name": "nullable|max:255",
"body_bg": "nullable",
"content_bg": "nullable",
"header_color": "nullable",
@@ -1794,9 +1796,10 @@ func (MailBrandSetting) Rules() map[string]string {
var brandColourPattern = regexp.MustCompile(`^#[0-9a-f]{6}$`)
// BeforeValidate lower-cases colours, refuses anything but #rrggbb or empty,
// and checks logo_file_id is null or a library image.
// BeforeValidate trims the site name, lower-cases colours, refuses anything
// but #rrggbb or empty, and checks logo_file_id is null or a library image.
func (b *MailBrandSetting) BeforeValidate(tx *gorm.DB) error {
b.SiteName = strings.TrimSpace(b.SiteName)
details := map[string]any{}
for _, col := range []struct {
name string

View File

@@ -587,6 +587,7 @@ func (s *service) mailBrandDraft(ctx context.Context, values map[string]any) (po
ButtonNegativeBg: stringValue(values["button_negative_bg"]),
PanelBg: stringValue(values["panel_bg"]),
TableBorderColor: stringValue(values["table_border_color"]),
SiteName: strings.TrimSpace(stringValue(values["site_name"])),
}
if raw, ok := values["logo_file_id"]; ok && raw != nil {
id, err := asUint(raw)

View File

@@ -908,6 +908,24 @@ Hi **{{ .name }}**, thanks for joining the Acme blog.
t.Fatalf("stored colour = %#v", row["button_primary_bg"])
}
env.expect(t, http.StatusUnprocessableEntity, http.MethodPut, "/settings/mail_brand", rootToken, map[string]any{"logo_file_id": 999999})
// The site name is saved trimmed and is shown in the default
// layout's header and footer by the Branding preview.
saved = env.expect(t, http.StatusOK, http.MethodPut, "/settings/mail_brand", rootToken, map[string]any{"button_primary_bg": "#d66829", "site_name": " Acme Mail "})
if name := saved["data"].(map[string]any)["data"].(map[string]any)["site_name"]; name != "Acme Mail" {
t.Fatalf("stored site_name = %#v", name)
}
var stored cabana.MailBrandSetting
if err := env.gdb.First(&stored, 1).Error; err != nil || stored.SiteName != "Acme Mail" {
t.Fatalf("brand row = %+v err=%v", stored, err)
}
env.expect(t, http.StatusUnprocessableEntity, http.MethodPut, "/settings/mail_brand", rootToken, map[string]any{"site_name": strings.Repeat("x", 256)})
preview := env.expect(t, http.StatusOK, http.MethodPost, "/mail/preview", rootToken, map[string]any{
"mode": "branding", "id": 0, "values": map[string]any{"site_name": "Preview Name"},
})
if html := fmt.Sprint(preview["data"].(map[string]any)["html"]); !strings.Contains(html, "<span>Preview Name</span>") || !strings.Contains(html, "Preview Name</p>") {
t.Fatalf("branding preview lacks the site name: %s", html)
}
})
t.Run("images", func(t *testing.T) {