Skip to content

Commit

Permalink
Merge pull request #552 from SourcePointUSA/DIA-3617-2_fix_GDPR_conse…
Browse files Browse the repository at this point in the history
…nts_disappearing_on_update

DIA-3617 fix gdpr consents disappearing on SDK update
  • Loading branch information
andresilveirah committed Feb 26, 2024
2 parents 58aa3d7 + 0561071 commit bc58b70
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
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 @@ -376,10 +375,6 @@ class SourcepointClientCoordinator: SPClientCoordinator {
localState.usnat = .empty()
}

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

return localState
}

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

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

Expand Down Expand Up @@ -603,6 +597,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 @@ -611,6 +606,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()))
}
}
}

0 comments on commit bc58b70

Please sign in to comment.