From 3994ab1d8ba41c46a9f7df0137a1982406377fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Wed, 22 Apr 2026 12:38:28 +0400 Subject: [PATCH] Add show_branding column to cookie banners MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Internal-only flag (defaults to true) that controls whether "Powered by Probo" branding appears on the cookie banner. Read directly from the live row (not the version snapshot) since branding is cosmetic, not consent-relevant. Signed-off-by: Émile Ré --- pkg/cookiebanner/service.go | 24 +++++++++++ pkg/coredata/cookie_banner.go | 42 ++++++++++++++++++++ pkg/coredata/migrations/20260422T120000Z.sql | 15 +++++++ 3 files changed, 81 insertions(+) create mode 100644 pkg/coredata/migrations/20260422T120000Z.sql diff --git a/pkg/cookiebanner/service.go b/pkg/cookiebanner/service.go index 0c1ac5e6f..a7ad020af 100644 --- a/pkg/cookiebanner/service.go +++ b/pkg/cookiebanner/service.go @@ -132,6 +132,7 @@ type ( PrivacyPolicyURL string `json:"privacy_policy_url"` ConsentExpiryDays int `json:"consent_expiry_days"` ConsentMode string `json:"consent_mode"` + ShowBranding bool `json:"show_branding"` Categories []coredata.CookieBannerVersionSnapshotCategory `json:"categories"` } @@ -412,6 +413,7 @@ func (s *Service) CreateCookieBanner( PrivacyPolicyURL: req.PrivacyPolicyURL, ConsentExpiryDays: req.ConsentExpiryDays, ConsentMode: req.ConsentMode, + ShowBranding: true, CreatedAt: now, UpdatedAt: now, } @@ -1561,6 +1563,7 @@ func (s *Service) GetActiveBannerConfig( PrivacyPolicyURL: snapshot.PrivacyPolicyURL, ConsentExpiryDays: snapshot.ConsentExpiryDays, ConsentMode: snapshot.ConsentMode, + ShowBranding: banner.ShowBranding, Categories: snapshot.Categories, } @@ -1574,6 +1577,27 @@ func (s *Service) GetActiveBannerConfig( return config, nil } +func (s *Service) SetShowBranding( + ctx context.Context, + bannerID gid.GID, + show bool, +) error { + return s.pg.WithTx( + ctx, + func(ctx context.Context, tx pg.Tx) error { + var banner coredata.CookieBanner + banner.ID = bannerID + if err := banner.UpdateShowBranding(ctx, tx, show); err != nil { + if errors.Is(err, coredata.ErrResourceNotFound) { + return ErrBannerNotFound + } + return fmt.Errorf("cannot update show_branding: %w", err) + } + return nil + }, + ) +} + func (s *Service) GetVisitorConsent( ctx context.Context, bannerID gid.GID, diff --git a/pkg/coredata/cookie_banner.go b/pkg/coredata/cookie_banner.go index e0fb7c68b..42093decc 100644 --- a/pkg/coredata/cookie_banner.go +++ b/pkg/coredata/cookie_banner.go @@ -38,6 +38,7 @@ type ( PrivacyPolicyURL string `db:"privacy_policy_url"` ConsentExpiryDays int `db:"consent_expiry_days"` ConsentMode CookieConsentMode `db:"consent_mode"` + ShowBranding bool `db:"show_branding"` CreatedAt time.Time `db:"created_at"` UpdatedAt time.Time `db:"updated_at"` } @@ -85,6 +86,7 @@ SELECT privacy_policy_url, consent_expiry_days, consent_mode, + show_branding, created_at, updated_at FROM @@ -134,6 +136,7 @@ SELECT privacy_policy_url, consent_expiry_days, consent_mode, + show_branding, created_at, updated_at FROM @@ -184,6 +187,7 @@ SELECT privacy_policy_url, consent_expiry_days, consent_mode, + show_branding, created_at, updated_at FROM @@ -240,6 +244,7 @@ SELECT privacy_policy_url, consent_expiry_days, consent_mode, + show_branding, created_at, updated_at FROM @@ -323,6 +328,7 @@ INSERT INTO cookie_banners ( privacy_policy_url, consent_expiry_days, consent_mode, + show_branding, created_at, updated_at ) VALUES ( @@ -335,6 +341,7 @@ INSERT INTO cookie_banners ( @privacy_policy_url, @consent_expiry_days, @consent_mode, + @show_branding, @created_at, @updated_at ) @@ -350,6 +357,7 @@ INSERT INTO cookie_banners ( "privacy_policy_url": b.PrivacyPolicyURL, "consent_expiry_days": b.ConsentExpiryDays, "consent_mode": b.ConsentMode, + "show_branding": b.ShowBranding, "created_at": b.CreatedAt, "updated_at": b.UpdatedAt, } @@ -381,6 +389,7 @@ SET privacy_policy_url = @privacy_policy_url, consent_expiry_days = @consent_expiry_days, consent_mode = @consent_mode, + show_branding = @show_branding, updated_at = @updated_at WHERE %s @@ -397,6 +406,7 @@ WHERE "privacy_policy_url": b.PrivacyPolicyURL, "consent_expiry_days": b.ConsentExpiryDays, "consent_mode": b.ConsentMode, + "show_branding": b.ShowBranding, "updated_at": b.UpdatedAt, } maps.Copy(args, scope.SQLArguments()) @@ -418,6 +428,38 @@ WHERE return nil } +func (b *CookieBanner) UpdateShowBranding( + ctx context.Context, + tx pg.Tx, + show bool, +) error { + q := ` +UPDATE cookie_banners +SET + show_branding = @show_branding, + updated_at = @updated_at +WHERE + id = @id +` + + result, err := tx.Exec(ctx, q, pgx.StrictNamedArgs{ + "id": b.ID, + "show_branding": show, + "updated_at": time.Now(), + }) + if err != nil { + return fmt.Errorf("cannot update cookie banner show_branding: %w", err) + } + + if result.RowsAffected() == 0 { + return ErrResourceNotFound + } + + b.ShowBranding = show + + return nil +} + func (b *CookieBanner) Delete( ctx context.Context, tx pg.Tx, diff --git a/pkg/coredata/migrations/20260422T120000Z.sql b/pkg/coredata/migrations/20260422T120000Z.sql new file mode 100644 index 000000000..99d55ff4f --- /dev/null +++ b/pkg/coredata/migrations/20260422T120000Z.sql @@ -0,0 +1,15 @@ +-- Copyright (c) 2026 Probo Inc . +-- +-- Permission to use, copy, modify, and/or distribute this software for any +-- purpose with or without fee is hereby granted, provided that the above +-- copyright notice and this permission notice appear in all copies. +-- +-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +-- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +-- PERFORMANCE OF THIS SOFTWARE. + +ALTER TABLE cookie_banners ADD COLUMN show_branding BOOLEAN NOT NULL DEFAULT TRUE;