Fix PR review comments on cookie banner i18n

Address locale normalization for region-tagged values, guard
language detection for non-DOM runtimes, validate DefaultLanguage
on update, pass translated texts through the deactivation flow,
handle slug collisions in migration, add organizations FK, fix
consent migration from name-keyed to slug-keyed data, render all
template placeholders in previews, and wrap helper text for i18n.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-23 23:41:37 +04:00
parent fa7a9c96c1
commit 2b6f131f43
17 changed files with 89 additions and 55 deletions

View File

@@ -16,6 +16,8 @@ package cookiebanner
import "go.probo.inc/probo/pkg/coredata"
var SupportedLanguages = []string{"en", "fr", "de", "es"}
var defaultCategories = []struct {
Name string
Slug string

View File

@@ -177,6 +177,7 @@ func (r *UpdateCookieBannerRequest) Validate() error {
v.Check(r.PrivacyPolicyURL, "privacy_policy_url", validator.URL())
v.Check(r.ConsentExpiryDays, "consent_expiry_days", validator.Min(1))
v.Check(r.ConsentMode, "consent_mode", validator.OneOfSlice(coredata.CookieConsentModes()))
v.Check(r.DefaultLanguage, "default_language", validator.OneOfSlice(SupportedLanguages))
return v.Error()
}

View File

@@ -18,7 +18,7 @@ ALTER TABLE cookie_banners ALTER COLUMN default_language DROP DEFAULT;
CREATE TABLE cookie_banner_translations (
id TEXT PRIMARY KEY,
tenant_id TEXT NOT NULL,
organization_id TEXT NOT NULL,
organization_id TEXT NOT NULL REFERENCES organizations(id),
cookie_banner_id TEXT NOT NULL REFERENCES cookie_banners(id) ON DELETE CASCADE,
language TEXT NOT NULL,
translations JSONB NOT NULL,

View File

@@ -16,7 +16,22 @@ ALTER TABLE cookie_categories
ADD COLUMN slug TEXT NOT NULL DEFAULT '';
UPDATE cookie_categories
SET slug = LOWER(REGEXP_REPLACE(REGEXP_REPLACE(name, '[^a-zA-Z0-9]+', '-', 'g'), '^-|-$', '', 'g'));
SET slug = COALESCE(
NULLIF(LOWER(REGEXP_REPLACE(REGEXP_REPLACE(name, '[^a-zA-Z0-9]+', '-', 'g'), '^-|-$', '', 'g')), ''),
'category-' || SUBSTR(id, 1, 8)
);
WITH dupes AS (
SELECT id,
cookie_banner_id,
slug,
ROW_NUMBER() OVER (PARTITION BY cookie_banner_id, slug ORDER BY created_at) AS rn
FROM cookie_categories
)
UPDATE cookie_categories
SET slug = cookie_categories.slug || '-' || dupes.rn
FROM dupes
WHERE cookie_categories.id = dupes.id AND dupes.rn > 1;
ALTER TABLE cookie_categories ALTER COLUMN slug DROP DEFAULT;