Add cookie banner versioning with JSONB snapshots#1028
Merged
Conversation
9f2e756 to
a153427
Compare
Introduce append-only cookie_banner_versions table with a JSONB snapshot of consent-relevant configuration (privacy policy URL, consent mode, expiry, categories and their cookies). Each version has its own state (DRAFT/PUBLISHED) separate from the banner lifecycle. Replace the banner state enum (DRAFT/PUBLISHED/DISABLED) with a simpler ACTIVE/INACTIVE toggle. Link consent records to the specific published version the visitor accepted. Signed-off-by: Émile Ré <emile@getprobo.com>
Signed-off-by: Émile Ré <emile@getprobo.com>
Add organization_id to cookie_banner_versions, cookie_categories, and cookie_consent_records so AuthorizationAttributes can return it directly without JOINing back to cookie_banners. Document the pattern in contrib/claude/coredata.md. Signed-off-by: Émile Ré <emile@getprobo.com>
605c9cc to
61cd324
Compare
There was a problem hiding this comment.
1 issue found across 12 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="pkg/cookiebanner/service.go">
<violation number="1" location="pkg/cookiebanner/service.go:254">
P1: No initial draft version is created when a new banner is created. The banner starts as `ACTIVE` with consent-relevant config and default categories, but `ensureDraftVersion` is never called in this transaction. As a result, `PublishCookieBannerVersion` will fail with `ErrNoDraftVersion` and no consent can be recorded until the user makes a separate update to trigger draft creation.
After inserting the default categories, load them back and call `ensureDraftVersion` (matching the pattern used in `CreateCookieCategory`, `UpdateCookieBanner`, etc.).</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Signed-off-by: Émile Ré <emile@getprobo.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes ENG-274
Introduce append-only cookie_banner_versions table with a JSONB snapshot of consent-relevant configuration (privacy policy URL, consent mode, expiry, categories and their cookies). Each version has its own state (DRAFT/PUBLISHED) separate from the banner lifecycle.
Replace the banner state enum (DRAFT/PUBLISHED/DISABLED) with a simpler ACTIVE/INACTIVE toggle. Link consent records to the specific published version the visitor accepted.
Summary by cubic
Adds append-only cookie banner versioning with JSONB snapshots and links each consent to the exact published version accepted. Auto-creates a draft version on banner creation and denormalizes
organization_idonto versions, categories, and consent records to avoid JOINs in auth.New Features
cookie_banner_versionswith per-versionDRAFT/PUBLISHEDand a JSONB snapshot (policy URL, consent mode, expiry, categories/cookies).PublishCookieBannerVersion,GetCookieBannerVersion,ListCookieBannerVersionsForBanner,CountCookieBannerVersionsForBanner(publishing promotes the latest draft and fails if none).cookie_banner_version_id;CreateCookieConsentRecordrequiresversionand validates it isPUBLISHED.ErrVersionNotFound,ErrVersionNotPublished,ErrBannerAlreadyActive,ErrBannerAlreadyInactive,ErrNoDraftVersion.Migration
cookie_banner_stateenum withACTIVE/INACTIVE; addcookie_banner_versions; add NOT NULLcookie_banner_version_idFK oncookie_consent_records; unique(cookie_banner_id, version); add NOT NULLorganization_idoncookie_banner_versions,cookie_categories, andcookie_consent_records.PublishCookieBanner/DisableCookieBannerwithActivateCookieBanner/DeactivateCookieBanner; useLoadActiveByID(wasLoadPublishedByID); passversionwhen creating consent; new banners start asACTIVE.PublishCookieBannerVersionbefore recording consent.Written for commit d2937c5. Summary will update on new commits.