From 9fbb716b00bca03b44305815cb3b62a35c014f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Fri, 24 Apr 2026 16:35:39 +0400 Subject: [PATCH] Constrain PostHog consent to one normal category per banner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a partial unique index ensuring only one category per banner can have posthog_consent enabled. Default it to the analytics category on banner creation, clear the previous mapping before setting a new one, and restrict the toggle to NORMAL categories in both the service layer and the console UI. Signed-off-by: Émile Ré --- .../cookies/_components/CategorySection.tsx | 1 + .../cookies/_components/EditCategoryForm.tsx | 38 +++++++------ pkg/cookiebanner/defaults.go | 51 ++++++++++++++++-- pkg/cookiebanner/errors.go | 1 + pkg/cookiebanner/service.go | 20 +++++-- pkg/coredata/cookie.go | 53 +++++++++++++++++++ pkg/coredata/cookie_category.go | 33 ++++++++++++ pkg/coredata/migrations/20260424T122219Z.sql | 17 ++++++ .../api/console/v1/cookie_banner_resolvers.go | 3 ++ 9 files changed, 190 insertions(+), 27 deletions(-) create mode 100644 pkg/coredata/migrations/20260424T122219Z.sql diff --git a/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/CategorySection.tsx b/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/CategorySection.tsx index 11f5b2f09..68fd26bcd 100644 --- a/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/CategorySection.tsx +++ b/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/CategorySection.tsx @@ -490,6 +490,7 @@ export function CategorySection({ categoryKey, onDelete }: CategorySectionProps) name={category.name} slug={category.slug} description={category.description} + kind={category.kind} gcmConsentTypes={[...category.gcmConsentTypes]} posthogConsent={category.posthogConsent} isUpdating={isUpdating} diff --git a/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/EditCategoryForm.tsx b/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/EditCategoryForm.tsx index 618c8866b..a62084c36 100644 --- a/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/EditCategoryForm.tsx +++ b/apps/console/src/pages/organizations/cookie-banners/configuration/cookies/_components/EditCategoryForm.tsx @@ -30,6 +30,7 @@ interface EditCategoryFormProps { name: string; slug: string; description: string; + kind: string; gcmConsentTypes: string[]; posthogConsent: boolean; isUpdating: boolean; @@ -41,6 +42,7 @@ export function EditCategoryForm({ name, slug, description, + kind, gcmConsentTypes, posthogConsent, isUpdating, @@ -105,23 +107,25 @@ export function EditCategoryForm({ ))} -
- -

- {__("Control PostHog tracking consent based on this category.")} -

- -
+ {kind === "NORMAL" && ( +
+ +

+ {__("Control PostHog tracking consent based on this category.")} +

+ +
+ )}