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:
Émile Ré
2026-05-04 19:51:22 +04:00
parent 3254c6ddec
commit c26b9c0abe
10 changed files with 113 additions and 27 deletions

View File

@@ -428,7 +428,7 @@ func (s *Service) ensureDraftVersionForBanner(
}
var categories coredata.CookieCategories
if err := categories.LoadConsentCategoriesByCookieBannerID(ctx, tx, scope, bannerID); err != nil {
if err := categories.LoadAllConsentCategoriesByCookieBannerID(ctx, tx, scope, bannerID); err != nil {
return nil, fmt.Errorf("cannot load cookie categories: %w", err)
}
@@ -1078,7 +1078,7 @@ func (s *Service) ListCookieCategoriesForBanner(
err := s.pg.WithConn(
ctx,
func(ctx context.Context, conn pg.Querier) error {
if err := categories.LoadByCookieBannerID(ctx, conn, scope, bannerID, cursor); err != nil {
if err := categories.LoadConsentCategoriesByCookieBannerID(ctx, conn, scope, bannerID, cursor); err != nil {
return fmt.Errorf("cannot list cookie categories: %w", err)
}
@@ -1105,7 +1105,7 @@ func (s *Service) CountCookieCategoriesForBanner(
var categories coredata.CookieCategories
var err error
count, err = categories.CountByCookieBannerID(ctx, conn, scope, bannerID)
count, err = categories.CountConsentCategoriesByCookieBannerID(ctx, conn, scope, bannerID)
if err != nil {
return fmt.Errorf("cannot count cookie categories: %w", err)
}
@@ -1943,7 +1943,7 @@ func (s *Service) GetActiveBannerConfig(
}
var categories coredata.CookieCategories
if err := categories.LoadConsentCategoriesByCookieBannerID(ctx, conn, scope, banner.ID); err != nil {
if err := categories.LoadAllConsentCategoriesByCookieBannerID(ctx, conn, scope, banner.ID); err != nil {
return fmt.Errorf("cannot load cookie categories: %w", err)
}

View File

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

View File

@@ -43,8 +43,8 @@ func (r *cookieBannerResolver) Organization(ctx context.Context, obj *types.Cook
return types.NewOrganization(organization), nil
}
// Categories is the resolver for the categories field.
func (r *cookieBannerResolver) Categories(ctx context.Context, obj *types.CookieBanner, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.CookieCategoryOrderBy) (*types.CookieCategoryConnection, error) {
// ConsentCategories is the resolver for the consentCategories field.
func (r *cookieBannerResolver) ConsentCategories(ctx context.Context, obj *types.CookieBanner, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.CookieCategoryOrderBy) (*types.CookieCategoryConnection, error) {
if err := r.authorize(ctx, obj.ID, probo.ActionCookieCategoryList); err != nil {
return nil, err
}

View File

@@ -102,7 +102,7 @@ type CookieBanner implements Node {
organization: Organization @goField(forceResolver: true)
categories(
consentCategories(
first: Int
after: CursorKey
last: Int