From 61f38a4fb0fb9c6884690d4b4f61b03a6fb37e90 Mon Sep 17 00:00:00 2001 From: kirk Date: Thu, 19 Dec 2024 09:56:48 -0500 Subject: [PATCH] PR feedback and reset system endpoint to exactly what it was before --- ...add_data_uses_column_to_stagedresource.py} | 2 +- src/fides/api/api/v1/endpoints/system.py | 59 ++++++++----------- src/fides/api/models/detection_discovery.py | 2 +- tests/ops/api/v1/endpoints/test_system.py | 4 ++ 4 files changed, 30 insertions(+), 37 deletions(-) rename src/fides/api/alembic/migrations/versions/{d9237a0c0d5a_add_hidden_column_to_stagedresource.py => d9237a0c0d5a_add_data_uses_column_to_stagedresource.py} (92%) diff --git a/src/fides/api/alembic/migrations/versions/d9237a0c0d5a_add_hidden_column_to_stagedresource.py b/src/fides/api/alembic/migrations/versions/d9237a0c0d5a_add_data_uses_column_to_stagedresource.py similarity index 92% rename from src/fides/api/alembic/migrations/versions/d9237a0c0d5a_add_hidden_column_to_stagedresource.py rename to src/fides/api/alembic/migrations/versions/d9237a0c0d5a_add_data_uses_column_to_stagedresource.py index a7797c90f6..b1298f4c05 100644 --- a/src/fides/api/alembic/migrations/versions/d9237a0c0d5a_add_hidden_column_to_stagedresource.py +++ b/src/fides/api/alembic/migrations/versions/d9237a0c0d5a_add_data_uses_column_to_stagedresource.py @@ -1,4 +1,4 @@ -"""add `data_uses` columns to stagedresource +"""add `data_uses` column to stagedresource Revision ID: d9237a0c0d5a Revises: e5ec30dfcd87 diff --git a/src/fides/api/api/v1/endpoints/system.py b/src/fides/api/api/v1/endpoints/system.py index 982a2dd09d..cd776397fb 100644 --- a/src/fides/api/api/v1/endpoints/system.py +++ b/src/fides/api/api/v1/endpoints/system.py @@ -391,48 +391,37 @@ async def ls( # pylint: disable=invalid-name data_uses: Optional[List[FidesKey]] = Query(None), data_categories: Optional[List[FidesKey]] = Query(None), data_subjects: Optional[List[FidesKey]] = Query(None), - show_deleted: Optional[bool] = Query(False), ) -> List: """Get a list of all of the Systems. - If any parameters or filters are provided the response will be paginated and/or filtered. + If any pagination parameters (size or page) are provided, then the response will be paginated + & provided filters (search, taxonomy fields) will be applied. Otherwise all Systems will be returned (this may be a slow operation if there are many systems, so using the pagination parameters is recommended). """ - if not (size or page or search or data_uses or data_categories or data_subjects): - return await list_resource(System, db) - - pagination_params = Params(page=page or 1, size=size or 50) - # Need to join with PrivacyDeclaration in order to be able to filter - # by data use, data category, and data subject - query = select(System).outerjoin( - PrivacyDeclaration, System.id == PrivacyDeclaration.system_id - ) - - # Filter out any vendor deleted systems, unless explicitly asked for - if not show_deleted: - query = query.filter( - or_( - System.vendor_deleted_date.is_(None), - System.vendor_deleted_date >= datetime.datetime.now(), - ) + if size or page: + pagination_params = Params(page=page or 1, size=size or 50) + # Need to join with PrivacyDeclaration in order to be able to filter + # by data use, data category, and data subject + query = select(System).outerjoin( + PrivacyDeclaration, System.id == PrivacyDeclaration.system_id ) + filter_params = FilterParams( + search=search, + data_uses=data_uses, + data_categories=data_categories, + data_subjects=data_subjects, + ) + filtered_query = apply_filters_to_query( + query=query, + filter_params=filter_params, + search_model=System, + taxonomy_model=PrivacyDeclaration, + ) + # Add a distinct so we only get one row per system + duplicates_removed = filtered_query.distinct(System.id) + return await async_paginate(db, duplicates_removed, pagination_params) - filter_params = FilterParams( - search=search, - data_uses=data_uses, - data_categories=data_categories, - data_subjects=data_subjects, - ) - filtered_query = apply_filters_to_query( - query=query, - filter_params=filter_params, - search_model=System, - taxonomy_model=PrivacyDeclaration, - ) - - # Add a distinct so we only get one row per system - duplicates_removed = filtered_query.distinct(System.id) - return await async_paginate(db, duplicates_removed, pagination_params) + return await list_resource(System, db) @SYSTEM_ROUTER.patch( diff --git a/src/fides/api/models/detection_discovery.py b/src/fides/api/models/detection_discovery.py index 2564c24349..37f1edfbdf 100644 --- a/src/fides/api/models/detection_discovery.py +++ b/src/fides/api/models/detection_discovery.py @@ -364,6 +364,6 @@ def fetch_staged_resources_by_type_query( if monitor_config_ids: query = query.filter(StagedResource.monitor_config_id.in_(monitor_config_ids)) if not show_hidden: - query = query.where(StagedResource.diff_status != "muted") + query = query.filter(StagedResource.diff_status != DiffStatus.MUTED.value) return query diff --git a/tests/ops/api/v1/endpoints/test_system.py b/tests/ops/api/v1/endpoints/test_system.py index 4544b46faf..39a4e954c8 100644 --- a/tests/ops/api/v1/endpoints/test_system.py +++ b/tests/ops/api/v1/endpoints/test_system.py @@ -294,6 +294,10 @@ def test_system_patch_hidden( "updated": 1, } + # fetch the system row from db + system = System.filter(system.id) + assert system.hidden is True + class TestGetConnections: def test_get_connections_not_authenticated(