From d71915abd4a8e404d9e5ec030fc89bbed2cf9c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Wed, 22 Apr 2026 15:02:59 +0400 Subject: [PATCH] Fix PR review comments on cookie banner branding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add scope parameter to UpdateShowBranding to prevent cross-tenant updates - Use cmd.Context() instead of context.Background() in proboctl CLI - Drop SQL column default after backfill in migration - Add bounds check for int-to-int32 conversion in PG_POOL_SIZE - Update branding link to getprobo.com homepage Signed-off-by: Émile Ré --- packages/cookie-banner/src/html.ts | 2 +- pkg/cookiebanner/service.go | 2 +- pkg/coredata/cookie_banner.go | 13 ++++++++++--- pkg/coredata/migrations/20260422T120000Z.sql | 1 + pkg/proboctl/cookiebanner/cookiebanner.go | 3 +-- pkg/proboctl/root.go | 4 ++++ 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/cookie-banner/src/html.ts b/packages/cookie-banner/src/html.ts index 595e3195a..a781371d2 100644 --- a/packages/cookie-banner/src/html.ts +++ b/packages/cookie-banner/src/html.ts @@ -22,4 +22,4 @@ export const LOCK_ICON = ``; -export const BRANDING = ``; +export const BRANDING = ``; diff --git a/pkg/cookiebanner/service.go b/pkg/cookiebanner/service.go index a7ad020af..25111ae29 100644 --- a/pkg/cookiebanner/service.go +++ b/pkg/cookiebanner/service.go @@ -1587,7 +1587,7 @@ func (s *Service) SetShowBranding( 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 err := banner.UpdateShowBranding(ctx, tx, coredata.NewNoScope(), show); err != nil { if errors.Is(err, coredata.ErrResourceNotFound) { return ErrBannerNotFound } diff --git a/pkg/coredata/cookie_banner.go b/pkg/coredata/cookie_banner.go index 42093decc..2126697f7 100644 --- a/pkg/coredata/cookie_banner.go +++ b/pkg/coredata/cookie_banner.go @@ -431,6 +431,7 @@ WHERE func (b *CookieBanner) UpdateShowBranding( ctx context.Context, tx pg.Tx, + scope Scoper, show bool, ) error { q := ` @@ -439,14 +440,20 @@ SET show_branding = @show_branding, updated_at = @updated_at WHERE - id = @id + %s + AND id = @id ` - result, err := tx.Exec(ctx, q, pgx.StrictNamedArgs{ + q = fmt.Sprintf(q, scope.SQLFragment()) + + args := pgx.StrictNamedArgs{ "id": b.ID, "show_branding": show, "updated_at": time.Now(), - }) + } + maps.Copy(args, scope.SQLArguments()) + + result, err := tx.Exec(ctx, q, args) if err != nil { return fmt.Errorf("cannot update cookie banner show_branding: %w", err) } diff --git a/pkg/coredata/migrations/20260422T120000Z.sql b/pkg/coredata/migrations/20260422T120000Z.sql index 99d55ff4f..608d88e21 100644 --- a/pkg/coredata/migrations/20260422T120000Z.sql +++ b/pkg/coredata/migrations/20260422T120000Z.sql @@ -13,3 +13,4 @@ -- PERFORMANCE OF THIS SOFTWARE. ALTER TABLE cookie_banners ADD COLUMN show_branding BOOLEAN NOT NULL DEFAULT TRUE; +ALTER TABLE cookie_banners ALTER COLUMN show_branding DROP DEFAULT; diff --git a/pkg/proboctl/cookiebanner/cookiebanner.go b/pkg/proboctl/cookiebanner/cookiebanner.go index e0f12d7af..f3f08b72a 100644 --- a/pkg/proboctl/cookiebanner/cookiebanner.go +++ b/pkg/proboctl/cookiebanner/cookiebanner.go @@ -15,7 +15,6 @@ package cookiebanner import ( - "context" "fmt" "strconv" @@ -61,7 +60,7 @@ func newCmdSetBranding(newPG pgClientFactory) *cobra.Command { defer pgClient.Close() svc := cookiebanner.NewService(pgClient) - if err := svc.SetShowBranding(context.Background(), bannerID, show); err != nil { + if err := svc.SetShowBranding(cmd.Context(), bannerID, show); err != nil { return err } diff --git a/pkg/proboctl/root.go b/pkg/proboctl/root.go index bfe6fc4b6..a8a87a0b4 100644 --- a/pkg/proboctl/root.go +++ b/pkg/proboctl/root.go @@ -16,6 +16,7 @@ package proboctl import ( "fmt" + "math" "os" "strconv" @@ -72,6 +73,9 @@ func newPGClient(flagDSN string) (*pg.Client, error) { } poolSize := envIntOrDefault("PG_POOL_SIZE", 2) + if poolSize < 0 || poolSize > math.MaxInt32 { + return nil, fmt.Errorf("PG_POOL_SIZE %d out of range", poolSize) + } opts := []pg.Option{ pg.WithAddr(addr),