From 54022e0638d1d3e748c9990e25186e35cd1f3895 Mon Sep 17 00:00:00 2001 From: tbsch Date: Wed, 8 May 2024 09:06:39 +0200 Subject: [PATCH] Fix permissions are not requested by pages()/reduce() (#183) * Add request_perms parameter to IterableMixin * Add tests --- .../models/mixins/helpers/callable.py | 4 +--- .../models/mixins/helpers/iterable.py | 4 ++++ tests/test_models_matrix.py | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/pypaperless/models/mixins/helpers/callable.py b/src/pypaperless/models/mixins/helpers/callable.py index bae9fba..c07cccc 100644 --- a/src/pypaperless/models/mixins/helpers/callable.py +++ b/src/pypaperless/models/mixins/helpers/callable.py @@ -2,8 +2,6 @@ from pypaperless.models.base import HelperProtocol, ResourceT -from .securable import SecurableMixin - class CallableMixin(HelperProtocol[ResourceT]): """Provide methods for calling a specific resource item.""" @@ -33,7 +31,7 @@ async def __call__( item = self._resource_cls.create_with_data(self._api, data) # set requesting full permissions - if SecurableMixin in type(self).__bases__ and getattr(self, "_request_full_perms", False): + if getattr(self, "_request_full_perms", False): item._params.update({"full_perms": "true"}) # noqa: SLF001 if not lazy: diff --git a/src/pypaperless/models/mixins/helpers/iterable.py b/src/pypaperless/models/mixins/helpers/iterable.py index ce28fde..2c527f5 100644 --- a/src/pypaperless/models/mixins/helpers/iterable.py +++ b/src/pypaperless/models/mixins/helpers/iterable.py @@ -94,4 +94,8 @@ def pages( params.setdefault("page", page) params.setdefault("page_size", page_size) + # set requesting full permissions + if getattr(self, "_request_full_perms", False): + params.update({"full_perms": "true"}) + return PageGenerator(self._api, self._api_path, self._resource_cls, params=params) diff --git a/tests/test_models_matrix.py b/tests/test_models_matrix.py index fac69ac..552df17 100644 --- a/tests/test_models_matrix.py +++ b/tests/test_models_matrix.py @@ -332,6 +332,7 @@ async def test_permissions( """Test permissions.""" getattr(api_latest, mapping.resource).request_permissions = True assert getattr(api_latest, mapping.resource).request_permissions + # request single object resp.get( re.compile( r"^" @@ -347,6 +348,22 @@ async def test_permissions( item = await getattr(api_latest, mapping.resource)(1) assert item.has_permissions assert isinstance(item.permissions, PermissionTableType) + # request by iterator + resp.get( + re.compile(r"^" + f"{PAPERLESS_TEST_URL}{API_PATH[mapping.resource]}" + r"\?.*$"), + status=200, + payload={ + **PATCHWORK[mapping.resource], + "results": [ + {**item, "permissions": PATCHWORK["object_permissions"]} + for item in PATCHWORK[mapping.resource]["results"] + ], + }, + ) + async for item in getattr(api_latest, mapping.resource): + assert isinstance(item, mapping.model_cls) + assert item.has_permissions + assert isinstance(item.permissions, PermissionTableType) async def test_permission_change( self, resp: aioresponses, api_latest: Paperless, mapping: ResourceTestMapping