From b7d0eec628021436e35ba652cb84f4b2f8008ab8 Mon Sep 17 00:00:00 2001 From: Lucano Vera Date: Tue, 19 Nov 2024 11:10:18 -0300 Subject: [PATCH 1/4] LA-141 Apply privacy policy override even when locale doesn't match --- .../__tests__/lib/i18n/i18n-utils.test.ts | 33 ++++++++++++++++--- clients/fides-js/src/lib/i18n/i18n-utils.ts | 9 ++++- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/clients/fides-js/__tests__/lib/i18n/i18n-utils.test.ts b/clients/fides-js/__tests__/lib/i18n/i18n-utils.test.ts index 5792d545e7..58c3305e1d 100644 --- a/clients/fides-js/__tests__/lib/i18n/i18n-utils.test.ts +++ b/clients/fides-js/__tests__/lib/i18n/i18n-utils.test.ts @@ -319,12 +319,11 @@ describe("i18n-utils", () => { expect(mockI18n.load).toHaveBeenCalledWith("en", mockI18nCatalogLoad[0]); }); - it("sets overrides experience_config translations when no locale match", () => { + it("sets overrides experience_config translations when locale matches", () => { const experienceTranslationOverrides: Partial = { title: "My override title", description: "My override description", - privacy_policy_url: "https://example.com/privacy", override_language: "en", }; loadMessagesFromExperience( @@ -338,8 +337,6 @@ describe("i18n-utils", () => { ...mockI18nCatalogLoad[0], ...{ "exp.description": experienceTranslationOverrides.description, - "exp.privacy_policy_url": - experienceTranslationOverrides.privacy_policy_url, "exp.title": experienceTranslationOverrides.title, }, }); @@ -351,7 +348,6 @@ describe("i18n-utils", () => { { title: "My override title", description: "My override description", - privacy_policy_url: "https://example.com/privacy", override_language: "ja", }; loadMessagesFromExperience( @@ -365,6 +361,33 @@ describe("i18n-utils", () => { expect(mockI18n.load).toHaveBeenCalledWith("es", mockI18nCatalogLoad[1]); }); + it("always override privacy_policy_url, even if locale doesn't match", () => { + const experienceTranslationOverrides: Partial = + { + title: "My override title", + description: "My override description", + privacy_policy_url: "https://example.com/privacy", + override_language: "ja", + }; + loadMessagesFromExperience( + mockI18n, + mockExperience, + experienceTranslationOverrides, + ); + const EXPECTED_NUM_TRANSLATIONS = 2; + expect(mockI18n.load).toHaveBeenCalledTimes(EXPECTED_NUM_TRANSLATIONS); + expect(mockI18n.load).toHaveBeenCalledWith("en", { + ...mockI18nCatalogLoad[0], + "exp.privacy_policy_url": + experienceTranslationOverrides.privacy_policy_url, + }); + expect(mockI18n.load).toHaveBeenCalledWith("es", { + ...mockI18nCatalogLoad[1], + "exp.privacy_policy_url": + experienceTranslationOverrides.privacy_policy_url, + }); + }); + describe("when loading from a tcf_overlay experience", () => { it("reads all messages from gvl translations API response and loads into the i18n catalog", () => { // Mock out a partial response for a tcf_overlay including translations diff --git a/clients/fides-js/src/lib/i18n/i18n-utils.ts b/clients/fides-js/src/lib/i18n/i18n-utils.ts index c70de7d275..04990184de 100644 --- a/clients/fides-js/src/lib/i18n/i18n-utils.ts +++ b/clients/fides-js/src/lib/i18n/i18n-utils.ts @@ -93,7 +93,14 @@ function extractMessagesFromExperienceConfig( const messages: Messages = {}; EXPERIENCE_TRANSLATION_FIELDS.forEach((key) => { let overrideValue: string | null | undefined = null; - if (experienceTranslationOverrides && localeHasOverride) { + + const isPrivacyPolicyUrl = key === "privacy_policy_url"; + // Override value when matching translation override exists for the language. + // Override privacy_policy_url even if override exists, even if the translation doesn't match the language + const shouldOverrideValue = + experienceTranslationOverrides && + (localeHasOverride || isPrivacyPolicyUrl); + if (shouldOverrideValue) { overrideValue = key in experienceTranslationOverrides ? experienceTranslationOverrides[ From 40924f7897c45f7d42c87b9c688a604a9fe6368e Mon Sep 17 00:00:00 2001 From: Lucano Vera Date: Tue, 19 Nov 2024 11:15:30 -0300 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64652fff67..342801f212 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ The types of changes are: ### Changed - Allow hiding systems via a `hidden` parameter and add two flags on the `/system` api endpoint; `show_hidden` and `dnd_relevant`, to display only systems with integrations [#5484](https://github.com/ethyca/fides/pull/5484) +- The CMP override `fides_privacy_policy_url` will now apply even if the `fides_override_language` doesn't match [#5515](https://github.com/ethyca/fides/pull/5515) + ### Developer Experience - Fixing BigQuery integration tests [#5491](https://github.com/ethyca/fides/pull/5491) From d562d0b22a6e8d9c800d0c3898931cfe6b6079d8 Mon Sep 17 00:00:00 2001 From: Lucano Vera Date: Tue, 19 Nov 2024 11:17:23 -0300 Subject: [PATCH 3/4] LA-141 Apply privacy policy override even when locale doesn't match --- clients/fides-js/src/lib/i18n/i18n-utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/fides-js/src/lib/i18n/i18n-utils.ts b/clients/fides-js/src/lib/i18n/i18n-utils.ts index 04990184de..6478b1c768 100644 --- a/clients/fides-js/src/lib/i18n/i18n-utils.ts +++ b/clients/fides-js/src/lib/i18n/i18n-utils.ts @@ -96,7 +96,7 @@ function extractMessagesFromExperienceConfig( const isPrivacyPolicyUrl = key === "privacy_policy_url"; // Override value when matching translation override exists for the language. - // Override privacy_policy_url even if override exists, even if the translation doesn't match the language + // Override privacy_policy_url, even if the translation doesn't match the language const shouldOverrideValue = experienceTranslationOverrides && (localeHasOverride || isPrivacyPolicyUrl); From bf07cce9044ed520a1378c724e20cf85bf034f31 Mon Sep 17 00:00:00 2001 From: Lucano Vera Date: Wed, 20 Nov 2024 10:58:29 -0300 Subject: [PATCH 4/4] LA-141 Update cypress tests --- .../cypress/e2e/consent-i18n.cy.ts | 71 +++++++++++++++---- 1 file changed, 59 insertions(+), 12 deletions(-) diff --git a/clients/privacy-center/cypress/e2e/consent-i18n.cy.ts b/clients/privacy-center/cypress/e2e/consent-i18n.cy.ts index e5c76e7287..1e1beb1308 100644 --- a/clients/privacy-center/cypress/e2e/consent-i18n.cy.ts +++ b/clients/privacy-center/cypress/e2e/consent-i18n.cy.ts @@ -1052,7 +1052,6 @@ describe("Consent i18n", () => { const experienceTranslationOverrides = { fides_title: "My override title", fides_description: "My override description", - fides_privacy_policy_url: "https://example.com/privacy", fides_override_language: "ja", }; cy.fixture("consent/experience_banner_modal.json").then( @@ -1082,11 +1081,6 @@ describe("Consent i18n", () => { cy.get( "div#fides-banner-description.fides-banner-description", ).contains(translation.banner_description as string); - cy.get("#fides-privacy-policy-link a").should( - "have.attr", - "href", - translation.privacy_policy_url as string, - ); }); // Open the modal cy.contains("button", "Manage preferences").click(); @@ -1101,6 +1095,36 @@ describe("Consent i18n", () => { }, ); }); + it("does apply fides_privacy_policy_url override", () => { + const experienceTranslationOverrides = { + fides_privacy_policy_url: "https://example.com/privacy", + fides_override_language: "ja", + }; + cy.fixture("consent/experience_banner_modal.json").then( + (experience) => { + const experienceItem = experience.items[0]; + stubConfig( + { + options: { + customOptionsPath: TEST_OVERRIDE_WINDOW_PATH, + }, + experience: experienceItem, + }, + null, + null, + undefined, + { ...experienceTranslationOverrides }, + ); + cy.get("div#fides-banner").within(() => { + cy.get("#fides-privacy-policy-link a").should( + "have.attr", + "href", + experienceTranslationOverrides.fides_privacy_policy_url as string, + ); + }); + }, + ); + }); }); describe("when fides_override_language is not provided", () => { @@ -1115,7 +1139,6 @@ describe("Consent i18n", () => { const experienceTranslationOverrides = { fides_title: "My override title", fides_description: "My override description", - fides_privacy_policy_url: "https://example.com/privacy", // skips setting fides_override_language }; cy.fixture("consent/experience_banner_modal.json").then( @@ -1144,11 +1167,6 @@ describe("Consent i18n", () => { cy.get( "div#fides-banner-description.fides-banner-description", ).contains(translation.banner_description as string); - cy.get("#fides-privacy-policy-link a").should( - "have.attr", - "href", - translation.privacy_policy_url as string, - ); }); // Open the modal cy.contains("button", "Manage preferences").click(); @@ -1163,6 +1181,35 @@ describe("Consent i18n", () => { }, ); }); + it("does apply fides_privacy_policy_url override", () => { + const experienceTranslationOverrides = { + fides_privacy_policy_url: "https://example.com/privacy", + }; + cy.fixture("consent/experience_banner_modal.json").then( + (experience) => { + const experienceItem = experience.items[0]; + stubConfig( + { + options: { + customOptionsPath: TEST_OVERRIDE_WINDOW_PATH, + }, + experience: experienceItem, + }, + null, + null, + undefined, + { ...experienceTranslationOverrides }, + ); + cy.get("div#fides-banner").within(() => { + cy.get("#fides-privacy-policy-link a").should( + "have.attr", + "href", + experienceTranslationOverrides.fides_privacy_policy_url as string, + ); + }); + }, + ); + }); }); }); });