Skip to content

Commit

Permalink
✨ No zaak related to object returns empty list (#1230)
Browse files Browse the repository at this point in the history
  • Loading branch information
damm89 authored Mar 22, 2024
1 parent 85ecedc commit 0467b1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
18 changes: 10 additions & 8 deletions backend/src/zac/elasticsearch/searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Bool,
Exists,
Match,
MatchNone,
MultiMatch,
Nested,
Query,
Expand Down Expand Up @@ -178,19 +179,20 @@ def search_zaken(

if object:
zon = search_zaakobjecten(zaken=urls, objecten=[object])
if not urls:
urls = []
zaakobject_zaakurls = [zo.zaak for zo in zon]
if urls:
urls += zaakobject_zaakurls
else:
urls = zaakobject_zaakurls

for zo in zon:
if zo.zaak not in urls:
urls.append(zo.zaak)
if urls:
s = s.filter(Terms(url=list(set(urls))))
elif type(urls) == list: # apparently we've gotten an empty list -> show nothing.
s = s.filter(MatchNone())

if not include_closed:
s = s.filter(~Exists(field="einddatum"))

if urls:
s = s.filter(Terms(url=urls))

# display only allowed zaken
if only_allowed:
s = s.filter(query_allowed_for_requester(request))
Expand Down
10 changes: 9 additions & 1 deletion backend/src/zac/elasticsearch/tests/test_api_zaken_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def test_search(self, m):
## ZAAKOBJECTEN
zaakobject = {
"url": f"{ZAKEN_ROOT}zaakobjecten/4abe87ea-3670-42c8-afc7-5e9fb071971d",
"object": "https://objects.nl/api/v1/objects/aa44d251-0ddc-4bf2-b114-00a5ce1925d1",
"object": f"{OBJECTS_ROOT}objects/aa44d251-0ddc-4bf2-b114-00a5ce1925d1",
"zaak": zaak1["url"],
"object_type": "",
"object_type_overige": "",
Expand Down Expand Up @@ -731,3 +731,11 @@ def test_search(self, m):
results = response.json()
self.assertEqual(results["count"], 1)
self.assertEqual(results["results"][0]["url"], zaak3["url"])

with self.subTest("Search with empty list of urls"):
data = {"object": f"{OBJECTS_ROOT}objects/123"}

response = self.client.post(self.endpoint, data=data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
results = response.json()
self.assertEqual(results["count"], 0)

0 comments on commit 0467b1f

Please sign in to comment.