diff --git a/segment_core_string.go b/segment_core_string.go index 8821299..da407a8 100644 --- a/segment_core_string.go +++ b/segment_core_string.go @@ -143,6 +143,68 @@ func (c *CoreString) IsVendorAllowedForPurposesLI(id int, purposeIds ...int) boo return true } +// 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 { + for _, p := range purposeIds { + if !c.IsPurposeAllowed(p) && !c.IsPurposeLIAllowed(p) { + return false + } + + pr := c.GetPubRestrictionsForPurpose(p) + 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) { + return false + } + } + } + + if !c.IsPurposeAllowed(p) { + return false + } + } + + if !c.IsVendorAllowed(id) { + return false + } + + return true +} + +// 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 { + for _, p := range purposeIds { + if !c.IsPurposeAllowed(p) && !c.IsPurposeLIAllowed(p) { + return false + } + + pr := c.GetPubRestrictionsForPurpose(p) + 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) { + return false + } + } + } + + if !c.IsPurposeLIAllowed(p) { + return false + } + } + + if !c.IsVendorLIAllowed(id) { + return false + } + + return true +} + // Returns a list of publisher restrictions applied to purpose id func (c *CoreString) GetPubRestrictionsForPurpose(id int) []*PubRestriction { var pr []*PubRestriction diff --git a/tcdata.go b/tcdata.go index a64ce9c..62dc0a8 100644 --- a/tcdata.go +++ b/tcdata.go @@ -48,6 +48,18 @@ func (t *TCData) IsVendorAllowedForPurposesLI(id int, purposeIds ...int) bool { return t.CoreString.IsVendorAllowedForPurposesLI(id, purposeIds...) } +// 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 (t *TCData) IsVendorAllowedForFlexiblePurposes(id int, purposeIds ...int) bool { + return t.CoreString.IsVendorAllowedForFlexiblePurposes(id, purposeIds...) +} + +// 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 (t *TCData) IsVendorAllowedForFlexiblePurposesLI(id int, purposeIds ...int) bool { + return t.CoreString.IsVendorAllowedForFlexiblePurposesLI(id, purposeIds...) +} + // Returns a list of publisher restrictions applied to purpose id func (t *TCData) GetPubRestrictionsForPurpose(id int) []*PubRestriction { return t.CoreString.GetPubRestrictionsForPurpose(id)