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

Add privacy declaration name to datamap response #2831

Merged
merged 9 commits into from
Mar 15, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The types of changes are:
### Changed

* Removed "progressive" navigation that would hide Admin UI tabs until Systems / Connections were configured [#2762](https://github.com/ethyca/fides/pull/2762)
* Added `system.privacy_declaration.name` to datamap response [#2831][https://github.com/ethyca/fides/pull/2831/files]

### Developer Experience

Expand Down
21 changes: 18 additions & 3 deletions src/fides/api/ctl/routes/datamap.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
"system.ingress": "Related Systems which receive data to this System",
"system.egress": "Related Systems which send data to this System",
}

DEPRECATED_COLUMNS = {
"system.privacy_declaration.name": "Privacy Declaration Name",
}

DATAMAP_COLUMNS_API = {**DATAMAP_COLUMNS, **API_EXTRA_COLUMNS}

router = APIRouter(tags=["Datamap"], prefix=f"{API_PREFIX}/datamap")
Expand Down Expand Up @@ -100,6 +105,7 @@
async def export_datamap(
organization_fides_key: str,
response: Response,
include_deprecated_columns: bool = False,
TheAndrewJackson marked this conversation as resolved.
Show resolved Hide resolved
db: AsyncSession = Depends(get_async_db),
) -> List[Dict[str, Any]]:
"""
Expand Down Expand Up @@ -161,20 +167,29 @@ async def export_datamap(
server_resource_dict
)

formatted_datamap = format_datamap_values(joined_system_dataset_df, custom_columns)
formatted_datamap = format_datamap_values(
joined_system_dataset_df, custom_columns, include_deprecated_columns
)
columns = {**DATAMAP_COLUMNS_API, **custom_columns}
if include_deprecated_columns:
columns = {**columns, **DEPRECATED_COLUMNS}

formatted_datamap = [{**DATAMAP_COLUMNS_API, **custom_columns}] + formatted_datamap
formatted_datamap = [columns] + formatted_datamap
return formatted_datamap


def format_datamap_values(
joined_system_dataset_df: DataFrame, custom_columns: Dict[str, str]
joined_system_dataset_df: DataFrame,
custom_columns: Dict[str, str],
include_deprecated_columns: bool = False,
) -> List[Dict[str, str]]:
"""
Formats the joined DataFrame to return the data as records.
"""

columns = {**DATAMAP_COLUMNS_API, **custom_columns}
if include_deprecated_columns:
columns = {**columns, **DEPRECATED_COLUMNS}

limited_columns_df = DataFrame(
joined_system_dataset_df,
Expand Down
1 change: 0 additions & 1 deletion src/fides/core/export_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ def union_data_categories_in_joined_dataframe(joined_df: pd.DataFrame) -> pd.Dat
# isolate the system data categories into a new dataframe and create a common column
joined_df = joined_df.drop(
[
"system.privacy_declaration.name",
TheAndrewJackson marked this conversation as resolved.
Show resolved Hide resolved
"dataset.description",
],
axis=1,
Expand Down
44 changes: 44 additions & 0 deletions tests/ctl/api/test_datamap.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,18 @@
]


PRIVACY_DECLARATION_WITH_NAME_SYSTEM_ROW_RESPONSE_PAYLOAD = [
{
**HEADERS_ROW_RESPONSE_PAYLOAD,
"system.privacy_declaration.name": "Privacy Declaration Name",
},
{
**PRIVACY_DECLARATION_SYSTEM_ROW_RESPONSE_PAYLOAD,
"system.privacy_declaration.name": "declaration-name-2",
},
]


@pytest.fixture
def system_no_privacy_declarations(db):
"""
Expand Down Expand Up @@ -544,6 +556,38 @@ def test_datamap_with_privacy_declaration(
assert response.json() == expected_response_payload


@pytest.mark.integration
@pytest.mark.usefixtures("system_privacy_declarations")
def test_datamap_with_privacy_declaration_with_name(
test_config: FidesConfig,
test_client: TestClient,
) -> None:
response = test_client.get(
test_config.cli.server_url
+ API_PREFIX
+ "/datamap/default_organization?include_deprecated_columns=true",
TheAndrewJackson marked this conversation as resolved.
Show resolved Hide resolved
headers=test_config.user.auth_header,
)
assert response.status_code == 200
assert response.json() == PRIVACY_DECLARATION_WITH_NAME_SYSTEM_ROW_RESPONSE_PAYLOAD


@pytest.mark.integration
@pytest.mark.usefixtures("system_privacy_declarations")
def test_datamap_with_privacy_declaration_without_name(
test_config: FidesConfig,
test_client: TestClient,
) -> None:
response = test_client.get(
test_config.cli.server_url
+ API_PREFIX
+ "/datamap/default_organization?include_deprecated_columns=false",
headers=test_config.user.auth_header,
)
assert response.status_code == 200
assert response.json() == EXPECTED_RESPONSE_NO_CUSTOM_FIELDS_PRIVACY_DECLARATION


@pytest.mark.integration
@pytest.mark.usefixtures(
"system_no_privacy_declarations",
Expand Down