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

@@ -22,4 +22,4 @@ export const LOCK_ICON = `<svg xmlns="http://www.w3.org/2000/svg" width="24" hei
const PROBO_LOGO = `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 25 24" fill="none" aria-hidden="true"><g clip-path="url(#pc)"><rect width="24" height="24" x=".85" fill="currentColor" rx="5.14"/><path stroke="#fff" stroke-width="3.53" d="M20.57 6.17c2.96 4.47-6.43 13.97-20.32 5.66"/><path stroke="url(#pg)" stroke-width="3.53" d="M20.57 6.17c2.96 4.47-6.43 13.97-20.32 5.66"/><path fill="#fff" d="M19.07 7.1a1.77 1.77 0 0 0 3-1.86l-1.5.93-1.5.94ZM8.82 25.18l1.71-.41c-2.3-9.67.01-14.66 2.54-16.83A6.25 6.25 0 0 1 17 6.33c1.22-.01 1.87.44 2.08.78l1.5-.94 1.5-.93c-1.1-1.74-3.16-2.46-5.13-2.44-2.03.03-4.26.81-6.17 2.45-3.9 3.35-6.16 9.92-3.67 20.33l1.72-.41Z"/></g><defs><linearGradient id="pg" x1="18.77" x2="1.2" y1="13.56" y2="13.56" gradientUnits="userSpaceOnUse"><stop stop-color="#101E1C" stop-opacity="0"/><stop offset="1" stop-color="#fff"/></linearGradient><clipPath id="pc"><rect width="24" height="24" x=".85" fill="#fff" rx="5.14"/></clipPath></defs></svg>`;
export const BRANDING = `<div class="branding" data-branding><a href="https://www.getprobo.com/cookie-policy" target="_blank" rel="noopener noreferrer">Privacy by ${PROBO_LOGO} Probo</a></div>`;
export const BRANDING = `<div class="branding" data-branding><a href="https://www.getprobo.com" target="_blank" rel="noopener noreferrer">Privacy by ${PROBO_LOGO} Probo</a></div>`;

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