Skip to content

Commit

Permalink
Update fides_disable_save_api option in FidesJS SDK to disable both p…
Browse files Browse the repository at this point in the history
…rivacy-preferences & notice-served APIs (#4860)
  • Loading branch information
NevilleS authored May 3, 2024
1 parent 43b62d4 commit 221cb05
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 92 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The types of changes are:
- Added multiple language translations support for privacy center consent page [#4785](https://github.com/ethyca/fides/pull/4785)
- Added ability to export the contents of datamap report [#1545](https://ethyca.atlassian.net/browse/PROD-1545)
- Added state persistence across sessions to the datamap report table [#4853](https://github.com/ethyca/fides/pull/4853)
- Update fides_disable_save_api option in FidesJS SDK to disable both privacy-preferences & notice-served APIs [#4860](https://github.com/ethyca/fides/pull/4860)

### Fixed
- Remove the extra 'white-space: normal' CSS for FidesJS HTML descriptions [#4850](https://github.com/ethyca/fides/pull/4850)
Expand Down
15 changes: 12 additions & 3 deletions clients/fides-js/src/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,24 @@ export const useConsentServed = ({

const handleUIEvent = useCallback(
async (event: FidesEvent) => {
// The only time a notices served API call isn't triggered is when
// the BANNER is shown or preview mode is enabled. Calls can be triggered for
// TCF_BANNER, TCF_OVERLAY, and OVERLAY
// Disable the notices-served API if the fides_disable_save_api option is set
if (options.fidesDisableSaveApi) {
return;
}

// Disable the notices-served API if the serving component is a regular
// banner (or unknown!). This means we trigger the API for:
// 1) MODAL
// 2) TCF_OVERLAY
// 3) TCF_BANNER
if (
!event.detail.extraDetails ||
event.detail.extraDetails.servingComponent === ServingComponent.BANNER
) {
return;
}

// Construct the notices-served API request and send!
const request: RecordConsentServedRequest = {
browser_identity: event.detail.identity,
privacy_experience_config_history_id:
Expand Down
174 changes: 85 additions & 89 deletions clients/privacy-center/cypress/e2e/consent-banner.cy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {
ComponentType,
CONSENT_COOKIE_NAME,
ComponentType,
ConsentMechanism,
ConsentMethod,
FidesCookie,
FidesInitOptions,
PrivacyNotice,
RecordConsentServedRequest,
UserConsentPreference,
} from "fides-js";

import { RecordConsentServedRequest } from "fides-js/src/lib/consent-types";
import { TEST_OVERRIDE_WINDOW_PATH } from "~/cypress/support/constants";

import {
Expand Down Expand Up @@ -2150,40 +2151,42 @@ describe("Consent overlay", () => {
});
});

describe("consent reporting", () => {
describe("consent reporting APIs (notices-served, privacy-preferences)", () => {
const historyId1 = "pri_mock_history_id_1";
const historyId2 = "pri_mock_history_id_2";
const buildMockNotices = (): PrivacyNotice[] => [
mockPrivacyNotice(
{
title: "Data Sales and Sharing",
id: "pri_notice-data-sales",
notice_key: "data_sales_and_sharing",
},
[
mockPrivacyNoticeTranslation({
title: "Data Sales and Sharing",
privacy_notice_history_id: historyId1,
}),
]
),
mockPrivacyNotice(
{
title: "Essential",
notice_key: "essential",
id: "pri_notice-essential",
},
[
mockPrivacyNoticeTranslation({
title: "Essential",
privacy_notice_history_id: historyId2,
}),
]
),
];

it("can go through consent reporting flow", () => {
stubConfig({
experience: {
privacy_notices: [
mockPrivacyNotice(
{
title: "Data Sales and Sharing",
id: "pri_notice-mock-1",
notice_key: "data_sales_and_sharing",
},
[
mockPrivacyNoticeTranslation({
title: "Data Sales and Sharing",
privacy_notice_history_id: historyId1,
}),
]
),
mockPrivacyNotice(
{
title: "Essential",
id: "pri_notice-mock-2",
notice_key: "essential",
},
[
mockPrivacyNoticeTranslation({
title: "Essential",
privacy_notice_history_id: historyId2,
}),
]
),
],
privacy_notices: buildMockNotices(),
},
});
cy.get("#fides-modal-link").click();
Expand Down Expand Up @@ -2229,38 +2232,13 @@ describe("Consent overlay", () => {
});

it("can set acknowledge mode to true", () => {
const noticeOnlyNotices = buildMockNotices().map((notice) => ({
...notice,
...{ consent_mechanism: ConsentMechanism.NOTICE_ONLY },
}));
stubConfig({
experience: {
privacy_notices: [
mockPrivacyNotice(
{
title: "Data Sales and Sharing",
id: "pri_notice-data-sales",
notice_key: "data_sales_and_sharing",
consent_mechanism: ConsentMechanism.NOTICE_ONLY,
},
[
mockPrivacyNoticeTranslation({
title: "Data Sales and Sharing",
privacy_notice_history_id: historyId1,
}),
]
),
mockPrivacyNotice(
{
title: "Essential",
notice_key: "essential",
id: "pri_notice-essential",
consent_mechanism: ConsentMechanism.NOTICE_ONLY,
},
[
mockPrivacyNoticeTranslation({
title: "Essential",
privacy_notice_history_id: historyId2,
}),
]
),
],
privacy_notices: noticeOnlyNotices,
},
});
cy.get("@FidesUIShown").should("have.been.calledOnce");
Expand All @@ -2269,6 +2247,7 @@ describe("Consent overlay", () => {
expect(interception.request.body.acknowledge_mode).to.eql(true);
});
});

it("can call custom notices served fn instead of Fides API", () => {
/* eslint-disable @typescript-eslint/no-unused-vars */
const apiOptions = {
Expand All @@ -2279,34 +2258,7 @@ describe("Consent overlay", () => {
const spyObject = cy.spy(apiOptions, "patchNoticesServedFn");
stubConfig({
experience: {
privacy_notices: [
mockPrivacyNotice(
{
title: "Data Sales and Sharing",
id: "pri_notice-data-sales",
notice_key: "data_sales_and_sharing",
},
[
mockPrivacyNoticeTranslation({
title: "Data Sales and Sharing",
privacy_notice_history_id: historyId1,
}),
]
),
mockPrivacyNotice(
{
title: "Essential",
id: "pri_notice-essential",
notice_key: "essential",
},
[
mockPrivacyNoticeTranslation({
title: "Essential",
privacy_notice_history_id: historyId2,
}),
]
),
],
privacy_notices: buildMockNotices(),
},
options: {
apiOptions,
Expand Down Expand Up @@ -2338,6 +2290,50 @@ describe("Consent overlay", () => {
});
});
});

it("when fides_disable_save_api option is set, disables notices-served & privacy-preferences APIs", () => {
stubConfig({
experience: {
privacy_notices: buildMockNotices(),
},
options: {
fidesDisableSaveApi: true,
},
});
cy.waitUntilFidesInitialized().then(() => {
cy.get("@FidesUIShown").should("not.have.been.called");
cy.get("#fides-modal-link").click();

// Check that notices-served API is not called when the modal is shown
cy.get("@FidesUIShown").then(() => {
cy.on("fail", (error) => {
if (error.message.indexOf("Timed out retrying") !== 0) {
throw error;
}
});
cy.wait("@patchNoticesServed", {
requestTimeout: 100,
}).then((xhr) => {
assert.isNull(xhr?.response?.body);
});
});

// Also, check that privacy-preferences API is not called after saving
cy.getByTestId("Save-btn").click();
cy.get("@FidesUpdated").then(() => {
cy.on("fail", (error) => {
if (error.message.indexOf("Timed out retrying") !== 0) {
throw error;
}
});
cy.wait("@patchPrivacyPreference", {
requestTimeout: 100,
}).then((xhr) => {
assert.isNull(xhr?.response?.body);
});
});
});
});
});

describe("consent overlay buttons", () => {
Expand Down

0 comments on commit 221cb05

Please sign in to comment.