Skip to content

Commit

Permalink
DIA-4323 add programatic rejectAll function (#828)
Browse files Browse the repository at this point in the history
* add rejectAll to SpConsentLib

* add prog rejectAll Gdpr button to sample app

* add ui test for rejectAll function

* Update README.md

* Update README.md
  • Loading branch information
andresilveirah authored Jul 29, 2024
1 parent bc7351c commit 3d3aaf2
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 3 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<SpClient>(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<SpClient>(relaxed = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions samples/app/src/main/res/layout/activity_main_v7.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
android:padding="16dp">

<Button
android:id="@+id/review_consents_gdpr"
android:id="@+id/reject_all_gdpr_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/review_consents"/>
android:text="@string/reject_all_gdpr_button_label"/>

<Button
android:id="@+id/review_consents_gdpr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/review_consents" />

<Button
android:id="@+id/review_consents_ccpa"
Expand Down
1 change: 1 addition & 0 deletions samples/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<resources>
<string name="app_name">SourcePoint</string>
<string name="reject_all_gdpr_button_label">Reject All GDPR</string>
<string name="review_consents">Review Consents GDPR</string>
<string name="source_point_logo">LOGO</string>
<string name="authid_activity">AuthId activity</string>
Expand Down

0 comments on commit 3d3aaf2

Please sign in to comment.