Skip to content

Commit

Permalink
Merge pull request #1402 from open-zaak/feature/besluit-list-optimiza…
Browse files Browse the repository at this point in the history
…tion

besluiten list api optimization
  • Loading branch information
annashamray committed Jul 17, 2023
2 parents 0732264 + 322aba9 commit 0571396
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/openzaak/components/besluiten/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def __init__(self, *args, **kwargs):
if isinstance(self, ProxyMixin):
self._previous_zaak = self.zaak
else:
self._previous_zaak = self._zaak
self._previous_zaak_id = self._zaak_id
self._previous_zaak_url = self._zaak_url

def __str__(self):
Expand All @@ -217,10 +217,15 @@ def unique_representation(self):

@property
def previous_zaak(self):
if self._previous_zaak:
from openzaak.components.zaken.models import Zaak

if getattr(self, "_previous_zaak", None):
return self._previous_zaak

if self._previous_zaak_url:
if getattr(self, "_previous_zaak_id", None):
return Zaak.objects.get(pk=self._previous_zaak_id)

if getattr(self, "_previous_zaak_url", None):
remote_model = apps.get_model("zaken", "Zaak")
return AuthorizedRequestsLoader().load(
url=self._previous_zaak_url, model=remote_model
Expand Down
22 changes: 22 additions & 0 deletions src/openzaak/components/besluiten/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ def test_besluit_list(self):
results[0]["besluittype"], f"http://testserver{reverse(self.besluittype)}"
)

def test_besluit_list_empty_max_vertrouwelijkheidaanduiding(self):
"""
max_vertrouwelijkheidaanduiding is not used for besluiten
"""
self.autorisatie.max_vertrouwelijkheidaanduiding = ""
self.autorisatie.save()

BesluitFactory.create(besluittype=self.besluittype)
BesluitFactory.create()
url = reverse("besluit-list")

response = self.client.get(url)

self.assertEqual(response.status_code, status.HTTP_200_OK)

results = response.data["results"]

self.assertEqual(len(results), 1)
self.assertEqual(
results[0]["besluittype"], f"http://testserver{reverse(self.besluittype)}"
)

def test_besluit_retreive(self):
"""
Assert you can only read BESLUITen of the besluittypes of your authorization
Expand Down
17 changes: 9 additions & 8 deletions src/openzaak/utils/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,16 @@ def get_filters(self, scope, authorizations, local=True) -> dict:
loose_fk_objecten.append(loose_fk_object)

# extract the order and map it to the database value
choice_item = VertrouwelijkheidsAanduiding.get_choice(
authorization.max_vertrouwelijkheidaanduiding
)
vertrouwelijkheidaanduiding_whens.append(
When(
**{f"{prefix}{loose_fk_field}": loose_fk_object},
then=Value(choice_item.order),
if authorization.max_vertrouwelijkheidaanduiding:
choice_item = VertrouwelijkheidsAanduiding.get_choice(
authorization.max_vertrouwelijkheidaanduiding
)
vertrouwelijkheidaanduiding_whens.append(
When(
**{f"{prefix}{loose_fk_field}": loose_fk_object},
then=Value(choice_item.order),
)
)
)

# filtering:
# * only allow the white-listed loose-fk objects, explicitly
Expand Down

0 comments on commit 0571396

Please sign in to comment.