Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding backwards compatibility for name identity #4791

Merged
merged 8 commits into from
Apr 12, 2024

Conversation

galvana
Copy link
Contributor

@galvana galvana commented Apr 12, 2024

Description Of Changes

Part of the work I did when adding custom identities was to demote "name" as an identity since it's not unique enough to uniquely identify a subject. This PR adds support to render the name field (if provided in the Privacy Center's config.json) but ignore it as part of the privacy request payload.

I'm also fixing a test with the demo seed data, I'm including it here to minimize the time spent juggling two separate PRs.

Code Changes

  • Updated PrivacyRequestForm.tsx component
  • Fixed test_seed.py tests

Steps to Confirm

  • Run nox -s dev to start the Fides server
  • Start the Privacy Center cd clients/privacy-center && turbo run dev
  • You should be able to specify name in the identity_inputs of the Privacy Center's config.json and still be able to submit a request

Pre-Merge Checklist

  • All CI Pipelines Succeeded
  • Issue Requirements are Met
  • Update CHANGELOG.md

Copy link

vercel bot commented Apr 12, 2024

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

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
fides-plus-nightly ⬜️ Ignored (Inspect) Visit Preview Apr 12, 2024 9:32pm

@galvana galvana requested a review from NevilleS April 12, 2024 17:16
Comment on lines +69 to +75
.filter(
([key, value]) =>
key === "name" ||
key === "phone" ||
key === "email" ||
(typeof value === "object" && value.label)
)
Copy link
Contributor Author

@galvana galvana Apr 12, 2024

Choose a reason for hiding this comment

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

Only keeping the known identities (name, phone, email) or custom identities with a label, this is to ignore someone just doing

"loyality_id: "required"

it needs to be labeled

"loyalty_id": {"label" "Loyalty ID"}

Copy link
Contributor

Choose a reason for hiding this comment

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

The repeated list of keys here would benefit from some kind of constant declaration like:

const DEFAULT_IDENTITY_INPUTS_MAP = {
  "name": undefined,
  "email": "email",
  "phone": "phone_number",
};

...which could more easily do comparisons like Object.keys(DEFAULT_IDENTITY_INPUTS_MAP).includes("name") etc

Comment on lines +99 to +102
if (key === "phone") {
// eslint-disable-next-line no-param-reassign
key = "phone_number";
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The key is phone in config.json but it needs to be converted to phone_number to be posted

Copy link
Contributor

Choose a reason for hiding this comment

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

Oof. That's messy. The IDENTITY_INPUTS_MAP suggestion I had above was to try to help make this slightly less magical, but it's still a confusing DX

Comment on lines +93 to +95
// we have to support name as an identity_input for legacy purposes
// but we ignore it since it's not unique enough to be treated as an identity
.filter(([key]) => key !== "name")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The name field will appear in the form but be ignored from the privacy request payload

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

OK, this'll work for our purposes. It's pretty confusing behaviour to explain to someone new to the code, but it's also confusing as is, so this is an improvement!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixing seed test

Comment on lines +232 to +238
.filter(
([key, value]) =>
key !== "email" &&
key !== "phone" &&
key !== "name" &&
typeof value !== "string"
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filter out the default identities or identity inputs with just string values (such as "required" or "optional") from the dynamic form validation

Comment on lines +392 to +398
.filter(
([key, item]) =>
key !== "email" &&
key !== "phone" &&
key !== "name" &&
typeof item !== "string"
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same filtering to render the form fields

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: You'll find this kind of rendering logic easier to manage if you pre-filter this above, like

const defaultIdentityInputs = Object.entries(identityInputs).filter(...)
const customIdentityInputs = Object.entries(identityInputs).filter(...)

And then you can use those variables directly with less fuss 😄

Copy link
Contributor

@adamsachs adamsachs left a comment

Choose a reason for hiding this comment

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

code looks enough to my novice eyes, and manual testing with nox -s "fides_env(test)" is looking good!

image

Copy link
Contributor

@NevilleS NevilleS left a comment

Choose a reason for hiding this comment

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

Couple nits but not particularly worth spending energy on here 😄

Comment on lines +69 to +75
.filter(
([key, value]) =>
key === "name" ||
key === "phone" ||
key === "email" ||
(typeof value === "object" && value.label)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

The repeated list of keys here would benefit from some kind of constant declaration like:

const DEFAULT_IDENTITY_INPUTS_MAP = {
  "name": undefined,
  "email": "email",
  "phone": "phone_number",
};

...which could more easily do comparisons like Object.keys(DEFAULT_IDENTITY_INPUTS_MAP).includes("name") etc

Comment on lines +93 to +95
// we have to support name as an identity_input for legacy purposes
// but we ignore it since it's not unique enough to be treated as an identity
.filter(([key]) => key !== "name")
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

OK, this'll work for our purposes. It's pretty confusing behaviour to explain to someone new to the code, but it's also confusing as is, so this is an improvement!

Comment on lines +99 to +102
if (key === "phone") {
// eslint-disable-next-line no-param-reassign
key = "phone_number";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Oof. That's messy. The IDENTITY_INPUTS_MAP suggestion I had above was to try to help make this slightly less magical, but it's still a confusing DX

Comment on lines +392 to +398
.filter(
([key, item]) =>
key !== "email" &&
key !== "phone" &&
key !== "name" &&
typeof item !== "string"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: You'll find this kind of rendering logic easier to manage if you pre-filter this above, like

const defaultIdentityInputs = Object.entries(identityInputs).filter(...)
const customIdentityInputs = Object.entries(identityInputs).filter(...)

And then you can use those variables directly with less fuss 😄

Copy link

cypress bot commented Apr 12, 2024

Passing run #7243 ↗︎

0 4 0 0 Flakiness 0
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

Merge 57409c0 into 9fd78f2...
Project: fides Commit: 2b7fceb8cf ℹ️
Status: Passed Duration: 00:34 💡
Started: Apr 12, 2024 9:46 PM Ended: Apr 12, 2024 9:46 PM

Review all test suite changes for PR #4791 ↗︎

Copy link

codecov bot commented Apr 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.61%. Comparing base (22fa0b9) to head (883e76c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4791      +/-   ##
==========================================
+ Coverage   86.28%   86.61%   +0.32%     
==========================================
  Files         339      339              
  Lines       20090    20090              
  Branches     2586     2586              
==========================================
+ Hits        17334    17400      +66     
+ Misses       2290     2217      -73     
- Partials      466      473       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@galvana galvana merged commit a9d3ea9 into main Apr 12, 2024
46 checks passed
@galvana galvana deleted the PROD-1964-legacy-support-for-name-identity branch April 12, 2024 22:00
galvana added a commit that referenced this pull request Apr 12, 2024
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.

3 participants