Skip to content

Commit

Permalink
PROD-1403: Omit specific fields from system payload if empty (#4525)
Browse files Browse the repository at this point in the history
Co-authored-by: Allison King <[email protected]>
  • Loading branch information
TheAndrewJackson and allisonking authored Dec 19, 2023
1 parent 1f62e7c commit 7e2b55e
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The types of changes are:

### Fixed
- Fixed incorrect Compass button behavior in system form [#4508](https://github.com/ethyca/fides/pull/4508)
- Omit certain fields from system payload when empty [#4508](https://github.com/ethyca/fides/pull/4525)

### Changed
- Upgrade to use Fideslang `3.0.0` and remove associated concepts [#4502](https://github.com/ethyca/fides/pull/4502)
Expand Down
75 changes: 75 additions & 0 deletions clients/admin-ui/src/features/system/form.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { describe, expect, it } from "@jest/globals";

import { transformFormValuesToSystem } from "~/features/system/form";

describe("transformFormValuesToSystem", () => {
it("should omit joint controller into and administrating department if empty", () => {
const formValues = {
system_type: "",
fides_key: "",
tags: [],
name: "new system",
description: "",
dataset_references: [],
processes_personal_data: true,
exempt_from_privacy_regulations: false,
reason_for_exemption: "",
uses_profiling: false,
does_international_transfers: false,
requires_data_protection_assessments: false,
privacy_policy: "",
legal_name: "",
legal_address: "",
administrating_department: "",
responsibility: [],
joint_controller_info: "",
data_security_practices: "",
privacy_declarations: [],
data_stewards: "",
dpo: "",
uses_cookies: false,
cookie_refresh: false,
uses_non_cookie_access: false,
legitimate_interest_disclosure_url: "",
};

const payload = transformFormValuesToSystem(formValues);
expect(payload).not.toHaveProperty("administrating_department");
expect(payload).not.toHaveProperty("joint_controller_info");
});

it("should keep joint controller into and administrating department if not empty", () => {
const formValues = {
system_type: "",
fides_key: "",
tags: [],
name: "new system",
description: "",
dataset_references: [],
processes_personal_data: true,
exempt_from_privacy_regulations: false,
reason_for_exemption: "",
uses_profiling: false,
does_international_transfers: false,
requires_data_protection_assessments: false,
privacy_policy: "",
legal_name: "",
legal_address: "",
administrating_department: "not empty",
responsibility: [],
joint_controller_info: "not empty",
data_security_practices: "",
privacy_declarations: [],
data_stewards: "",
dpo: "",
uses_cookies: false,
cookie_refresh: false,
uses_non_cookie_access: false,
legitimate_interest_disclosure_url: "",
};

const payload = transformFormValuesToSystem(formValues);
expect(payload).toHaveProperty("administrating_department");
expect(payload).toHaveProperty("joint_controller_info");
});
});
16 changes: 12 additions & 4 deletions clients/admin-ui/src/features/system/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const transformFormValuesToSystem = (formValues: FormValues): System => {
const privacyPolicy =
formValues.privacy_policy === "" ? undefined : formValues.privacy_policy;

const payload: System = {
let payload: System = {
system_type: formValues.system_type,
fides_key: key,
name: formValues.name,
Expand Down Expand Up @@ -132,7 +132,7 @@ export const transformFormValuesToSystem = (formValues: FormValues): System => {
return payload;
}

return {
payload = {
...payload,
dataset_references: formValues.dataset_references,
uses_profiling: formValues.uses_profiling,
Expand All @@ -151,10 +151,18 @@ export const transformFormValuesToSystem = (formValues: FormValues): System => {
privacy_policy: privacyPolicy,
legal_name: formValues.legal_name,
legal_address: formValues.legal_address,
administrating_department: formValues.administrating_department,
responsibility: formValues.responsibility,
dpo: formValues.dpo,
joint_controller_info: formValues.joint_controller_info,
data_security_practices: formValues.data_security_practices,
};

if (formValues.administrating_department) {
payload.administrating_department = formValues.administrating_department;
}

if (formValues.joint_controller_info) {
payload.joint_controller_info = formValues.joint_controller_info;
}

return payload;
};

0 comments on commit 7e2b55e

Please sign in to comment.