diff --git a/pkg/cookiebanner/worker.go b/pkg/cookiebanner/worker.go index 0f313bbcb..ed1e2981a 100644 --- a/pkg/cookiebanner/worker.go +++ b/pkg/cookiebanner/worker.go @@ -304,7 +304,7 @@ func (h *patternAnalysisHandler) adoptUncategorisedPatterns( tx, scope, banner.ID, - coredata.NewCookiePatternFilter(&prefixMatchType, nil), + coredata.NewCookiePatternFilter(&prefixMatchType, nil, nil), ); err != nil { return false, fmt.Errorf("cannot load prefix patterns: %w", err) } @@ -324,7 +324,7 @@ func (h *patternAnalysisHandler) adoptUncategorisedPatterns( tx, scope, banner.ID, - coredata.NewCookiePatternFilter(&exactMatchType, &uncategorised.ID), + coredata.NewCookiePatternFilter(&exactMatchType, &uncategorised.ID, nil), ); err != nil { return false, fmt.Errorf("cannot load uncategorised exact patterns: %w", err) } diff --git a/pkg/coredata/cookie_pattern.go b/pkg/coredata/cookie_pattern.go index 87cb5641a..76333de97 100644 --- a/pkg/coredata/cookie_pattern.go +++ b/pkg/coredata/cookie_pattern.go @@ -40,6 +40,7 @@ type ( MaxAgeSeconds *int `db:"max_age_seconds"` Description string `db:"description"` Source CookieSource `db:"source"` + Excluded bool `db:"excluded"` CreatedAt time.Time `db:"created_at"` UpdatedAt time.Time `db:"updated_at"` } @@ -89,6 +90,7 @@ SELECT max_age_seconds, description, source, + excluded, created_at, updated_at FROM @@ -141,6 +143,7 @@ SELECT max_age_seconds, description, source, + excluded, created_at, updated_at FROM @@ -197,6 +200,7 @@ SELECT max_age_seconds, description, source, + excluded, created_at, updated_at FROM @@ -264,6 +268,7 @@ SELECT max_age_seconds, description, source, + excluded, created_at, updated_at FROM @@ -345,6 +350,7 @@ SELECT max_age_seconds, description, source, + excluded, created_at, updated_at FROM @@ -396,6 +402,7 @@ INSERT INTO cookie_patterns ( max_age_seconds, description, source, + excluded, created_at, updated_at ) VALUES ( @@ -410,6 +417,7 @@ INSERT INTO cookie_patterns ( @max_age_seconds, @description, @source, + @excluded, @created_at, @updated_at ) @@ -427,6 +435,7 @@ INSERT INTO cookie_patterns ( "max_age_seconds": cp.MaxAgeSeconds, "description": cp.Description, "source": cp.Source, + "excluded": cp.Excluded, "created_at": cp.CreatedAt, "updated_at": cp.UpdatedAt, } @@ -462,6 +471,7 @@ INSERT INTO cookie_patterns ( max_age_seconds, description, source, + excluded, created_at, updated_at ) VALUES ( @@ -476,6 +486,7 @@ INSERT INTO cookie_patterns ( @max_age_seconds, @description, @source, + @excluded, @created_at, @updated_at ) @@ -494,6 +505,7 @@ ON CONFLICT (cookie_banner_id, pattern) DO NOTHING "max_age_seconds": cp.MaxAgeSeconds, "description": cp.Description, "source": cp.Source, + "excluded": cp.Excluded, "created_at": cp.CreatedAt, "updated_at": cp.UpdatedAt, } @@ -518,6 +530,7 @@ SET display_name = @display_name, max_age_seconds = @max_age_seconds, description = @description, + excluded = @excluded, updated_at = @updated_at WHERE %s @@ -532,6 +545,7 @@ WHERE "display_name": cp.DisplayName, "max_age_seconds": cp.MaxAgeSeconds, "description": cp.Description, + "excluded": cp.Excluded, "updated_at": cp.UpdatedAt, } maps.Copy(args, scope.SQLArguments()) diff --git a/pkg/coredata/cookie_pattern_filter.go b/pkg/coredata/cookie_pattern_filter.go index 31ba41118..da0cffeba 100644 --- a/pkg/coredata/cookie_pattern_filter.go +++ b/pkg/coredata/cookie_pattern_filter.go @@ -22,15 +22,18 @@ import ( type CookiePatternFilter struct { matchType *CookiePatternMatchType cookieCategoryID *gid.GID + excluded *bool } func NewCookiePatternFilter( matchType *CookiePatternMatchType, cookieCategoryID *gid.GID, + excluded *bool, ) *CookiePatternFilter { return &CookiePatternFilter{ matchType: matchType, cookieCategoryID: cookieCategoryID, + excluded: excluded, } } @@ -54,6 +57,13 @@ func (f *CookiePatternFilter) SQLFragment() string { cookie_category_id = @filter_cookie_category_id::text ELSE TRUE END + AND + CASE + WHEN @has_excluded_filter::boolean = false THEN TRUE + WHEN @has_excluded_filter::boolean = true THEN + excluded = @filter_excluded + ELSE TRUE + END )` } @@ -67,6 +77,8 @@ func (f *CookiePatternFilter) SQLArguments() pgx.StrictNamedArgs { "filter_match_type": nil, "has_cookie_category_id_filter": false, "filter_cookie_category_id": nil, + "has_excluded_filter": false, + "filter_excluded": nil, } if f.matchType != nil { @@ -79,5 +91,10 @@ func (f *CookiePatternFilter) SQLArguments() pgx.StrictNamedArgs { args["filter_cookie_category_id"] = *f.cookieCategoryID } + if f.excluded != nil { + args["has_excluded_filter"] = true + args["filter_excluded"] = *f.excluded + } + return args } diff --git a/pkg/coredata/migrations/20260501T121519Z.sql b/pkg/coredata/migrations/20260501T121519Z.sql new file mode 100644 index 000000000..ce0d7d8af --- /dev/null +++ b/pkg/coredata/migrations/20260501T121519Z.sql @@ -0,0 +1,16 @@ +-- Copyright (c) 2026 Probo Inc . +-- +-- Permission to use, copy, modify, and/or distribute this software for any +-- purpose with or without fee is hereby granted, provided that the above +-- copyright notice and this permission notice appear in all copies. +-- +-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +-- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +-- PERFORMANCE OF THIS SOFTWARE. + +ALTER TABLE cookie_patterns ADD COLUMN excluded BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE cookie_patterns ALTER COLUMN excluded DROP DEFAULT;