Skip to content

Commit

Permalink
Code review improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
erosselli committed Jul 31, 2024
1 parent f094f68 commit 071258d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/fides/api/api/v1/endpoints/dataset_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ def delete_dataset(
f"/filter{DATASETS}",
dependencies=[Security(verify_oauth_client, scopes=[DATASET_READ])],
response_model=List[Dataset],
deprecated=True,
)
def get_ctl_datasets(
db: Session = Depends(deps.get_db),
Expand Down
14 changes: 8 additions & 6 deletions src/fides/api/api/v1/endpoints/generic_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.sql.expression import select

from fides.api.db.crud import list_resource
from fides.api.db.crud import list_resource_query
from fides.api.db.ctl_session import get_async_db
from fides.api.models.connectionconfig import ConnectionConfig
from fides.api.models.datasetconfig import DatasetConfig
Expand Down Expand Up @@ -45,15 +45,14 @@ async def list_dataset_paginated(
) -> Union[Page[Dataset], List[Dataset]]:
"""
Get a list of all of the Datasets.
If any pagination parameters (size or page) are provided, then the response will be paginated
& provided filters (search, data_categories, exclude_saas_datasets, only_unlinked_datasets) will be applied.
If any pagination parameters (size or page) are provided, then the response will be paginated.
Otherwise all Datasets will be returned (this may be a slow operation if there are many datasets,
so using the pagination parameters is recommended).
Provided filters (search, data_categories, exclude_saas_datasets, only_unlinked_datasets) will be applied,
returning only the datasets that match ALL of the filters.
"""
if not page and not size:
return await list_resource(CtlDataset, db)

query = select(CtlDataset)

# Add filters for search and data categories
filter_params = FilterParams(search=search, data_categories=data_categories)
filtered_query = apply_filters_to_query(
Expand All @@ -79,6 +78,9 @@ async def list_dataset_paginated(
not_(CtlDataset.fides_key.in_(saas_subquery))
)

if not page and not size:
return await list_resource_query(db, filtered_query, CtlDataset)

pagination_params = Params(page=page or 1, size=size or 50)
return await async_paginate(db, filtered_query, pagination_params)

Expand Down
36 changes: 36 additions & 0 deletions tests/ops/api/v1/endpoints/test_dataset_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2015,6 +2015,42 @@ def test_list_dataset_no_pagination(
assert sorted_items[0]["fides_key"] == ctl_dataset.fides_key
assert sorted_items[1]["fides_key"] == secondary_sendgrid_instance[1].fides_key

def test_list_dataset_no_pagination_exclude_saas(
self,
api_client: TestClient,
generate_auth_header,
ctl_dataset,
secondary_sendgrid_instance,
):
auth_header = generate_auth_header(scopes=[DATASET_READ])
response = api_client.get(
f"{V1_URL_PREFIX}/dataset?exclude_saas_datasets=True",
headers=auth_header,
)

assert response.status_code == 200
response_json = response.json()
assert len(response_json) == 1
assert response_json[0]["fides_key"] == ctl_dataset.fides_key

def test_list_dataset_no_pagination_only_unlinked_datasets(
self,
api_client: TestClient,
generate_auth_header,
unlinked_dataset,
linked_dataset,
):
auth_header = generate_auth_header(scopes=[DATASET_READ])
response = api_client.get(
f"{V1_URL_PREFIX}/dataset?only_unlinked_datasets=True",
headers=auth_header,
)

assert response.status_code == 200
response_json = response.json()
assert len(response_json) == 1
assert response_json[0]["fides_key"] == unlinked_dataset.fides_key

def test_list_dataset_with_pagination(
self,
api_client: TestClient,
Expand Down

0 comments on commit 071258d

Please sign in to comment.