Constrain PostHog consent to one normal category per banner

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é <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-24 16:35:39 +04:00
parent 7f1dffad80
commit 9fbb716b00
9 changed files with 190 additions and 27 deletions

View File

@@ -25,12 +25,53 @@ var defaultCategories = []struct {
Kind coredata.CookieCategoryKind
Rank int
GCMConsentTypes []string
PostHogConsent bool
}{
{"Necessary", "necessary", "Essential cookies required for the website to function properly.", coredata.CookieCategoryKindNecessary, 0, []string{"security_storage"}},
{"Analytics", "analytics", "Cookies that help understand how visitors interact with the website.", coredata.CookieCategoryKindNormal, 1, []string{"analytics_storage"}},
{"Advertising", "advertising", "Cookies used to deliver relevant advertisements and track campaigns.", coredata.CookieCategoryKindNormal, 2, []string{"ad_storage", "ad_user_data", "ad_personalization"}},
{"Functional", "functional", "Cookies that enable enhanced functionality and personalization.", coredata.CookieCategoryKindNormal, 3, []string{"functionality_storage", "personalization_storage"}},
{"Uncategorised", "uncategorised", "Cookies that have not been assigned to a category yet.", coredata.CookieCategoryKindUncategorised, 4, nil},
{
Name: "Necessary",
Slug: "necessary",
Description: "Essential cookies required for the website to function properly.",
Kind: coredata.CookieCategoryKindNecessary,
Rank: 0,
GCMConsentTypes: []string{"security_storage"},
PostHogConsent: false,
},
{
Name: "Analytics",
Slug: "analytics",
Description: "Cookies that help understand how visitors interact with the website.",
Kind: coredata.CookieCategoryKindNormal,
Rank: 1,
GCMConsentTypes: []string{"analytics_storage"},
PostHogConsent: true,
},
{
Name: "Advertising",
Slug: "advertising",
Description: "Cookies used to deliver relevant advertisements and track campaigns.",
Kind: coredata.CookieCategoryKindNormal,
Rank: 2,
GCMConsentTypes: []string{"ad_storage", "ad_user_data", "ad_personalization"},
PostHogConsent: false,
},
{
Name: "Functional",
Slug: "functional",
Description: "Cookies that enable enhanced functionality and personalization.",
Kind: coredata.CookieCategoryKindNormal,
Rank: 3,
GCMConsentTypes: []string{"functionality_storage", "personalization_storage"},
PostHogConsent: false,
},
{
Name: "Uncategorised",
Slug: "uncategorised",
Description: "Cookies that have not been assigned to a category yet.",
Kind: coredata.CookieCategoryKindUncategorised,
Rank: 4,
GCMConsentTypes: nil,
PostHogConsent: false,
},
}
var defaultCategoryTranslationsByLanguage = map[string]map[string]struct {