Skip to content

Commit

Permalink
add fides_reject_all override option
Browse files Browse the repository at this point in the history
  • Loading branch information
gilluminate committed Nov 26, 2024
1 parent ca2be22 commit 3af1ba8
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 20 deletions.
16 changes: 15 additions & 1 deletion clients/fides-js/docs/interfaces/FidesOptions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Interface: FidesOptions

FidesJS supports a variety of custom options to modify it's behavior or
enabled more advanced usage. For example, the `fides_locale` option can be
enable more advanced usage. For example, the `fides_locale` option can be
provided to override the browser locale. See the properties list below for
the supported options and example usage for each.

Expand Down Expand Up @@ -160,3 +160,17 @@ overriden at the page-level as needed. Only applicable to a TCF experience.
For more details, see the [TCF CMP API technical specification](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20CMP%20API%20v2.md#what-does-the-gdprapplies-value-mean) *

Defaults to `true`.

***

### fides\_reject\_all

> **fides\_reject\_all**: `boolean`
When `true`, FidesJS will automatically opt out of all consent and
only show the consent modal upon user request. This is useful for any
scenario where the user has previously provided consent in a different
context (e.g. a native app, another website, etc.) and you want to ensure
that those preferences are respected.

Defaults to `false`.
1 change: 1 addition & 0 deletions clients/fides-js/src/components/Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const Overlay: FunctionComponent<Props> = ({

const showBanner = useMemo(
() =>
!options.fidesRejectAll &&
!options.fidesDisableBanner &&
experience.experience_config?.component !== ComponentType.MODAL &&
shouldResurfaceConsent(experience, cookie, savedConsent),
Expand Down
22 changes: 22 additions & 0 deletions clients/fides-js/src/components/notices/NoticeOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,28 @@ const NoticeOverlay: FunctionComponent<OverlayProps> = ({
],
);

useEffect(() => {
if (
handleUpdatePreferences &&
options.fidesRejectAll &&
experience.privacy_notices
) {
fidesDebugger(
"Consent automatically rejected by fides_reject_all override!",
);
handleUpdatePreferences(
ConsentMethod.REJECT,
experience.privacy_notices
.filter((n) => n.consent_mechanism === ConsentMechanism.NOTICE_ONLY)
.map((n) => n.notice_key),
);
}
}, [
experience.privacy_notices,
handleUpdatePreferences,
options.fidesRejectAll,
]);

const dispatchOpenBannerEvent = useCallback(() => {
dispatchFidesEvent("FidesUIShown", cookie, options.debug, {
servingComponent: ServingComponent.BANNER,
Expand Down
11 changes: 2 additions & 9 deletions clients/fides-js/src/components/tcf/TcfConsentButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PrivacyExperience,
PrivacyExperienceMinimal,
} from "../../lib/consent-types";
import { EMPTY_ENABLED_IDS } from "../../lib/tcf/constants";
import type { EnabledIds, TcfModels } from "../../lib/tcf/types";
import { ConsentButtons } from "../ConsentButtons";

Expand Down Expand Up @@ -87,15 +88,7 @@ export const TcfConsentButtons = ({
onSave(ConsentMethod.ACCEPT, allIds);
};
const handleRejectAll = () => {
const emptyIds: EnabledIds = {
purposesConsent: [],
purposesLegint: [],
specialPurposes: [],
features: [],
specialFeatures: [],
vendorsConsent: [],
vendorsLegint: [],
};
const emptyIds: EnabledIds = EMPTY_ENABLED_IDS;
onSave(ConsentMethod.REJECT, emptyIds);
};

Expand Down
20 changes: 11 additions & 9 deletions clients/fides-js/src/components/tcf/TcfOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from "../../lib/i18n";
import { useI18n } from "../../lib/i18n/i18n-context";
import { updateConsentPreferences } from "../../lib/preferences";
import { EMPTY_ENABLED_IDS } from "../../lib/tcf/constants";
import { useGvl } from "../../lib/tcf/gvl-context";
import type { EnabledIds, TcfSavePreferences } from "../../lib/tcf/types";
import {
Expand Down Expand Up @@ -163,15 +164,7 @@ export const TcfOverlay = ({

useEffect(() => {
if (!experience) {
setDraftIds({
purposesConsent: [],
purposesLegint: [],
specialPurposes: [],
features: [],
specialFeatures: [],
vendorsConsent: [],
vendorsLegint: [],
});
setDraftIds(EMPTY_ENABLED_IDS);
} else {
const {
tcf_purpose_consents: consentPurposes = [],
Expand Down Expand Up @@ -293,6 +286,15 @@ export const TcfOverlay = ({
],
);

useEffect(() => {
if (options.fidesRejectAll) {
fidesDebugger(
"Consent automatically rejected by fides_reject_all override!",
);
handleUpdateAllPreferences(ConsentMethod.REJECT, EMPTY_ENABLED_IDS);
}
}, [handleUpdateAllPreferences, options.fidesRejectAll]);

const [activeTabIndex, setActiveTabIndex] = useState(0);

const dispatchOpenBannerEvent = useCallback(() => {
Expand Down
13 changes: 12 additions & 1 deletion clients/fides-js/src/docs/fides-options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* FidesJS supports a variety of custom options to modify it's behavior or
* enabled more advanced usage. For example, the `fides_locale` option can be
* enable more advanced usage. For example, the `fides_locale` option can be
* provided to override the browser locale. See the properties list below for
* the supported options and example usage for each.
*
Expand Down Expand Up @@ -143,4 +143,15 @@ export interface FidesOptions {
* Defaults to `true`.
*/
fides_tcf_gdpr_applies: boolean;

/**
* When `true`, FidesJS will automatically opt out of all consent and
* only show the consent modal upon user request. This is useful for any
* scenario where the user has previously provided consent in a different
* context (e.g. a native app, another website, etc.) and you want to ensure
* that those preferences are respected.
*
* Defaults to `false`.
*/
fides_reject_all: boolean;
}
5 changes: 5 additions & 0 deletions clients/fides-js/src/fides-tcf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ const _Fides: FidesGlobal = {
fidesPrimaryColor: null,
fidesClearCookie: false,
showFidesBrandLink: false,
fidesRejectAll: false,
},
fides_meta: {},
identity: {},
Expand All @@ -281,6 +282,10 @@ const _Fides: FidesGlobal = {
// Nothing to show if there's no experience
return false;
}
if (this.options.fidesRejectAll) {
// If automatically rejected, we should not show the experience
return false;
}
if (!this.cookie) {
throw new Error("Should have a cookie");
}
Expand Down
5 changes: 5 additions & 0 deletions clients/fides-js/src/fides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ const _Fides: FidesGlobal = {
fidesPrimaryColor: null,
fidesClearCookie: false,
showFidesBrandLink: true,
fidesRejectAll: false,
},
fides_meta: {},
identity: {},
Expand All @@ -223,6 +224,10 @@ const _Fides: FidesGlobal = {
// Nothing to show if there's no experience
return false;
}
if (this.options.fidesRejectAll) {
// If automatically rejected, we should not show the experience
return false;
}
if (!this.cookie) {
throw new Error("Should have a cookie");
}
Expand Down
6 changes: 6 additions & 0 deletions clients/fides-js/src/lib/consent-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ export const FIDES_OVERRIDE_OPTIONS_VALIDATOR_MAP: {
overrideKey: "fides_clear_cookie",
validationRegex: /(.*)/,
},
{
overrideName: "fidesRejectAll",
overrideType: "boolean",
overrideKey: "fides_reject_all",
validationRegex: /^(true|false)$/,
},
];

/**
Expand Down
4 changes: 4 additions & 0 deletions clients/fides-js/src/lib/consent-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ export interface FidesInitOptions {

// Whether to render the brand link in the footer of the modal
showFidesBrandLink: boolean;

// Whether to reject all consent preferences by default
fidesRejectAll: boolean;
}

/**
Expand Down Expand Up @@ -686,6 +689,7 @@ export type FidesInitOptionsOverrides = Pick<
| "fidesLocale"
| "fidesPrimaryColor"
| "fidesClearCookie"
| "fidesRejectAll"
>;

export type FidesExperienceTranslationOverrides = {
Expand Down
10 changes: 10 additions & 0 deletions clients/fides-js/src/lib/tcf/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,13 @@ export const LEGAL_BASIS_OPTIONS = [
value: LegalBasisEnum.LEGITIMATE_INTERESTS.toString(),
},
];

export const EMPTY_ENABLED_IDS: EnabledIds = {
purposesConsent: [],
purposesLegint: [],
specialPurposes: [],
features: [],
specialFeatures: [],
vendorsConsent: [],
vendorsLegint: [],
};
2 changes: 2 additions & 0 deletions clients/privacy-center/app/server-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export type PrivacyCenterClientSettings = Pick<
| "BASE_64_COOKIE"
| "FIDES_PRIMARY_COLOR"
| "FIDES_CLEAR_COOKIE"
| "FIDES_REJECT_ALL"
>;

export type Styles = string;
Expand Down Expand Up @@ -352,6 +353,7 @@ export const loadPrivacyCenterEnvironment = async ({
BASE_64_COOKIE: settings.BASE_64_COOKIE,
FIDES_PRIMARY_COLOR: settings.FIDES_PRIMARY_COLOR,
FIDES_CLEAR_COOKIE: settings.FIDES_CLEAR_COOKIE,
FIDES_REJECT_ALL: settings.FIDES_REJECT_ALL,
};

// For backwards-compatibility, override FIDES_API_URL with the value from the config file if present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ export interface PrivacyCenterSettings {
BASE_64_COOKIE: boolean; // whether or not to encode cookie as base64 on top of the default JSON string
FIDES_PRIMARY_COLOR: string | null; // (optional) sets fides primary color
FIDES_CLEAR_COOKIE: boolean; // (optional) deletes fides_consent cookie on reload
FIDES_REJECT_ALL: boolean; // (optional) rejects all consent preferences on load
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ const loadEnvironmentVariables = () => {
FIDES_CLEAR_COOKIE: process.env.FIDES_PRIVACY_CENTER__FIDES_CLEAR_COOKIE
? process.env.FIDES_PRIVACY_CENTER__FIDES_CLEAR_COOKIE === "true"
: false,
FIDES_REJECT_ALL: process.env.FIDES_PRIVACY_CENTER__FIDES_REJECT_ALL
? process.env.FIDES_PRIVACY_CENTER__FIDES_REJECT_ALL === "true"
: false,
};
return settings;
};
Expand Down
1 change: 1 addition & 0 deletions clients/privacy-center/pages/api/fides-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export default async function handler(
base64Cookie: environment.settings.BASE_64_COOKIE,
fidesPrimaryColor: environment.settings.FIDES_PRIMARY_COLOR,
fidesClearCookie: environment.settings.FIDES_CLEAR_COOKIE,
fidesRejectAll: environment.settings.FIDES_REJECT_ALL,
},
experience: experience || undefined,
geolocation: geolocation || undefined,
Expand Down

0 comments on commit 3af1ba8

Please sign in to comment.