mirror of
https://github.com/cubixle/iabtcfv2.git
synced 2026-04-24 23:54:43 +01:00
Add functions to get a list of publisher restrictions for purpose + check if vendor has consent or LI for a list of purposes
This commit is contained in:
@@ -141,6 +141,9 @@ To verify that a legal basis is established for a purpose or a vendor, use the f
|
||||
| IsPurposeLIAllowed | int | Returns `true` if legitimate interest is established for purpose id and user didn't exercise their right to object |
|
||||
| IsVendorAllowed | int | Returns `true` if user has given consent to vendor id processing their personal data |
|
||||
| IsVendorLIAllowed | int | Returns `true` if transparency for vendor id's legitimate interest is established and user didn't exercise their right to object |
|
||||
| IsVendorAllowedForPurposes | (int, ...int) | Returns `true` if user has given consent to vendor id processing all purposes ids and publisher hasn't set restrictions for them |
|
||||
| IsVendorAllowedForPurposesLI | (int, ...int) | Returns `true` if transparency for vendor id's legitimate interest is established for all purpose ids and publisher hasn't set restrictions for them |
|
||||
| GetPubRestrictionsForPurpose | int | Returns a list of publisher restrictions applied to purpose id |
|
||||
|
||||
NOTE: For convenience the `CoreString` functions are also available from the `TCData` structure.
|
||||
|
||||
|
||||
@@ -93,6 +93,77 @@ func (c *CoreString) IsVendorLIAllowed(id int) bool {
|
||||
return c.VendorsLITransparency[id]
|
||||
}
|
||||
|
||||
// Returns true if user has given consent to vendor id processing all purposes ids
|
||||
// and publisher hasn't set restrictions for them
|
||||
func (c *CoreString) IsVendorAllowedForPurposes(id int, purposeIds ...int) bool {
|
||||
if !c.IsVendorAllowed(id) {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, p := range purposeIds {
|
||||
if !c.IsPurposeAllowed(p) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
for _, p := range purposeIds {
|
||||
pr := c.GetPubRestrictionsForPurpose(p)
|
||||
for _, r := range pr {
|
||||
if (r.RestrictionType == RestrictionTypeNotAllowed || r.RestrictionType == RestrictionTypeRequireLI) && r.IsVendorIncluded(id) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Returns true if transparency for vendor id's legitimate interest is established for all purpose ids
|
||||
// and publisher hasn't set restrictions for them
|
||||
func (c *CoreString) IsVendorAllowedForPurposesLI(id int, purposeIds ...int) bool {
|
||||
if !c.IsVendorLIAllowed(id) {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, p := range purposeIds {
|
||||
if !c.IsPurposeLIAllowed(p) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
for _, p := range purposeIds {
|
||||
pr := c.GetPubRestrictionsForPurpose(p)
|
||||
for _, r := range pr {
|
||||
if (r.RestrictionType == RestrictionTypeNotAllowed || r.RestrictionType == RestrictionTypeRequireConsent) && r.IsVendorIncluded(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
|
||||
for _, r := range c.PubRestrictions {
|
||||
if r.PurposeId == id {
|
||||
pr = append(pr, r)
|
||||
}
|
||||
}
|
||||
return pr
|
||||
}
|
||||
|
||||
// Returns true if restriction is applied to vendor id
|
||||
func (p *PubRestriction) IsVendorIncluded(id int) bool {
|
||||
for _, entry := range p.RangeEntries {
|
||||
if entry.StartVendorID <= id && id <= entry.EndVendorID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Returns structure as a base64 raw url encoded string
|
||||
func (c *CoreString) Encode() string {
|
||||
bitSize := 230
|
||||
|
||||
17
tcdata.go
17
tcdata.go
@@ -36,6 +36,23 @@ func (t *TCData) IsVendorLIAllowed(id int) bool {
|
||||
return t.CoreString.IsVendorLIAllowed(id)
|
||||
}
|
||||
|
||||
// Returns true if user has given consent to vendor id processing all purposes ids
|
||||
// and publisher hasn't set restrictions for them
|
||||
func (t *TCData) IsVendorAllowedForPurposes(id int, purposeIds ...int) bool {
|
||||
return t.CoreString.IsVendorAllowedForPurposes(id, purposeIds...)
|
||||
}
|
||||
|
||||
// Returns true if transparency for vendor id's legitimate interest is established for all purpose ids
|
||||
// and publisher hasn't set restrictions for them
|
||||
func (t *TCData) IsVendorAllowedForPurposesLI(id int, purposeIds ...int) bool {
|
||||
return t.CoreString.IsVendorAllowedForPurposesLI(id, purposeIds...)
|
||||
}
|
||||
|
||||
// Returns a list of publisher restrictions applied to purpose id
|
||||
func (t *TCData) GetPubRestrictionsForPurpose(id int) []*PubRestriction {
|
||||
return t.CoreString.GetPubRestrictionsForPurpose(id)
|
||||
}
|
||||
|
||||
// Returns structure as a base64 raw url encoded string
|
||||
func (t *TCData) ToTCString() string {
|
||||
var segments []string
|
||||
|
||||
Reference in New Issue
Block a user