Link detected cookies to existing patterns on conflict
When a cookie pattern already exists for a banner, the insert conflict caused a continue that silently dropped the detected cookie instead of linking it to the existing pattern. Load the existing pattern to obtain its ID and proceed with cookie insertion. Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -29,9 +29,9 @@ var (
|
||||
ErrCategorySlugAlreadyExists = errors.New("a category with this slug already exists in this banner")
|
||||
ErrOriginAlreadyInUse = errors.New("origin is already used by another active cookie banner")
|
||||
ErrConsentNotFound = errors.New("consent record not found")
|
||||
ErrCookieNotFound = errors.New("cookie not found")
|
||||
ErrCategoriesBannerMismatch = errors.New("source and target categories belong to different banners")
|
||||
ErrPostHogConsentKindInvalid = errors.New("PostHog consent can only be enabled on normal categories")
|
||||
ErrCookieNotFound = errors.New("cookie not found")
|
||||
ErrCategoriesBannerMismatch = errors.New("source and target categories belong to different banners")
|
||||
ErrPostHogConsentKindInvalid = errors.New("PostHog consent can only be enabled on normal categories")
|
||||
ErrCookiePatternNotFound = errors.New("cookie pattern not found")
|
||||
ErrPatternAlreadyExists = errors.New("a pattern with this name already exists in this banner")
|
||||
ErrSamePatternCategoryMove = errors.New("source and target cookie categories must be different")
|
||||
|
||||
@@ -2286,11 +2286,16 @@ func (s *Service) ReportDetectedCookies(
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot insert cookie pattern: %w", err)
|
||||
}
|
||||
if !wasInserted {
|
||||
continue
|
||||
if wasInserted {
|
||||
patternID = newPattern.ID
|
||||
inserted++
|
||||
} else {
|
||||
var existingPattern coredata.CookiePattern
|
||||
if err := existingPattern.LoadByBannerIDAndPattern(ctx, tx, scope, banner.ID, dc.Name); err != nil {
|
||||
return fmt.Errorf("cannot load existing cookie pattern: %w", err)
|
||||
}
|
||||
patternID = existingPattern.ID
|
||||
}
|
||||
patternID = newPattern.ID
|
||||
inserted++
|
||||
}
|
||||
|
||||
cookie := &coredata.Cookie{
|
||||
|
||||
Reference in New Issue
Block a user