Fix PR review comments on cookie banner branding

- 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é <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-22 15:02:59 +04:00
parent b1607d76c5
commit d71915abd4
6 changed files with 18 additions and 7 deletions

View File

@@ -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
}

View File

@@ -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)
}

View File

@@ -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;

View File

@@ -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
}

View File

@@ -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),