Skip to content

[DIA-2151] Removed singleShotPM from ConsentActionImpl #657

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

Merged
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
1 change: 0 additions & 1 deletion cmplibrary/src/main/assets/js_receiver.js
Original file line number Diff line number Diff line change
@@ -34,7 +34,6 @@ function actionFromPM(payload) {
return {
localPmId: window.localPmId,
legislation: window.spLegislation,
singleShot: window.isSingleShot,
name: payload.name,
actionType: payload.actionType,
choiceId: null,
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ internal class SpConsentLibImpl(
spClient.onConsentReady(spConsents)
(spClient as? UnitySpClient)?.onConsentReady(spConsentString)
executor.executeOnSingleThread {
clientEventManager.checkStatus()
clientEventManager.checkIfAllCampaignsWereProcessed()
}
}
}
@@ -147,7 +147,7 @@ internal class SpConsentLibImpl(
},
pSuccess = {
val list = it.toCampaignModelList(logger = pLogger)
clientEventManager.setCampaignNumber(list.size)
clientEventManager.setCampaignsToProcess(list.size)
if (list.isEmpty()) {
consentManager.sendStoredConsentToClient()
return@getMessages
@@ -351,7 +351,7 @@ internal class SpConsentLibImpl(
useGroupPmIfAvailable: Boolean
) {
checkMainThread("loadPrivacyManager")
clientEventManager.executingLoadPM()
clientEventManager.setCampaignsToProcess(1)

val gdprGroupPmId = campaignManager.getGroupId(campaignType)

@@ -392,7 +392,6 @@ internal class SpConsentLibImpl(
url = url,
campaignType = campaignType,
pmId = it.messageId,
singleShot = true,
consent = JSONObject(storedConsent)
)
}
@@ -619,7 +618,6 @@ internal class SpConsentLibImpl(
url = url,
campaignType = actionImpl.campaignType,
pmId = actionImpl.privacyManagerId,
singleShot = true,
consent = JSONObject(dataStorage.gdprConsentStatus!!)
)
}
@@ -646,7 +644,6 @@ internal class SpConsentLibImpl(
url = url,
campaignType = actionImpl.campaignType,
pmId = actionImpl.privacyManagerId,
singleShot = false,
consent = JSONObject(dataStorage.ccpaConsentStatus!!)
)
}
@@ -679,7 +676,6 @@ internal class SpConsentLibImpl(
url = url,
campaignType = action.campaignType,
pmId = action.privacyManagerId,
singleShot = true,
consent = JSONObject(dataStorage.gdprConsentStatus!!)
)
}
@@ -706,7 +702,6 @@ internal class SpConsentLibImpl(
url = url,
campaignType = action.campaignType,
pmId = action.privacyManagerId,
singleShot = true,
consent = JSONObject(dataStorage.ccpaConsentStatus!!)
)
}
Original file line number Diff line number Diff line change
@@ -9,14 +9,11 @@ import com.sourcepoint.cmplibrary.model.exposed.* // ktlint-disable
import com.sourcepoint.cmplibrary.util.check

internal interface ClientEventManager {

fun setCampaignNumber(campNum: Int)
fun executingLoadPM()
fun storedConsent()
fun setCampaignsToProcess(numberOfCampaigns: Int)
fun registerConsentResponse()
fun setAction(action: ConsentActionImpl)
fun setAction(action: NativeMessageActionType)
fun checkStatus()

fun checkIfAllCampaignsWereProcessed()
companion object
}

@@ -34,42 +31,35 @@ private class ClientEventManagerImpl(
val consentManagerUtils: ConsentManagerUtils,
) : ClientEventManager {

private var cNumber: Int = Int.MAX_VALUE
private var storedConsent: Int = 0

override fun setCampaignNumber(campNum: Int) {
cNumber = campNum
storedConsent = 0
}
private var campaignsToProcess: Int = Int.MAX_VALUE
private var isFirstLayerMessage = true

override fun executingLoadPM() {
cNumber = 1
storedConsent = 0
override fun setCampaignsToProcess(numberOfCampaigns: Int) {
campaignsToProcess = numberOfCampaigns
}

override fun setAction(action: ConsentActionImpl) {
executor.executeOnSingleThread {
when (action.actionType) {
ActionType.ACCEPT_ALL,
ActionType.REJECT_ALL,
ActionType.SAVE_AND_EXIT -> {
}
ActionType.SHOW_OPTIONS -> {
}
ActionType.UNKNOWN -> {
isFirstLayerMessage = false
}
ActionType.CUSTOM,
ActionType.MSG_CANCEL,
ActionType.PM_DISMISS -> {
if (!action.requestFromPm || action.singleShotPM) {
if (cNumber > 0) cNumber--
if (isFirstLayerMessage) {
campaignsToProcess--
}
isFirstLayerMessage = true
}
ActionType.GET_MSG_ERROR, ActionType.GET_MSG_NOT_CALLED -> {
cNumber = 0
campaignsToProcess = 0
}
else -> {
// do nothing
}
}
checkStatus()
checkIfAllCampaignsWereProcessed()
}
}

@@ -83,20 +73,19 @@ private class ClientEventManagerImpl(
NativeMessageActionType.UNKNOWN -> {
}
NativeMessageActionType.MSG_CANCEL -> {
if (cNumber > 0) cNumber--
if (campaignsToProcess > 0) campaignsToProcess--
}
NativeMessageActionType.GET_MSG_ERROR, NativeMessageActionType.GET_MSG_NOT_CALLED -> {
cNumber = 0
campaignsToProcess = 0
}
}
checkStatus()
checkIfAllCampaignsWereProcessed()
}
}

override fun checkStatus() {
if (cNumber == storedConsent) {
cNumber = Int.MAX_VALUE
storedConsent = 0
override fun checkIfAllCampaignsWereProcessed() {
if (campaignsToProcess <= 0) {
campaignsToProcess = Int.MAX_VALUE

val spConsent: SPConsents? = getSPConsents().getOrNull()
val spConsentString = spConsent
@@ -116,8 +105,8 @@ private class ClientEventManagerImpl(
}
}

override fun storedConsent() {
storedConsent++
override fun registerConsentResponse() {
campaignsToProcess--
}

private fun getSPConsents() = check<SPConsents> {
Original file line number Diff line number Diff line change
@@ -111,7 +111,7 @@ private class ConsentManagerImpl(
service.sendConsent(actionImpl, env, sPConsentsSuccess, actionImpl.privacyManagerId)
.executeOnLeft { sPConsentsError?.invoke(it) }
.executeOnRight {
clientEventManager.storedConsent()
clientEventManager.registerConsentResponse()
}
}
}
Original file line number Diff line number Diff line change
@@ -104,7 +104,6 @@ internal class ConsentWebView(
url: HttpUrl,
campaignType: CampaignType,
pmId: String?,
singleShot: Boolean,
consent: JSONObject
): Either<Boolean> = check {
if (!connectionManager.isConnected) throw NoInternetConnectionException(description = "No internet connection")
@@ -127,7 +126,6 @@ internal class ConsentWebView(
"""
javascript: window.spLegislation = '${campaignType.name}';
window.localPmId ='$pmId';
window.isSingleShot = $singleShot;
$jsReceiver;
window.postMessage($obj, "*");
""".trimIndent()
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ internal interface IConsentWebView {
url: HttpUrl,
campaignType: CampaignType,
pmId: String?,
singleShot: Boolean,
consent: JSONObject
): Either<Boolean>
fun loadConsentUI(campaignModel: CampaignModel, url: HttpUrl, campaignType: CampaignType): Either<Boolean>
Original file line number Diff line number Diff line change
@@ -32,7 +32,6 @@ internal fun String.toConsentAction(): ConsentActionImpl {
val actionType = (map["actionType"] as? Int)?.let { ActionType.values().find { v -> v.code == it } }
val choiceId = (map["choiceId"] as? String)
val legislation = map.getFieldValue<String>("legislation") ?: "CCPA"
val singleShot = map.getFieldValue<Boolean>("singleShot") ?: false
val privacyManagerId = (map["pmId"] as? String) ?: (map["localPmId"] as? String)
val pmTab = (map["pmTab"] as? String)
val requestFromPm = map.getFieldValue<Boolean>("requestFromPm") ?: false
@@ -57,7 +56,6 @@ internal fun String.toConsentAction(): ConsentActionImpl {
campaignType = CampaignType.valueOf(legislation),
customActionId = customActionId,
thisContent = map.toJSONObj(),
singleShotPM = singleShot
)
}

Original file line number Diff line number Diff line change
@@ -32,7 +32,6 @@ internal data class ConsentActionImpl(
override val requestFromPm: Boolean,
override val saveAndExitVariables: JSONObject = JSONObject(),
override val consentLanguage: String? = MessageLanguage.ENGLISH.value,
val singleShotPM: Boolean = false,
val saveAndExitVariablesOptimized: JsonObject = JsonObject(mapOf()),
val pmTab: String? = null,
val thisContent: JSONObject = JSONObject()
Original file line number Diff line number Diff line change
@@ -22,9 +22,7 @@ data class ConsentActionImplOptimized(
@SerialName("pmTab") val pmTab: String? = null,
@SerialName("requestFromPm") override val requestFromPm: Boolean,
@SerialName("saveAndExitVariables") val saveAndExitVariablesOptimized: JsonObject = JsonObject(mapOf()),
@SerialName("singleShot") val singleShot: Boolean?,
@SerialName("pubData") override val pubData2: JsonObject = JsonObject(mapOf()),
@SerialName("singleShotPM") val singleShotPM: Boolean = false,
@SerialName("privacyManagerId") override val privacyManagerId: String? = null,
) : ConsentAction {
override val pubData: JSONObject
Original file line number Diff line number Diff line change
@@ -19,13 +19,10 @@ class ClientEventManagerTest {

@MockK
private lateinit var consentManagerUtils: ConsentManagerUtils

@MockK
private lateinit var logger: Logger

@MockK
private lateinit var spClient: SpClient

private lateinit var clientEventManager: ClientEventManager

@Before
@@ -38,118 +35,116 @@ class ClientEventManagerTest {
spClient = spClient,
executor = MockExecutorManager()
)
}

@Test
fun `GIVEN 2 successfully sendConsent (GDPR, CCPA) calls, TRIGGER 1 onSpFinish`() {

every { consentManagerUtils.gdprConsentOptimized }.returns(Either.Right(GDPRConsentInternal()))
every { consentManagerUtils.ccpaConsentOptimized }.returns(Either.Right(CCPAConsentInternal()))
}

@Test
fun `GIVEN 2 successfully sendConsent (GDPR, CCPA) calls, TRIGGER 1 onSpFinish`() {
clientEventManager.run {
setCampaignNumber(2) // 2 campaigns GDPR and CCPA
setCampaignsToProcess(2) // 2 campaigns GDPR and CCPA
setAction(ConsentActionImpl(actionType = ACCEPT_ALL, requestFromPm = false, campaignType = CampaignType.GDPR)) // accept the GDPR
setAction(ConsentActionImpl(actionType = ACCEPT_ALL, requestFromPm = false, campaignType = CampaignType.CCPA)) // accept the CCPA
storedConsent() // first consent saved
storedConsent() // second consent saved
checkStatus() // check the status
registerConsentResponse() // first consent saved
registerConsentResponse() // second consent saved
checkIfAllCampaignsWereProcessed() // check the status
}

verify(exactly = 1) { spClient.onSpFinished(any()) }
}

@Test
fun `GIVEN 1 successfully sendConsent call and 1 dismiss action, TRIGGER 1 onSpFinish`() {

every { consentManagerUtils.gdprConsentOptimized }.returns(Either.Right(GDPRConsentInternal()))
every { consentManagerUtils.ccpaConsentOptimized }.returns(Either.Right(CCPAConsentInternal()))

clientEventManager.run {
setCampaignNumber(2) // 2 campaigns GDPR and CCPA
setCampaignsToProcess(2) // 2 campaigns GDPR and CCPA
setAction(ConsentActionImpl(actionType = MSG_CANCEL, requestFromPm = false, campaignType = CampaignType.GDPR)) // accept the GDPR
setAction(ConsentActionImpl(actionType = ACCEPT_ALL, requestFromPm = false, campaignType = CampaignType.CCPA)) // accept the CCPA
storedConsent() // first consent saved
checkStatus() // check the status
registerConsentResponse() // first consent saved
checkIfAllCampaignsWereProcessed() // check the status
}

verify(exactly = 1) { spClient.onSpFinished(any()) }
}

@Test
fun `GIVEN 2 dismiss action2, TRIGGER 1 onSpFinish`() {
fun `GIVEN 1 campaign to process WHEN in the 2nd layer message AND user cancels the PM, TRIGGER 0 onSPFinished`() {
clientEventManager.run {
setCampaignsToProcess(1)
setAction(ConsentActionImpl(actionType = SHOW_OPTIONS, requestFromPm = false, campaignType = CampaignType.GDPR)) // accept the GDPR
setAction(ConsentActionImpl(actionType = PM_DISMISS, requestFromPm = false, campaignType = CampaignType.GDPR)) // accept the GDPR
checkIfAllCampaignsWereProcessed() // check the status
}

every { consentManagerUtils.gdprConsentOptimized }.returns(Either.Right(GDPRConsentInternal()))
every { consentManagerUtils.ccpaConsentOptimized }.returns(Either.Right(CCPAConsentInternal()))
verify(exactly = 0) { spClient.onSpFinished(any()) }
}

@Test
fun `GIVEN 1 campaign to process WHEN in the 1st layer message AND user cancels the PM, TRIGGER 1 onSPFinished`() {
clientEventManager.run {
setCampaignsToProcess(1)
setAction(ConsentActionImpl(actionType = PM_DISMISS, requestFromPm = false, campaignType = CampaignType.GDPR)) // accept the GDPR
checkIfAllCampaignsWereProcessed() // check the status
}

verify(exactly = 1) { spClient.onSpFinished(any()) }
}

@Test
fun `GIVEN 2 dismiss action2, TRIGGER 1 onSpFinish`() {
clientEventManager.run {
setCampaignNumber(2) // 2 campaigns GDPR and CCPA
setCampaignsToProcess(2) // 2 campaigns GDPR and CCPA
setAction(ConsentActionImpl(actionType = MSG_CANCEL, requestFromPm = false, campaignType = CampaignType.GDPR)) // accept the GDPR
setAction(ConsentActionImpl(actionType = PM_DISMISS, requestFromPm = false, campaignType = CampaignType.CCPA)) // accept the CCPA
checkStatus() // check the status
checkIfAllCampaignsWereProcessed() // check the status
}

verify(exactly = 1) { spClient.onSpFinished(any()) }
}

@Test
fun `GIVEN PM flow TRIGGER 1 onSpFinish`() {

every { consentManagerUtils.gdprConsentOptimized }.returns(Either.Right(GDPRConsentInternal()))
every { consentManagerUtils.ccpaConsentOptimized }.returns(Either.Right(CCPAConsentInternal()))

clientEventManager.run {
setCampaignNumber(2) // 2 campaigns GDPR and CCPA
setCampaignsToProcess(2) // 2 campaigns GDPR and CCPA
setAction(ConsentActionImpl(actionType = SHOW_OPTIONS, requestFromPm = false, campaignType = CampaignType.GDPR)) // accept the GDPR
setAction(ConsentActionImpl(actionType = PM_DISMISS, requestFromPm = true, campaignType = CampaignType.GDPR)) // accept the GDPR
setAction(ConsentActionImpl(actionType = MSG_CANCEL, requestFromPm = false, campaignType = CampaignType.CCPA)) // accept the CCPA
setAction(ConsentActionImpl(actionType = ACCEPT_ALL, requestFromPm = false, campaignType = CampaignType.CCPA)) // accept the CCPA
storedConsent()
checkStatus() // check the status
registerConsentResponse()
checkIfAllCampaignsWereProcessed() // check the status
}

verify(exactly = 1) { spClient.onSpFinished(any()) }
}

@Test
fun `GIVEN 0 campaigns TRIGGER 1 onSpFinish`() {

every { consentManagerUtils.gdprConsentOptimized }.returns(Either.Right(GDPRConsentInternal()))
every { consentManagerUtils.ccpaConsentOptimized }.returns(Either.Right(CCPAConsentInternal()))

clientEventManager.run {
setCampaignNumber(0) // 0 campaigns GDPR and CCPA
checkStatus() // check the status
setCampaignsToProcess(0) // 0 campaigns GDPR and CCPA
checkIfAllCampaignsWereProcessed() // check the status
}

verify(exactly = 1) { spClient.onSpFinished(any()) }
}

@Test
fun `GIVEN 1 campaigns and 1 ACCEPT_ALL TRIGGER 1 onSpFinish`() {

every { consentManagerUtils.gdprConsentOptimized }.returns(Either.Right(GDPRConsentInternal()))
every { consentManagerUtils.ccpaConsentOptimized }.returns(Either.Right(CCPAConsentInternal()))

clientEventManager.run {
setCampaignNumber(1) // 1 campaigns GDPR and CCPA
setCampaignsToProcess(1) // 1 campaigns GDPR and CCPA
setAction(ConsentActionImpl(actionType = ACCEPT_ALL, requestFromPm = false, campaignType = CampaignType.CCPA)) // accept the CCPA
storedConsent()
checkStatus() // check the status
registerConsentResponse()
checkIfAllCampaignsWereProcessed() // check the status
}

verify(exactly = 1) { spClient.onSpFinished(any()) }
}

@Test
fun `GIVEN 1 campaigns and 1 MSG_CANCEL TRIGGER 1 onSpFinish`() {

every { consentManagerUtils.gdprConsentOptimized }.returns(Either.Right(GDPRConsentInternal()))
every { consentManagerUtils.ccpaConsentOptimized }.returns(Either.Right(CCPAConsentInternal()))

clientEventManager.run {
setCampaignNumber(1) // 1 campaigns GDPR and CCPA
setCampaignsToProcess(1) // 1 campaigns GDPR and CCPA
setAction(ConsentActionImpl(actionType = MSG_CANCEL, requestFromPm = false, campaignType = CampaignType.CCPA)) // accept the CCPA
checkStatus() // check the status
checkIfAllCampaignsWereProcessed() // check the status
}

verify(exactly = 1) { spClient.onSpFinished(any()) }