Skip to content

Add a new method to Fides object for updating user consent#6151

Merged
gilluminate merged 17 commits intomainfrom
gill/LJ-684/janus-add-new-method-to-fides
May 21, 2025
Merged

Add a new method to Fides object for updating user consent#6151
gilluminate merged 17 commits intomainfrom
gill/LJ-684/janus-add-new-method-to-fides

Conversation

@gilluminate
Copy link
Copy Markdown
Contributor

@gilluminate gilluminate commented May 15, 2025

Closes LJ-684

Description Of Changes

Added a new updateConsent method to the Fides interface, allowing developers to programmatically update user consent preferences using either a consent object or fidesString.

Code Changes

  • Added comprehensive tests for the updateConsent function in preferences module
  • Updated Fides interface documentation to include the new updateConsent method
  • Implemented error handling for various edge cases in the consent update process

Steps to Confirm

  1. Add 6Sense vendor in Admin UI
  2. Enable Analytics, Data sales and sharing, and Essential notices
  3. Create a Headless experience and add those 3 notices to it
  4. Add location Utah to the Headless experience
  5. Visit the privacy center demo page for Utah (/fides-js-demo.html?geolocation=us-ut)
  6. Verify updating consent works with a plain consent object by pasting the following in to the browser devtools console. You should see the values updated in the main window, in Fides.consent, and the cookie.
Fides.encodeNoticeConsentString({ data_sales_and_sharing: false, analytics: true })
  1. Delete the cookie and reload the demo (do this between each step below)
  2. Verify updating consent works with a fidesString
Fides.updateConsent({ fidesString: ",,,eyJkYXRhX3NhbGVzX2FuZF9zaGFyaW5nIjpmYWxzZSwiYW5hbHl0aWNzIjp0cnVlfQ==" })
  1. Confirm error handling for invalid inputs works correctly by pasting the following in to the borwser devtools console:
Fides.updateConsent({invalid: true});
  1. Test that fidesString takes priority when both options are provided:
Fides.updateConsent({
  consent: {
    data_sales_and_sharing: false,
    analytics: true,
  },
  fidesString: ",,,eyJkYXRhX3NhbGVzX2FuZF9zaGFyaW5nIjpmYWxzZSwiYW5hbHl0aWNzIjp0cnVlfQ=="
});
  1. Verify consent mechanism types are handled correctly by running:
Fides.updateConsent({ consent: { data_sales_and_sharing: "opt_out", analytics: "opt_in" } });
  1. Verify with mixed value types:
Fides.updateConsent({ consent: { analytics: true, data_sales_and_sharing: "opt_out" } });
  1. Test validation mode behavior:
// Try to use an invalid value with validation='reject'
  Fides.updateConsent({ 
    consent: { essential: true }, // should be "acknowledge" 
    validation: "reject" 
  });

// Try with validation='warn' - should warn but not throw
Fides.updateConsent({ 
  consent: { essential: true }, 
  validation: "warn" 
});
// Check console for warning

// Try with validation='ignore' - should not warn or throw
Fides.updateConsent({ 
  consent: { essential: true }, 
  validation: "ignore" 
});
  1. Test NOTICE_ONLY consent mechanism:
Fides.updateConsent({ consent: { essential: "acknowledge" } });
  1. Test error handling scenarios:
Fides.updateConsent({});
Fides.updateConsent({ fidesString: "invalid-string" });
Fides.updateConsent({ 
  consent: { analytics: true }, 
  validation: "invalid" 
});

Pre-Merge Checklist

  • Issue requirements met
  • All CI pipelines succeeded
  • CHANGELOG.md updated
    • Add a db-migration This indicates that a change includes a database migration label to the entry if your change includes a DB migration
    • Add a high-risk This issue suggests changes that have a high-probability of breaking existing code label to the entry if your change includes a high-risk change (i.e. potential for performance impact or unexpected regression) that should be flagged
    • Updates unreleased work already in Changelog, no new entry necessary
  • Followup issues:
    • Followup issues created
    • No followup issues
  • Database migrations:
    • Ensure that your downrev is up to date with the latest revision on main
    • Ensure that your downgrade() migration is correct and works
      • If a downgrade migration is not possible for this change, please call this out in the PR description!
    • No migrations
  • Documentation:
    • Documentation complete, PR opened in fidesdocs
    • Documentation issue created in fidesdocs
    • If there are any new client scopes created as part of the pull request, remember to update public-facing documentation that references our scope registry
    • No documentation updates required

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fides-privacy-center ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 7:09pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
fides-plus-nightly ⬜️ Ignored (Inspect) Visit Preview May 21, 2025 7:09pm

Copy link
Copy Markdown
Contributor

@eastandwestwind eastandwestwind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple small questions and requests. Looking great otherwise @gilluminate !

Comment thread clients/fides-js/src/lib/preferences.ts Outdated
Comment thread clients/fides-js/src/lib/preferences.ts Outdated
Comment thread clients/fides-js/src/lib/preferences.ts Outdated
Comment thread clients/fides-js/src/lib/preferences.ts Outdated
@gilluminate gilluminate force-pushed the gill/LJ-684/janus-add-new-method-to-fides branch from f75bdb8 to 301467e Compare May 20, 2025 19:50
@gilluminate gilluminate force-pushed the gill/LJ-684/janus-add-new-method-to-fides branch from 301467e to 21a0034 Compare May 20, 2025 22:04
@gilluminate gilluminate force-pushed the gill/LJ-684/janus-add-new-method-to-fides branch from 8e1c419 to c37d921 Compare May 21, 2025 00:07
@gilluminate gilluminate force-pushed the gill/LJ-684/janus-add-new-method-to-fides branch from c37d921 to 248fae4 Compare May 21, 2025 00:29
@gilluminate gilluminate force-pushed the gill/LJ-684/janus-add-new-method-to-fides branch from 248fae4 to 35d3144 Compare May 21, 2025 00:39
* - String values:
* - `"opt_in"` - user has explicitly opted in to this notice
* - `"opt_out"` - user has explicitly opted out of this notice
* - `"acknowledge"` - ONLY valid for notices with "notice_only" consent mechanism
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we also need to update this with "not_applicable" option too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good callout. No, we don't want to support non_applicable but we do want to create an error specifically for that purpose that I forgot to add (see Neville's comment in JIRA https://ethyca.atlassian.net/browse/ENG-439?focusedCommentId=53324)

Copy link
Copy Markdown
Contributor

@eastandwestwind eastandwestwind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! 1 small Q, non-blocking

}

const handleValidationError = (errorMessage: string) => {
if (validation === "throw") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can these be enums?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good suggestion! I'll create a task in Jira for that so we don't hold up the release any longer. :)

@gilluminate gilluminate merged commit 8c41b39 into main May 21, 2025
17 checks passed
@gilluminate gilluminate deleted the gill/LJ-684/janus-add-new-method-to-fides branch May 21, 2025 19:16
@cypress
Copy link
Copy Markdown

cypress Bot commented May 21, 2025

fides    Run #12937

Run Properties:  status check passed Passed #12937  •  git commit 8c41b39bfe: Add a new method to Fides object for updating user consent (#6151)
Project fides
Branch Review main
Run status status check passed Passed #12937
Run duration 00m 51s
Commit git commit 8c41b39bfe: Add a new method to Fides object for updating user consent (#6151)
Committer Jason Gill
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 5
View all changes introduced in this branch ↗︎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants