From c5f49f183345e0f95a3ef18451e574ff2144dcae Mon Sep 17 00:00:00 2001 From: Thomas Lay Date: Wed, 26 Jan 2022 15:38:57 +0100 Subject: [PATCH] Fix IsVendorAllowedForFlexiblePurposes/IsVendorAllowedForFlexiblePurposesLI --- segment_core_string.go | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/segment_core_string.go b/segment_core_string.go index da407a8..8c3c841 100644 --- a/segment_core_string.go +++ b/segment_core_string.go @@ -146,29 +146,31 @@ func (c *CoreString) IsVendorAllowedForPurposesLI(id int, purposeIds ...int) boo // Returns true if user has given consent to vendor id processing all purposes ids // or if transparency for its legitimate interest is established in accordance with publisher restrictions func (c *CoreString) IsVendorAllowedForFlexiblePurposes(id int, purposeIds ...int) bool { + if !c.IsVendorAllowed(id) && !c.IsVendorLIAllowed(id) { + return false + } + for _, p := range purposeIds { if !c.IsPurposeAllowed(p) && !c.IsPurposeLIAllowed(p) { return false } pr := c.GetPubRestrictionsForPurpose(p) + if len(pr) == 0 && (!c.IsVendorAllowed(id) || !c.IsPurposeAllowed(p)) { + return false + } + for _, r := range pr { if r.IsVendorIncluded(id) { if r.RestrictionType == RestrictionTypeNotAllowed { return false - } else if r.RestrictionType == RestrictionTypeRequireLI && !c.IsVendorLIAllowed(id) && !c.IsPurposeLIAllowed(p) { + } else if r.RestrictionType == RestrictionTypeRequireLI && (!c.IsVendorLIAllowed(id) || !c.IsPurposeLIAllowed(p)) { + return false + } else if !c.IsVendorAllowed(id) || !c.IsPurposeAllowed(p) { return false } } } - - if !c.IsPurposeAllowed(p) { - return false - } - } - - if !c.IsVendorAllowed(id) { - return false } return true @@ -177,29 +179,31 @@ func (c *CoreString) IsVendorAllowedForFlexiblePurposes(id int, purposeIds ...in // Returns true if transparency for vendor id's legitimate interest is established for all purpose ids // or if user has given consent in accordance with publisher restrictions func (c *CoreString) IsVendorAllowedForFlexiblePurposesLI(id int, purposeIds ...int) bool { + if !c.IsVendorAllowed(id) && !c.IsVendorLIAllowed(id) { + return false + } + for _, p := range purposeIds { if !c.IsPurposeAllowed(p) && !c.IsPurposeLIAllowed(p) { return false } pr := c.GetPubRestrictionsForPurpose(p) + if len(pr) == 0 && (!c.IsVendorLIAllowed(id) || !c.IsPurposeLIAllowed(p)) { + return false + } + for _, r := range pr { if r.IsVendorIncluded(id) { if r.RestrictionType == RestrictionTypeNotAllowed { return false - } else if r.RestrictionType == RestrictionTypeRequireConsent && !c.IsVendorAllowed(id) && !c.IsPurposeAllowed(p) { + } else if r.RestrictionType == RestrictionTypeRequireConsent && (!c.IsVendorAllowed(id) || !c.IsPurposeAllowed(p)) { + return false + } else if !c.IsVendorLIAllowed(id) || !c.IsPurposeLIAllowed(p) { return false } } } - - if !c.IsPurposeLIAllowed(p) { - return false - } - } - - if !c.IsVendorLIAllowed(id) { - return false } return true