Add show_branding column to cookie banners
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é <emile@getprobo.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
15
pkg/coredata/migrations/20260422T120000Z.sql
Normal file
15
pkg/coredata/migrations/20260422T120000Z.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
-- Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
|
||||
--
|
||||
-- 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;
|
||||
Reference in New Issue
Block a user