Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DIA-3283 expire consent if propertyId or accountId change #590

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class SourcepointClientCoordinator: SPClientCoordinator {
var partitionUUID: String?
}

var accountId, propertyId: Int?

var gdpr: SPGDPRConsent?
var ccpa: SPCCPAConsent?
var usnat: SPUSNatConsent?
Expand Down Expand Up @@ -336,12 +338,33 @@ class SourcepointClientCoordinator: SPClientCoordinator {
)
self.deviceManager = deviceManager

self.state = Self.setupState(from: storage, campaigns: campaigns)
self.state = Self.setupState(
from: storage,
accountId: accountId,
propertyId: propertyId,
campaigns: campaigns
)
self.storage.spState = self.state
}

static func setupState(from localStorage: SPLocalStorage, campaigns localCampaigns: SPCampaigns) -> State {
static func setupState(
from localStorage: SPLocalStorage,
accountId: Int,
propertyId: Int,
campaigns localCampaigns: SPCampaigns
) -> State {
var spState = localStorage.spState ?? .init()
if spState.accountId == nil || spState.propertyId == nil {
spState.accountId = accountId
spState.propertyId = propertyId
}

if spState.accountId != accountId || spState.propertyId != propertyId {
spState = .init()
spState.accountId = accountId
spState.propertyId = propertyId
}

if localCampaigns.gdpr != nil, spState.gdpr == nil {
spState.gdpr = localStorage.userData.gdpr?.consents ?? .empty()
spState.gdpr?.applies = localStorage.userData.gdpr?.applies ?? false
Expand Down Expand Up @@ -485,7 +508,12 @@ class SourcepointClientCoordinator: SPClientCoordinator {
}

func loadMessages(forAuthId authId: String?, pubData: SPPublisherData?, _ handler: @escaping MessagesAndConsentsHandler) {
state = Self.setupState(from: storage, campaigns: campaigns)
state = Self.setupState(
from: storage,
accountId: accountId,
propertyId: propertyId,
campaigns: campaigns
)
storage.spState = state

self.authId = authId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,26 @@ class SPClientCoordinatorSpec: QuickSpec {
}
}
}

it("when propertyId changes") {
let sameStorage = LocalStorageMock()
coordinator = coordinatorFor(propertyId: 999, campaigns: gdprCcpaCampaigns, storage: sameStorage)
coordinator.state.gdpr?.uuid = "foo"
expect(coordinator.state.gdpr?.uuid).to(equal("foo"))

coordinator = coordinatorFor(propertyId: 123, campaigns: gdprCcpaCampaigns, storage: sameStorage)
expect(coordinator.state.gdpr?.uuid).to(beNil())
}

it("when accountId changes") {
let sameStorage = LocalStorageMock()
coordinator = coordinatorFor(accountId: 999, campaigns: gdprCcpaCampaigns, storage: sameStorage)
coordinator.state.gdpr?.uuid = "foo"
expect(coordinator.state.gdpr?.uuid).to(equal("foo"))

coordinator = coordinatorFor(accountId: 123, campaigns: gdprCcpaCampaigns, storage: sameStorage)
expect(coordinator.state.gdpr?.uuid).to(beNil())
}
}
}
}