Validate cookie policy link in banner description

Translations are no longer part of the version snapshot, so the
banner_description text must be validated at write time to ensure
the {{cookie_policy_link}} placeholder is present. Without it
the cookie policy URL silently disappears from the rendered banner.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-05-02 19:09:16 +04:00
parent 33940d63ca
commit 9d4af4d73e
4 changed files with 117 additions and 1 deletions

View File

@@ -328,7 +328,12 @@ func (r *UpsertCookieBannerTranslationRequest) Validate() error {
if json.Unmarshal(raw, &s) != nil {
continue
}
v.Check(s, "translations."+key, validator.NoHTML(), validator.MaxLen(2000))
validators := []validator.ValidatorFunc{validator.NoHTML(), validator.MaxLen(2000)}
if key == "banner_description" {
validators = append(validators, validator.ContainsSubstring("{{cookie_policy_link}}"))
}
v.Check(s, "translations."+key, validators...)
}
return v.Error()