Add tenant scoping to LoadAllByCookieBannerID
Every other LoadAll* method in coredata takes a Scoper parameter for tenant isolation. LoadAllByCookieBannerID was the only one that omitted it, making the isolation invariant depend entirely on callers first loading the banner with a scoped query. Add scope.SQLFragment to the WHERE clause to match the pattern used by the paginated sibling LoadByCookieBannerID. Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
@@ -283,7 +283,7 @@ func (s *Service) CreateCookieBanner(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var categories coredata.CookieCategories
|
var categories coredata.CookieCategories
|
||||||
if err := categories.LoadAllByCookieBannerID(ctx, tx, banner.ID); err != nil {
|
if err := categories.LoadAllByCookieBannerID(ctx, tx, scope, banner.ID); err != nil {
|
||||||
return fmt.Errorf("cannot load cookie categories: %w", err)
|
return fmt.Errorf("cannot load cookie categories: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -430,7 +430,7 @@ func (s *Service) UpdateCookieBanner(
|
|||||||
|
|
||||||
if consentChanged {
|
if consentChanged {
|
||||||
var categories coredata.CookieCategories
|
var categories coredata.CookieCategories
|
||||||
if err := categories.LoadAllByCookieBannerID(ctx, tx, banner.ID); err != nil {
|
if err := categories.LoadAllByCookieBannerID(ctx, tx, scope, banner.ID); err != nil {
|
||||||
return fmt.Errorf("cannot load cookie categories: %w", err)
|
return fmt.Errorf("cannot load cookie categories: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,7 +635,7 @@ func (s *Service) CreateCookieCategory(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var categories coredata.CookieCategories
|
var categories coredata.CookieCategories
|
||||||
if err := categories.LoadAllByCookieBannerID(ctx, tx, req.CookieBannerID); err != nil {
|
if err := categories.LoadAllByCookieBannerID(ctx, tx, scope, req.CookieBannerID); err != nil {
|
||||||
return fmt.Errorf("cannot load cookie categories: %w", err)
|
return fmt.Errorf("cannot load cookie categories: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -779,7 +779,7 @@ func (s *Service) UpdateCookieCategory(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var categories coredata.CookieCategories
|
var categories coredata.CookieCategories
|
||||||
if err := categories.LoadAllByCookieBannerID(ctx, tx, category.CookieBannerID); err != nil {
|
if err := categories.LoadAllByCookieBannerID(ctx, tx, scope, category.CookieBannerID); err != nil {
|
||||||
return fmt.Errorf("cannot load cookie categories: %w", err)
|
return fmt.Errorf("cannot load cookie categories: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -829,7 +829,7 @@ func (s *Service) DeleteCookieCategory(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var categories coredata.CookieCategories
|
var categories coredata.CookieCategories
|
||||||
if err := categories.LoadAllByCookieBannerID(ctx, tx, bannerID); err != nil {
|
if err := categories.LoadAllByCookieBannerID(ctx, tx, scope, bannerID); err != nil {
|
||||||
return fmt.Errorf("cannot load cookie categories: %w", err)
|
return fmt.Errorf("cannot load cookie categories: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -212,6 +212,7 @@ WHERE
|
|||||||
func (c *CookieCategories) LoadAllByCookieBannerID(
|
func (c *CookieCategories) LoadAllByCookieBannerID(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
conn pg.Querier,
|
conn pg.Querier,
|
||||||
|
scope Scoper,
|
||||||
cookieBannerID gid.GID,
|
cookieBannerID gid.GID,
|
||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
@@ -229,12 +230,16 @@ SELECT
|
|||||||
FROM
|
FROM
|
||||||
cookie_categories
|
cookie_categories
|
||||||
WHERE
|
WHERE
|
||||||
cookie_banner_id = @cookie_banner_id
|
%s
|
||||||
|
AND cookie_banner_id = @cookie_banner_id
|
||||||
ORDER BY
|
ORDER BY
|
||||||
rank ASC, id ASC;
|
rank ASC, id ASC;
|
||||||
`
|
`
|
||||||
|
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{"cookie_banner_id": cookieBannerID}
|
args := pgx.StrictNamedArgs{"cookie_banner_id": cookieBannerID}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
rows, err := conn.Query(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user