From 3d3aaf21245dbca8445ef60f15131d02c9e08ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= Date: Mon, 29 Jul 2024 18:47:39 +0200 Subject: [PATCH] DIA-4323 add programatic rejectAll function (#828) * add rejectAll to SpConsentLib * add prog rejectAll Gdpr button to sample app * add ui test for rejectAll function * Update README.md * Update README.md --- README.md | 10 +++++++- .../sourcepoint/cmplibrary/SpConsentLib.kt | 2 ++ .../cmplibrary/SpConsentLibImpl.kt | 4 +++ .../app/v6/MainActivityKotlinTest.kt | 25 +++++++++++++++++++ .../com/sourcepoint/app/v6/TestUseCase.kt | 3 +++ .../sourcepoint/app/v6/MainActivityKotlin.kt | 2 ++ .../src/main/res/layout/activity_main_v7.xml | 10 ++++++-- samples/app/src/main/res/values/strings.xml | 1 + 8 files changed, 54 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9fe8b182a..609578a0f 100644 --- a/README.md +++ b/README.md @@ -858,6 +858,14 @@ Regarding `handleOnBackPress` from `spConsentLib`, there are 2 parameters: - isMessageDismissible - flag that can customize the behaviour, when the user clicks back button on "Home" page of the message (if true - message is dismissible, if false - when the user is on "Home" page and clicks back, then the back event will be dispatched to the activity delegating navigation to the app) - onHomePage - lambda, code in which should be invoked when the user clicks back on "Home" page of the message (in other words, the initial navigation position in message) +## Programmatically rejecting all for a user + +It’s possible to programmatically issue a “reject all” action on behalf of the current end-user by calling the rejectAll(campaignType) function. The rejectAll function behaves in the exact same manner as if an end-user pressed the “reject all” button on the 1st layer message or privacy manager. Upon completion, the SDK will call either onConsentReady in case of success or onError in case of failure. + +```kotlin + spConsentLib.rejectAll(CampaignType.GDPR) +``` + ## Adding or Removing custom consents It's possible to programmatically consent the current user to a list of vendors, categories and legitimate interest categories by using the following method from the consent lib: @@ -1160,7 +1168,7 @@ public class MainActivityJava extends AppCompatActivity { When migrating a property from the U.S. Privacy (Legacy) campaign to U.S. Multi-State Privacy campaign, the SDK will automatically detect previously set end-user opt-in/opt-out preferences for U.S. Privacy (Legacy) and have that transferred over to U.S. Multi-State Privacy. -> If an end-user rejected a vendor or category for U.S. Privacy, Sourcepoint will set the _Sharing of Personal Information Targeted Advertisting_ and _Sale of Personal Information_ privacy choices or the _Sale or Share of Personal Information/Targeted Advertising_ privacy choice (depending on your configuration) to **opted-out** when the preferences are transferred. +> If an end-user rejected a vendor or category for U.S. Privacy, Sourcepoint will set the _Sharing of Personal Information Targeted Advertising_ and _Sale of Personal Information_ privacy choices or the _Sale or Share of Personal Information/Targeted Advertising_ privacy choice (depending on your configuration) to **opted-out** when the preferences are transferred. If you ever used authenticated consent for CCPA, you'll have to specify the `ConfigOption.TRANSITION_CCPA_AUTH` option in your configuration to transfer an end-user's opt-in/opt-out preferences. The `ConfigOption.TRANSITION_CCPA_AUTH` option is crucial if you are using AuthId. This way, the SDK will look for authenticated consent within CCPA profiles and carry that over to USNat, even if the user current doesn't have CCPA local data (on a fresh install, for example). diff --git a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLib.kt b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLib.kt index 6710995a0..c87f2434f 100644 --- a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLib.kt +++ b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLib.kt @@ -68,6 +68,8 @@ interface SpConsentLib { successCallback: CustomConsentClient ) + fun rejectAll(campaignType: CampaignType) + fun loadPrivacyManager(pmId: String, campaignType: CampaignType) fun loadPrivacyManager(pmId: String, pmTab: PMTab, campaignType: CampaignType) fun loadPrivacyManager(pmId: String, pmTab: PMTab, campaignType: CampaignType, useGroupPmIfAvailable: Boolean) diff --git a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibImpl.kt b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibImpl.kt index 44ed80ef7..baca0dc01 100644 --- a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibImpl.kt +++ b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibImpl.kt @@ -493,6 +493,10 @@ internal class SpConsentLibImpl( .executeOnLeft { pLogger.d(this::class.java.simpleName, "PmUrlConfig is null") } } + override fun rejectAll(campaignType: CampaignType) { + sendConsent(NativeMessageActionType.REJECT_ALL, campaignType) + } + override fun showView(view: View) { checkMainThread("showView") viewManager.showView(view) diff --git a/samples/app/src/androidTest/java/com/sourcepoint/app/v6/MainActivityKotlinTest.kt b/samples/app/src/androidTest/java/com/sourcepoint/app/v6/MainActivityKotlinTest.kt index 5cf1bf975..1c49344af 100644 --- a/samples/app/src/androidTest/java/com/sourcepoint/app/v6/MainActivityKotlinTest.kt +++ b/samples/app/src/androidTest/java/com/sourcepoint/app/v6/MainActivityKotlinTest.kt @@ -26,6 +26,7 @@ import com.sourcepoint.app.v6.TestUseCase.Companion.clickOnDeleteCustomConsent import com.sourcepoint.app.v6.TestUseCase.Companion.clickOnGdprReviewConsent import com.sourcepoint.app.v6.TestUseCase.Companion.clickOnRefreshBtnActivity import com.sourcepoint.app.v6.TestUseCase.Companion.mockModule +import com.sourcepoint.app.v6.TestUseCase.Companion.progRejectAll import com.sourcepoint.app.v6.TestUseCase.Companion.tapAcceptAllOnWebView import com.sourcepoint.app.v6.TestUseCase.Companion.tapAcceptCcpaOnWebView import com.sourcepoint.app.v6.TestUseCase.Companion.tapAcceptOnWebView @@ -135,6 +136,30 @@ class MainActivityKotlinTest { private fun getSharedPrefs(activity: Activity) = PreferenceManager.getDefaultSharedPreferences(activity) + @Test + fun programatically_reject_all_calls_callbacks_and_rejects_all() = runBlocking { + val spClient = mockk(relaxed = true) + loadKoinModules( + mockModule( + spConfig = spConfGdpr, + gdprPmId = "488393", + spClientObserver = listOf(spClient) + ) + ) + + scenario = launchActivity() + + wr { tapAcceptOnWebView() } + wr { progRejectAll() } + wr { + verify(exactly = 2) { + spClient.onConsentReady(any()) + } + } + wr { clickOnGdprReviewConsent() } + wr { checkAllTogglesOFF() } + } + @Test fun given_a_USNAT_campaign_SHOW_message_and_ACCEPT_ALL() = runBlocking { val spClient = mockk(relaxed = true) diff --git a/samples/app/src/androidTest/java/com/sourcepoint/app/v6/TestUseCase.kt b/samples/app/src/androidTest/java/com/sourcepoint/app/v6/TestUseCase.kt index ed88e684f..f70745ee3 100644 --- a/samples/app/src/androidTest/java/com/sourcepoint/app/v6/TestUseCase.kt +++ b/samples/app/src/androidTest/java/com/sourcepoint/app/v6/TestUseCase.kt @@ -40,6 +40,9 @@ import org.koin.dsl.module class TestUseCase { companion object { + fun progRejectAll() { + performClickById(R.id.reject_all_gdpr_button) + } fun checkConsentIsNotSelected() { CONSENT_LIST.forEach { consent -> diff --git a/samples/app/src/main/java/com/sourcepoint/app/v6/MainActivityKotlin.kt b/samples/app/src/main/java/com/sourcepoint/app/v6/MainActivityKotlin.kt index cb5fcb7a2..af9b8f136 100644 --- a/samples/app/src/main/java/com/sourcepoint/app/v6/MainActivityKotlin.kt +++ b/samples/app/src/main/java/com/sourcepoint/app/v6/MainActivityKotlin.kt @@ -83,6 +83,8 @@ class MainActivityKotlin : AppCompatActivity() { preferences.edit().putString(CLIENT_PREF_KEY, CLIENT_PREF_VAL).apply() setContentView(R.layout.activity_main_v7) + + reject_all_gdpr_button.setOnClickListener { spConsentLib.rejectAll(CampaignType.GDPR) } review_consents_gdpr.setOnClickListener { selectGDPRPM(dataProvider) } review_consents_ccpa.setOnClickListener { selectCCPAPM(dataProvider) } clear_all.setOnClickListener { diff --git a/samples/app/src/main/res/layout/activity_main_v7.xml b/samples/app/src/main/res/layout/activity_main_v7.xml index 96bdc62fd..fdda40efa 100644 --- a/samples/app/src/main/res/layout/activity_main_v7.xml +++ b/samples/app/src/main/res/layout/activity_main_v7.xml @@ -17,10 +17,16 @@ android:padding="16dp">