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-3617 fix gdpr consents disappearing on SDK update #552

Merged
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
4 changes: 2 additions & 2 deletions ConsentViewController/Classes/Consents/SPCCPAConsent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ extension SPUSPString {
status = try container.decode(CCPAConsentStatus.self, forKey: .status)
rejectedVendors = try container.decode([String].self, forKey: .rejectedVendors)
rejectedCategories = try container.decode([String].self, forKey: .rejectedCategories)
signedLspa = try container.decode(Bool.self, forKey: .signedLspa)
signedLspa = try container.decodeIfPresent(Bool.self, forKey: .signedLspa) ?? false
uuid = try container.decodeIfPresent(String.self, forKey: .uuid)
childPmId = try container.decodeIfPresent(String.self, forKey: .childPmId)
consentStatus = try (try? container.decode(ConsentStatus.self, forKey: .consentStatus)) ?? ConsentStatus(from: decoder)
webConsentPayload = try container.decodeIfPresent(SPWebConsentPayload.self, forKey: .webConsentPayload)
applies = try container.decodeIfPresent(Bool.self, forKey: .applies) ?? false
GPPData = try container.decodeIfPresent(SPJson.self, forKey: .GPPData) ?? SPJson()
expirationDate = try container.decode(SPDate.self, forKey: .expirationDate)
expirationDate = try container.decodeIfPresent(SPDate.self, forKey: .expirationDate) ?? .distantFuture()
if let date = try container.decodeIfPresent(SPDate.self, forKey: .dateCreated) {
dateCreated = date
}
Expand Down
5 changes: 4 additions & 1 deletion ConsentViewController/Classes/SPConsentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import Foundation
import UIKit
// swiftlint:disable file_length

// swiftlint:disable file_length function_parameter_count
@objcMembers public class SPConsentManager: NSObject {
static let DefaultTimeout = TimeInterval(30)
public static var shouldCallErrorMetrics = true
Expand Down Expand Up @@ -701,3 +702,5 @@ func mainSync<T>(execute work: () throws -> T) rethrows -> T {

return try DispatchQueue.main.sync { try work() }
}

// swiftlint:enable function_parameter_count
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extension SPSampleable {

class SourcepointClientCoordinator: SPClientCoordinator {
struct State: Codable {
static let version = 2
static let version = 3

struct GDPRMetaData: Codable, SPSampleable, Equatable {
var additionsChangeDate = SPDate.now()
Expand Down Expand Up @@ -197,8 +197,7 @@ class SourcepointClientCoordinator: SPClientCoordinator {

var needsNewConsentData: Bool {
migratingUser || needsNewUSNatData || transitionCCPAUSNat || (
state.localVersion != nil && state.localVersion != State.version &&
(
state.localVersion != State.version && (
state.gdpr?.uuid != nil ||
state.ccpa?.uuid != nil ||
state.usnat?.uuid != nil
Expand Down Expand Up @@ -373,10 +372,6 @@ class SourcepointClientCoordinator: SPClientCoordinator {
localState.usnat = .empty()
}

if localState.localVersion == nil {
localState.localVersion = State.version
}

return localState
}

Expand Down Expand Up @@ -568,7 +563,6 @@ class SourcepointClientCoordinator: SPClientCoordinator {
)
}

state.localVersion = State.version
storage.spState = state
}

Expand Down Expand Up @@ -600,6 +594,7 @@ class SourcepointClientCoordinator: SPClientCoordinator {
) { result in
switch result {
case .success(let response):
self.state.localVersion = State.version
self.handleConsentStatusResponse(response)

case .failure(let error):
Expand All @@ -608,6 +603,7 @@ class SourcepointClientCoordinator: SPClientCoordinator {
next()
}
} else {
self.state.localVersion = State.version
next()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public func containQueryParam(_ name: String, withValue value: String) -> Predic
guard let actual = try actual.evaluate(),
let params = actual.queryParams
else {
return PredicateResult(bool: false, message: .fail("could not get query params from URL(\(try? actual.evaluate()?.absoluteString))"))
return PredicateResult(bool: false, message: .fail("could not get query params from URL(\(try? actual.evaluate()?.absoluteString as Any))"))
}
var pass = false
var message = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class SPCCPAConsentsSpec: QuickSpec {
"rejectedCategories": [],
"consentStatus": {},
"signedLspa": false,
"expirationDate": "2023-02-06T16:20:53.707Z",
"GPPData": {
"foo": "bar"
}
Expand All @@ -50,7 +49,7 @@ class SPCCPAConsentsSpec: QuickSpec {
expect(consent.rejectedCategories).to(beEmpty())
expect(consent.signedLspa).to(beFalse())
expect(consent.GPPData.dictionaryValue?["foo"] as? String).to(equal("bar"))
expect(consent.expirationDate).to(equal(year: 2023, month: 2, day: 6))
expect(consent.expirationDate).to(equal(.distantFuture()))
}
}
}
Loading