-
Notifications
You must be signed in to change notification settings - Fork 699
/
basic_enforcement.go
57 lines (52 loc) · 2.04 KB
/
basic_enforcement.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package gdpr
import (
tcf2 "github.com/prebid/go-gdpr/vendorconsent/tcf2"
)
// BasicEnforcement determines if legal basis is satisfied for a given purpose and bidder/analytics adapter using
// the TCF2 basic enforcement algorithm. The algorithm is a high-level mode of consent confirmation
// that looks for a good-faith indication that the user has provided consent or legal basis signals
// necessary to perform a privacy-protected activity. The algorithm does not involve the GVL.
// BasicEnforcement implements the PurposeEnforcer interface
type BasicEnforcement struct {
cfg purposeConfig
}
// LegalBasis determines if legal basis is satisfied for a given purpose and bidder/analytics adapter based on user consent
// and legal basis signals.
func (be *BasicEnforcement) LegalBasis(vendorInfo VendorInfo, name string, consent tcf2.ConsentMetadata, overrides Overrides) bool {
enforcePurpose, enforceVendors := be.applyEnforceOverrides(overrides)
if !enforcePurpose && !enforceVendors {
return true
}
if be.cfg.vendorException(name) && !overrides.blockVendorExceptions {
return true
}
if !enforcePurpose && be.cfg.basicEnforcementVendor(name) {
return true
}
if enforcePurpose && consent.PurposeAllowed(be.cfg.PurposeID) && be.cfg.basicEnforcementVendor(name) {
return true
}
if enforcePurpose && consent.PurposeLITransparency(be.cfg.PurposeID) && overrides.allowLITransparency {
return true
}
if enforcePurpose && !consent.PurposeAllowed(be.cfg.PurposeID) {
return false
}
if !enforceVendors {
return true
}
return consent.VendorConsent(vendorInfo.vendorID)
}
// applyEnforceOverrides returns the enforce purpose and enforce vendor configuration values unless
// those values have been overridden, in which case they return true
func (be *BasicEnforcement) applyEnforceOverrides(overrides Overrides) (enforcePurpose, enforceVendors bool) {
enforcePurpose = be.cfg.EnforcePurpose
if overrides.enforcePurpose {
enforcePurpose = true
}
enforceVendors = be.cfg.EnforceVendors
if overrides.enforceVendors {
enforceVendors = true
}
return
}