Skip to content

Commit 0119ae9

Browse files
authored
Add profile ids filter to crawlconfigs search-values endpoint (#3000)
Backend work to help support #2978
1 parent 9cef9bf commit 0119ae9

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

backend/btrixcloud/crawlconfigs.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44

55
# pylint: disable=too-many-lines
66

7-
from typing import List, Optional, TYPE_CHECKING, cast, Dict, Tuple, Annotated, Union
7+
from typing import (
8+
List,
9+
Optional,
10+
TYPE_CHECKING,
11+
cast,
12+
Dict,
13+
Tuple,
14+
Annotated,
15+
Union,
16+
Any,
17+
)
818

919
import asyncio
1020
import json
@@ -1174,12 +1184,18 @@ async def get_crawl_config_tag_counts(self, org):
11741184
).to_list()
11751185
return tags
11761186

1177-
async def get_crawl_config_search_values(self, org):
1187+
async def get_crawl_config_search_values(
1188+
self, org, profile_ids: Optional[List[UUID]] = None
1189+
):
11781190
"""List unique names, first seeds, and descriptions from all workflows in org"""
1179-
names = await self.crawl_configs.distinct("name", {"oid": org.id})
1180-
descriptions = await self.crawl_configs.distinct("description", {"oid": org.id})
1181-
workflow_ids = await self.crawl_configs.distinct("_id", {"oid": org.id})
1182-
first_seeds = await self.crawl_configs.distinct("firstSeed", {"oid": org.id})
1191+
query: Dict[str, Any] = {"oid": org.id}
1192+
if profile_ids:
1193+
query["profileid"] = {"$in": profile_ids}
1194+
1195+
names = await self.crawl_configs.distinct("name", query)
1196+
descriptions = await self.crawl_configs.distinct("description", query)
1197+
workflow_ids = await self.crawl_configs.distinct("_id", query)
1198+
first_seeds = await self.crawl_configs.distinct("firstSeed", query)
11831199

11841200
# Remove empty strings
11851201
names = [name for name in names if name]
@@ -1700,8 +1716,11 @@ async def get_crawl_config_tag_counts(org: Organization = Depends(org_viewer_dep
17001716
@router.get("/search-values", response_model=CrawlConfigSearchValues)
17011717
async def get_crawl_config_search_values(
17021718
org: Organization = Depends(org_viewer_dep),
1719+
profile_ids: Annotated[
1720+
Optional[List[UUID]], Query(alias="profileIds", title="Profile IDs")
1721+
] = None,
17031722
):
1704-
return await ops.get_crawl_config_search_values(org)
1723+
return await ops.get_crawl_config_search_values(org, profile_ids)
17051724

17061725
@router.get("/crawler-channels", response_model=CrawlerChannels)
17071726
async def get_crawler_channels(

backend/test/test_crawl_config_search_values.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,17 @@ def test_get_search_values_3(admin_auth_headers, default_org_id):
124124
assert sorted(data["firstSeeds"]) == sorted(
125125
["https://old.webrecorder.net/", FIRST_SEED_1_URL, FIRST_SEED_2_URL]
126126
)
127+
128+
129+
def test_get_search_values_filter_profiles(
130+
admin_auth_headers, default_org_id, profile_id, profile_config_id
131+
):
132+
"""Test profile_ids filter"""
133+
r = requests.get(
134+
f"{API_PREFIX}/orgs/{default_org_id}/crawlconfigs/search-values?profileIds={profile_id}",
135+
headers=admin_auth_headers,
136+
)
137+
data = r.json()
138+
assert data["names"] == ["Profile Test Crawl"]
139+
assert data["descriptions"] == ["Crawl using browser profile"]
140+
assert data["firstSeeds"] == ["https://old.webrecorder.net/"]

backend/test/test_filter_sort_results.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,9 @@ def test_sort_crawl_configs(
362362
headers=crawler_auth_headers,
363363
)
364364
data = r.json()
365-
assert data["total"] == 16
365+
assert data["total"] == 17
366366
items = data["items"]
367-
assert len(items) == 16
367+
assert len(items) == 17
368368

369369
last_created = None
370370
for config in items:

0 commit comments

Comments
 (0)