Skip to content

Commit

Permalink
Merge pull request #1524 from open-zaak/feature/1522-documenten-expand
Browse files Browse the repository at this point in the history
Feature/1522 documenten expand
  • Loading branch information
annashamray committed Jan 17, 2024
2 parents bb7427a + 000dcd5 commit 8a733a1
Show file tree
Hide file tree
Showing 16 changed files with 407 additions and 43 deletions.
11 changes: 11 additions & 0 deletions src/openzaak/components/documenten/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,28 @@
from vng_api_common.filtersets import FilterSet
from vng_api_common.utils import get_help_text

from openzaak.utils.filters import ExpandFilter

from ..models import (
EnkelvoudigInformatieObject,
EnkelvoudigInformatieObjectCanonical,
Gebruiksrechten,
ObjectInformatieObject,
Verzending,
)
from .serializers import (
EnkelvoudigInformatieObjectSerializer,
GebruiksrechtenSerializer,
VerzendingSerializer,
)
from .utils import check_path

logger = logging.getLogger(__name__)


class EnkelvoudigInformatieObjectListFilter(FilterSet):
expand = ExpandFilter(serializer_class=EnkelvoudigInformatieObjectSerializer)

class Meta:
model = EnkelvoudigInformatieObject
fields = ("identificatie", "bronorganisatie")
Expand All @@ -42,6 +51,7 @@ class GebruiksrechtenFilter(FilterSet):
instance_path="canonical",
help_text=get_help_text("documenten.Gebruiksrechten", "informatieobject"),
)
expand = ExpandFilter(serializer_class=GebruiksrechtenSerializer)

class Meta:
model = Gebruiksrechten
Expand Down Expand Up @@ -112,6 +122,7 @@ class VerzendingFilter(FilterSet):
instance_path="canonical",
help_text=get_help_text("documenten.Verzending", "informatieobject"),
)
expand = ExpandFilter(serializer_class=VerzendingSerializer)

class Meta:
model = Verzending
Expand Down
45 changes: 24 additions & 21 deletions src/openzaak/components/documenten/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from django.utils.http import urlencode
from django.utils.translation import ugettext_lazy as _

from django_loose_fk.drf import FKOrURLField
from drc_cmis.utils.convert import make_absolute_uri
from drf_extra_fields.fields import Base64FileField
from humanize import naturalsize
Expand All @@ -33,7 +32,10 @@
from vng_api_common.utils import get_help_text

from openzaak.contrib.verzoeken.validators import verzoek_validator
from openzaak.utils.serializer_fields import LengthHyperlinkedRelatedField
from openzaak.utils.serializer_fields import (
FKOrServiceUrlField,
LengthHyperlinkedRelatedField,
)
from openzaak.utils.serializers import get_from_serializer_data_or_instance
from openzaak.utils.validators import (
IsImmutableValidator,
Expand All @@ -56,7 +58,6 @@
Verzending,
)
from ..query.cmis import flatten_gegevens_groep
from ..query.django import InformatieobjectRelatedQuerySet
from ..utils import PrivateMediaStorageWithCMIS
from .fields import OnlyRemoteOrFKOrURLField
from .scopes import SCOPE_DOCUMENTEN_GEFORCEERD_BIJWERKEN
Expand All @@ -68,6 +69,8 @@
VerzendingAddressValidator,
)

oz = "openzaak.components"


class AnyFileType:
def __contains__(self, item):
Expand Down Expand Up @@ -179,23 +182,6 @@ class EnkelvoudigInformatieObjectHyperlinkedRelatedField(LengthHyperlinkedRelate
store the uuid
"""

def get_url(self, obj, view_name, request, format):
# obj is a EIOCanonical. If CMIS is enabled, it can't be used to retrieve the EIO latest version.
if settings.CMIS_ENABLED:
# self.parent is a serialiser, with instance Oio/Gebruiksrechten. These can be used to retrieve the EIO
if isinstance(self.parent.instance, Gebruiksrechten) or isinstance(
self.parent.instance, ObjectInformatieObject
):
eio_latest_version = self.parent.instance.get_informatieobject()
# If self.parent.parent is a ListSerializer, self.parent.instance is a queryset rather than a
# gebruiksrechten/oio. The informatieobject URL cannot be retrieved. See issue #791
elif isinstance(self.parent.instance, InformatieobjectRelatedQuerySet):
return ""
else:
eio_latest_version = obj.latest_version

return super().get_url(eio_latest_version, view_name, request, format)

def get_object(self, view_name, view_args, view_kwargs):
lookup_value = view_kwargs[self.lookup_url_kwarg]
lookup_kwargs = {self.lookup_field: lookup_value}
Expand All @@ -210,6 +196,9 @@ def get_object(self, view_name, view_args, view_kwargs):
except (TypeError, AttributeError):
self.fail("does_not_exist")

def get_attribute(self, instance):
return instance.get_informatieobject()


class BestandsDeelSerializer(serializers.HyperlinkedModelSerializer):
lock = serializers.CharField(
Expand Down Expand Up @@ -289,7 +278,7 @@ class EnkelvoudigInformatieObjectSerializer(serializers.HyperlinkedModelSerializ
"Uitdrukking van mate van volledigheid en onbeschadigd zijn van digitaal bestand."
),
)
informatieobjecttype = FKOrURLField(
informatieobjecttype = FKOrServiceUrlField(
lookup_field="uuid",
max_length=200,
min_length=1,
Expand Down Expand Up @@ -324,6 +313,10 @@ class EnkelvoudigInformatieObjectSerializer(serializers.HyperlinkedModelSerializ
many=True, source="get_bestandsdelen", read_only=True,
)

inclusion_serializers = {
"informatieobjecttype": f"{oz}.catalogi.api.serializers.InformatieObjectTypeSerializer",
}

class Meta:
model = EnkelvoudigInformatieObject
fields = (
Expand Down Expand Up @@ -871,6 +864,11 @@ class GebruiksrechtenSerializer(serializers.HyperlinkedModelSerializer):
help_text=get_help_text("documenten.Gebruiksrechten", "informatieobject"),
)

inclusion_serializers = {
"informatieobject": f"{oz}.documenten.api.serializers.EnkelvoudigInformatieObjectSerializer",
"informatieobject.informatieobjecttype": f"{oz}.catalogi.api.serializers.InformatieObjectTypeSerializer",
}

class Meta:
model = Gebruiksrechten
fields = (
Expand Down Expand Up @@ -1059,6 +1057,11 @@ class VerzendingSerializer(
),
)

inclusion_serializers = {
"informatieobject": f"{oz}.documenten.api.serializers.EnkelvoudigInformatieObjectSerializer",
"informatieobject.informatieobjecttype": f"{oz}.catalogi.api.serializers.InformatieObjectTypeSerializer",
}

class Meta:
model = Verzending
fields = (
Expand Down
13 changes: 12 additions & 1 deletion src/openzaak/components/documenten/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@

from openzaak.utils.data_filtering import ListFilterByAuthorizationsMixin
from openzaak.utils.exceptions import CMISNotSupportedException
from openzaak.utils.mixins import CMISConnectionPoolMixin, ConvertCMISAdapterExceptions
from openzaak.utils.mixins import (
CMISConnectionPoolMixin,
ConvertCMISAdapterExceptions,
ExpandMixin,
)
from openzaak.utils.pagination import OptimizedPagination
from openzaak.utils.permissions import AuthRequired
from openzaak.utils.schema import COMMON_ERROR_RESPONSES, use_ref
Expand Down Expand Up @@ -97,6 +101,7 @@ class EnkelvoudigInformatieObjectViewSet(
ConvertCMISAdapterExceptions,
CheckQueryParamsMixin,
SearchMixin,
ExpandMixin,
NotificationViewSetMixin,
ListFilterByAuthorizationsMixin,
AuditTrailViewsetMixin,
Expand Down Expand Up @@ -390,6 +395,10 @@ def _zoek(self, request, *args, **kwargs):
)
raise ValidationError({api_settings.NON_FIELD_ERRORS_KEY: err})

expand_param = self.get_requested_inclusions(request)
if settings.CMIS_ENABLED and expand_param:
raise CMISNotSupportedException()

search_input = self.get_search_input()
queryset = self.filter_queryset(self.get_queryset())

Expand All @@ -406,6 +415,7 @@ class GebruiksrechtenViewSet(
CMISConnectionPoolMixin,
ConvertCMISAdapterExceptions,
CheckQueryParamsMixin,
ExpandMixin,
NotificationViewSetMixin,
ListFilterByAuthorizationsMixin,
AuditTrailViewsetMixin,
Expand Down Expand Up @@ -643,6 +653,7 @@ class BestandsDeelViewSet(UpdateWithoutPartialMixin, viewsets.GenericViewSet):
@cmis_conditional_retrieve()
class VerzendingViewSet(
CheckQueryParamsMixin,
ExpandMixin,
NotificationViewSetMixin,
ListFilterByAuthorizationsMixin,
# in the OAS there are no additional audittrail endpoints for verzending
Expand Down
7 changes: 3 additions & 4 deletions src/openzaak/components/documenten/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from rest_framework.reverse import reverse
from vng_api_common.descriptors import GegevensGroepType
from vng_api_common.fields import RSINField, VertrouwelijkheidsAanduidingField
from vng_api_common.models import APIMixin
from vng_api_common.utils import generate_unique_identification
from vng_api_common.validators import alphanumeric_excluding_diacritic
from zgw_consumers.models import ServiceUrlField
Expand All @@ -29,7 +28,7 @@
RelativeURLField,
ServiceFkField,
)
from openzaak.utils.mixins import AuditTrailMixin, CMISClientMixin
from openzaak.utils.mixins import APIMixin, AuditTrailMixin, CMISClientMixin

from ..besluiten.models import BesluitInformatieObject
from ..zaken.models import ZaakInformatieObject
Expand Down Expand Up @@ -636,7 +635,7 @@ def voltooid(self) -> bool:
return self.inhoud.size == self.omvang


class Gebruiksrechten(CMISETagMixin, models.Model, CMISClientMixin):
class Gebruiksrechten(APIMixin, CMISETagMixin, models.Model, CMISClientMixin):
uuid = models.UUIDField(
unique=True, default=_uuid.uuid4, help_text="Unieke resource identifier (UUID4)"
)
Expand Down Expand Up @@ -972,7 +971,7 @@ def does_zaakinformatieobject_exist(self):


# gebaseerd op https://www.gemmaonline.nl/index.php/Rgbz_2.0/doc/relatieklasse/verzending
class Verzending(CMISETagMixin, models.Model):
class Verzending(APIMixin, CMISETagMixin, models.Model):
uuid = models.UUIDField(
unique=True,
default=_uuid.uuid4,
Expand Down
83 changes: 80 additions & 3 deletions src/openzaak/components/documenten/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ paths:
required: false
schema:
type: string
- name: expand
in: query
description: 'Sluit de gespecifieerde gerelateerde resources in in het antwoord. '
required: false
schema:
type: array
items:
type: string
enum:
- informatieobjecttype
style: form
explode: false
- name: page
in: query
description: Een pagina binnen de gepagineerde set resultaten.
Expand Down Expand Up @@ -196,7 +208,17 @@ paths:
results:
type: array
items:
$ref: '#/components/schemas/EnkelvoudigInformatieObject'
type: object
allOf:
- $ref: '#/components/schemas/EnkelvoudigInformatieObject'
- type: object
properties:
_expand:
description: Display details of the linked resources requested
in the `expand` parameter
type: object
properties:
informatieobjecttype: https://raw.githubusercontent.com/vng-Realisatie/catalogi-api/1.2.0/src/openapi.yaml#/components/schemas/InformatieObjectType
'400':
$ref: '#/components/responses/400'
'401':
Expand Down Expand Up @@ -1135,6 +1157,19 @@ paths:
required: false
schema:
type: string
- name: expand
in: query
description: 'Sluit de gespecifieerde gerelateerde resources in in het antwoord. '
required: false
schema:
type: array
items:
type: string
enum:
- informatieobject
- informatieobject.informatieobjecttype
style: form
explode: false
responses:
'200':
description: OK
Expand All @@ -1149,7 +1184,18 @@ paths:
schema:
type: array
items:
$ref: '#/components/schemas/Gebruiksrechten'
type: object
allOf:
- $ref: '#/components/schemas/Gebruiksrechten'
- type: object
properties:
_expand:
description: Display details of the linked resources requested
in the `expand` parameter
type: object
properties:
informatieobject:
$ref: '#/components/schemas/EnkelvoudigInformatieObject'
'400':
$ref: '#/components/responses/400'
'401':
Expand Down Expand Up @@ -1974,6 +2020,19 @@ paths:
schema:
type: string
format: uri
- name: expand
in: query
description: 'Sluit de gespecifieerde gerelateerde resources in in het antwoord. '
required: false
schema:
type: array
items:
type: string
enum:
- informatieobject
- informatieobject.informatieobjecttype
style: form
explode: false
- name: page
in: query
description: Een pagina binnen de gepagineerde set resultaten.
Expand Down Expand Up @@ -2010,7 +2069,18 @@ paths:
results:
type: array
items:
$ref: '#/components/schemas/Verzending'
type: object
allOf:
- $ref: '#/components/schemas/Verzending'
- type: object
properties:
_expand:
description: Display details of the linked resources requested
in the `expand` parameter
type: object
properties:
informatieobject:
$ref: '#/components/schemas/EnkelvoudigInformatieObject'
'400':
$ref: '#/components/responses/400'
'401':
Expand Down Expand Up @@ -3262,6 +3332,13 @@ components:
\ eerste in een samenwerkingsketen heeft vastgelegd."
type: string
minLength: 1
expand:
title: Expand
description: "Sluit de gespecifieerde gerelateerde resources in in het antwoord.\
\ \n\nUitleg bij mogelijke waarden:\n\n* `informatieobjecttype` - informatieobjecttype"
type: string
enum:
- informatieobjecttype
EnkelvoudigInformatieObjectData:
required:
- bronorganisatie
Expand Down

0 comments on commit 8a733a1

Please sign in to comment.