Skip to content

Commit

Permalink
PR feedback and reset system endpoint to exactly what it was before
Browse files Browse the repository at this point in the history
  • Loading branch information
thingscouldbeworse committed Dec 19, 2024
1 parent 7181a02 commit 61f38a4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""add `data_uses` columns to stagedresource
"""add `data_uses` column to stagedresource
Revision ID: d9237a0c0d5a
Revises: e5ec30dfcd87
Expand Down
59 changes: 24 additions & 35 deletions src/fides/api/api/v1/endpoints/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/fides/api/models/detection_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions tests/ops/api/v1/endpoints/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 61f38a4

Please sign in to comment.