Rename categories to consentCategories
Exclude the UNCATEGORISED category at the SQL level so the admin cookie/display/translations pages only see consent-relevant categories. Removes dead client-side UNCATEGORISED filters that are no longer needed. Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -274,6 +274,95 @@ WHERE
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (c *CookieCategories) LoadConsentCategoriesByCookieBannerID(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookieBannerID gid.GID,
|
||||
cursor *page.Cursor[CookieCategoryOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
cookie_banner_id,
|
||||
name,
|
||||
slug,
|
||||
description,
|
||||
kind,
|
||||
rank,
|
||||
gcm_consent_types,
|
||||
posthog_consent,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
cookie_categories
|
||||
WHERE
|
||||
%s
|
||||
AND cookie_banner_id = @cookie_banner_id
|
||||
AND kind != @excluded_kind
|
||||
AND %s
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"cookie_banner_id": cookieBannerID,
|
||||
"excluded_kind": CookieCategoryKindUncategorised,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, cursor.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query consent cookie categories: %w", err)
|
||||
}
|
||||
|
||||
categories, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[CookieCategory])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect consent cookie categories: %w", err)
|
||||
}
|
||||
|
||||
*c = categories
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *CookieCategories) CountConsentCategoriesByCookieBannerID(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
cookieBannerID gid.GID,
|
||||
) (int, error) {
|
||||
q := `
|
||||
SELECT
|
||||
COUNT(id)
|
||||
FROM
|
||||
cookie_categories
|
||||
WHERE
|
||||
%s
|
||||
AND cookie_banner_id = @cookie_banner_id
|
||||
AND kind != @excluded_kind
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"cookie_banner_id": cookieBannerID,
|
||||
"excluded_kind": CookieCategoryKindUncategorised,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
row := conn.QueryRow(ctx, q, args)
|
||||
|
||||
var count int
|
||||
if err := row.Scan(&count); err != nil {
|
||||
return 0, fmt.Errorf("cannot scan count: %w", err)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (c *CookieCategories) LoadAllByCookieBannerID(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
@@ -323,9 +412,9 @@ ORDER BY
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadConsentCategoriesByCookieBannerID loads all categories except
|
||||
// LoadAllConsentCategoriesByCookieBannerID loads all categories except
|
||||
// UNCATEGORISED, which is an admin-side inbox never shown to visitors.
|
||||
func (c *CookieCategories) LoadConsentCategoriesByCookieBannerID(
|
||||
func (c *CookieCategories) LoadAllConsentCategoriesByCookieBannerID(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
|
||||
Reference in New Issue
Block a user