Exemplo n.º 1
0
    def set_object_properties(self, object_type: str) -> None:
        object_field = self.fields["object"]

        if object_type == ObjectTypes.besluit:
            object_field.source = "besluit"
            object_field.validators.append(
                LooseFkResourceValidator("Besluit", settings.BRC_API_SPEC))
        elif object_type == ObjectTypes.zaak:
            object_field.source = "zaak"
            object_field.validators.append(
                LooseFkResourceValidator("Zaak", settings.ZRC_API_SPEC))
Exemplo n.º 2
0
 class Meta:
     model = Status
     fields = (
         "url",
         "uuid",
         "zaak",
         "statustype",
         "datum_status_gezet",
         "statustoelichting",
     )
     validators = [
         CorrectZaaktypeValidator("statustype"),
         EndStatusIOsUnlockedValidator(),
         EndStatusIOsIndicatieGebruiksrechtValidator(),
     ]
     extra_kwargs = {
         "url": {"lookup_field": "uuid"},
         "uuid": {"read_only": True},
         "zaak": {"lookup_field": "uuid"},
         "datum_status_gezet": {"validators": [DateNotInFutureValidator()]},
         "statustype": {
             "lookup_field": "uuid",
             "max_length": 1000,
             "min_length": 1,
             "validators": [
                 LooseFkResourceValidator("StatusType", settings.ZTC_API_SPEC),
             ],
         },
     }
Exemplo n.º 3
0
 class Meta:
     model = ZaakBesluit
     fields = ("url", "uuid", "besluit")
     extra_kwargs = {
         "url": {
             "lookup_field": "uuid"
         },
         "uuid": {
             "read_only": True
         },
         "zaak": {
             "lookup_field": "uuid"
         },
         "besluit": {
             "lookup_field":
             "uuid",
             "max_length":
             1000,
             "min_length":
             1,
             "validators": [
                 LooseFkResourceValidator("Besluit", settings.BRC_API_SPEC),
             ],
         },
     }
Exemplo n.º 4
0
 class Meta:
     model = Resultaat
     fields = ("url", "uuid", "zaak", "resultaattype", "toelichting")
     validators = [CorrectZaaktypeValidator("resultaattype")]
     extra_kwargs = {
         "url": {
             "lookup_field": "uuid"
         },
         "uuid": {
             "read_only": True
         },
         "zaak": {
             "lookup_field": "uuid"
         },
         "resultaattype": {
             "lookup_field":
             "uuid",
             "max_length":
             1000,
             "min_length":
             1,
             "validators": [
                 LooseFkResourceValidator("ResultaatType",
                                          settings.ZTC_API_SPEC),
                 LooseFkIsImmutableValidator(),
             ],
         },
     }
Exemplo n.º 5
0
 class Meta:
     model = ZaakEigenschap
     fields = ("url", "uuid", "zaak", "eigenschap", "naam", "waarde")
     extra_kwargs = {
         "url": {
             "lookup_field": "uuid"
         },
         "uuid": {
             "read_only": True
         },
         "zaak": {
             "lookup_field": "uuid"
         },
         "naam": {
             "source": "_naam",
             "read_only": True
         },
         "eigenschap": {
             "lookup_field":
             "uuid",
             "max_length":
             1000,
             "min_length":
             1,
             "validators": [
                 LooseFkResourceValidator("Eigenschap",
                                          settings.ZTC_API_SPEC),
             ],
         },
     }
     validators = [CorrectZaaktypeValidator("eigenschap")]
Exemplo n.º 6
0
 class Meta:
     model = Besluit
     fields = (
         "url",
         "identificatie",
         "verantwoordelijke_organisatie",
         "besluittype",
         "zaak",
         "datum",
         "toelichting",
         "bestuursorgaan",
         "ingangsdatum",
         "vervaldatum",
         "vervalreden",
         "vervalreden_weergave",
         "publicatiedatum",
         "verzenddatum",
         "uiterlijke_reactiedatum",
     )
     extra_kwargs = {
         "url": {
             "lookup_field": "uuid"
         },
         # per BRC API spec!
         "besluittype": {
             "lookup_field":
             "uuid",
             "max_length":
             200,
             "min_length":
             1,
             "validators": [
                 LooseFkResourceValidator("BesluitType",
                                          settings.ZTC_API_SPEC),
                 LooseFkIsImmutableValidator(),
                 PublishValidator(),
             ],
         },
         # per BRC API spec!
         "zaak": {
             "lookup_field": "uuid",
             "max_length": 200
         },
         "identificatie": {
             "validators": [IsImmutableValidator()]
         },
         "verantwoordelijke_organisatie": {
             "validators": [IsImmutableValidator(), validate_rsin]
         },
     }
     validators = [
         UniekeIdentificatieValidator(),
         BesluittypeZaaktypeValidator()
     ]
Exemplo n.º 7
0
 class Meta:
     model = RelevanteZaakRelatie
     fields = ("url", "aard_relatie")
     extra_kwargs = {
         "url": {
             "lookup_field": "uuid",
             "max_length": 1000,
             "min_length": 1,
             "validators": [LooseFkResourceValidator("Zaak", settings.ZRC_API_SPEC)],
         },
     }
Exemplo n.º 8
0
 class Meta:
     model = Rol
     fields = (
         "url",
         "uuid",
         "zaak",
         "betrokkene",
         "betrokkene_type",
         "roltype",
         "omschrijving",
         "omschrijving_generiek",
         "roltoelichting",
         "registratiedatum",
         "indicatie_machtiging",
     )
     validators = [
         RolOccurenceValidator(RolOmschrijving.initiator, max_amount=1),
         RolOccurenceValidator(RolOmschrijving.zaakcoordinator,
                               max_amount=1),
         CorrectZaaktypeValidator("roltype"),
     ]
     extra_kwargs = {
         "url": {
             "lookup_field": "uuid"
         },
         "uuid": {
             "read_only": True
         },
         "zaak": {
             "lookup_field": "uuid"
         },
         "betrokkene": {
             "required": False
         },
         "roltype": {
             "lookup_field":
             "uuid",
             "max_length":
             1000,
             "min_length":
             1,
             "validators": [
                 LooseFkResourceValidator("RolType", settings.ZTC_API_SPEC),
                 LooseFkIsImmutableValidator(),
             ],
             "help_text":
             get_help_text("zaken.Rol", "roltype"),
         },
     }
Exemplo n.º 9
0
 class Meta:
     model = EnkelvoudigInformatieObject
     fields = (
         "url",
         "identificatie",
         "bronorganisatie",
         "creatiedatum",
         "titel",
         "vertrouwelijkheidaanduiding",
         "auteur",
         "status",
         "formaat",
         "taal",
         "versie",
         "begin_registratie",
         "bestandsnaam",
         "inhoud",
         "bestandsomvang",
         "link",
         "beschrijving",
         "ontvangstdatum",
         "verzenddatum",
         "indicatie_gebruiksrecht",
         "ondertekening",
         "integriteit",
         "informatieobjecttype",  # van-relatie,
         "locked",
     )
     extra_kwargs = {
         "taal": {
             "min_length": 3
         },
         "informatieobjecttype": {
             "lookup_field":
             "uuid",
             "max_length":
             200,
             "min_length":
             1,
             "validators": [
                 LooseFkResourceValidator("InformatieObjectType",
                                          settings.ZTC_API_SPEC),
                 LooseFkIsImmutableValidator(),
                 PublishValidator(),
             ],
         },
     }
     read_only_fields = ["versie", "begin_registratie"]
     validators = [StatusValidator()]
Exemplo n.º 10
0
class BesluitInformatieObjectSerializer(serializers.HyperlinkedModelSerializer):
    informatieobject = EnkelvoudigInformatieObjectField(
        validators=[
            LooseFkIsImmutableValidator(instance_path="canonical"),
            LooseFkResourceValidator(
                "EnkelvoudigInformatieObject", settings.DRC_API_SPEC
            ),
        ],
        max_length=1000,
        min_length=1,
        help_text=get_help_text(
            "besluiten.BesluitInformatieObject", "informatieobject"
        ),
    )

    class Meta:
        model = BesluitInformatieObject
        fields = ("url", "informatieobject", "besluit")
        validators = [
            UniqueTogetherValidator(
                queryset=BesluitInformatieObject.objects.all(),
                fields=["besluit", "informatieobject"],
            ),
            ObjecttypeInformatieobjecttypeRelationValidator("besluit", "besluittype"),
        ]
        extra_kwargs = {
            "url": {"lookup_field": "uuid"},
            "besluit": {"lookup_field": "uuid", "validators": [IsImmutableValidator()]},
        }

    def create(self, validated_data):
        with transaction.atomic():
            bio = super().create(validated_data)

        # local FK or CMIS - nothing to do -> our signals create the OIO
        if bio.informatieobject.pk or settings.CMIS_ENABLED:
            return bio

        # we know that we got valid URLs in the initial data
        io_url = self.initial_data["informatieobject"]
        besluit_url = self.initial_data["besluit"]

        # manual transaction management - documents API checks that the BIO
        # exists, so that transaction must be committed.
        # If it fails in any other way, we need to handle that by rolling back
        # the BIO creation.
        try:
            response = create_remote_oio(io_url, besluit_url, "besluit")
        except Exception as exception:
            bio.delete()
            raise serializers.ValidationError(
                {
                    "informatieobject": _(
                        "Could not create remote relation: {exception}"
                    ).format(exception=exception)
                },
                code="pending-relations",
            )
        else:
            bio._objectinformatieobject_url = response["url"]
            bio.save()
        return bio

    def run_validators(self, value):
        """
        Add read_only fields with defaults to value before running validators.
        """
        # In the case CMIS is enabled, we need to filter on the URL and not the canonical object
        if value.get("informatieobject") is not None and settings.CMIS_ENABLED:
            value["informatieobject"] = self.initial_data.get("informatieobject")

        return super().run_validators(value)
Exemplo n.º 11
0
class ZaakInformatieObjectSerializer(serializers.HyperlinkedModelSerializer):
    aard_relatie_weergave = serializers.ChoiceField(
        source="get_aard_relatie_display",
        read_only=True,
        choices=[(force_text(value), key) for key, value in RelatieAarden.choices],
    )
    informatieobject = EnkelvoudigInformatieObjectField(
        validators=[
            LooseFkIsImmutableValidator(instance_path="canonical"),
            LooseFkResourceValidator(
                "EnkelvoudigInformatieObject", settings.DRC_API_SPEC
            ),
        ],
        max_length=1000,
        min_length=1,
        help_text=get_help_text("zaken.ZaakInformatieObject", "informatieobject"),
    )

    class Meta:
        model = ZaakInformatieObject
        fields = (
            "url",
            "uuid",
            "informatieobject",
            "zaak",
            "aard_relatie_weergave",
            "titel",
            "beschrijving",
            "registratiedatum",
        )
        validators = [
            UniqueTogetherValidator(
                queryset=ZaakInformatieObject.objects.all(),
                fields=["zaak", "informatieobject"],
            ),
            ObjecttypeInformatieobjecttypeRelationValidator(),
        ]
        extra_kwargs = {
            "url": {"lookup_field": "uuid"},
            "uuid": {"read_only": True},
            "zaak": {"lookup_field": "uuid", "validators": [IsImmutableValidator()]},
        }

    def create(self, validated_data):
        with transaction.atomic():
            zio = super().create(validated_data)

        # local FK - nothing to do -> our signals create the OIO
        if zio.informatieobject.pk:
            return zio

        # we know that we got valid URLs in the initial data
        io_url = self.initial_data["informatieobject"]
        zaak_url = self.initial_data["zaak"]

        # manual transaction management - documents API checks that the ZIO
        # exists, so that transaction must be committed.
        # If it fails in any other way, we need to handle that by rolling back
        # the ZIO creation.
        try:
            response = create_remote_oio(io_url, zaak_url)
        except Exception as exception:
            zio.delete()
            raise serializers.ValidationError(
                {
                    "informatieobject": _(
                        "Could not create remote relation: {exception}"
                    ).format(exception)
                },
                code="pending-relations",
            )
        else:
            zio._objectinformatieobject_url = response["url"]
            zio.save()

        return zio
Exemplo n.º 12
0
 class Meta:
     model = Zaak
     fields = (
         "url",
         "uuid",
         "identificatie",
         "bronorganisatie",
         "omschrijving",
         "toelichting",
         "zaaktype",
         "registratiedatum",
         "verantwoordelijke_organisatie",
         "startdatum",
         "einddatum",
         "einddatum_gepland",
         "uiterlijke_einddatum_afdoening",
         "publicatiedatum",
         "communicatiekanaal",
         # TODO: add shape validator once we know the shape
         "producten_of_diensten",
         "vertrouwelijkheidaanduiding",
         "betalingsindicatie",
         "betalingsindicatie_weergave",
         "laatste_betaaldatum",
         "zaakgeometrie",
         "verlenging",
         "opschorting",
         "selectielijstklasse",
         "hoofdzaak",
         "deelzaken",
         "relevante_andere_zaken",
         "eigenschappen",
         # read-only veld, on-the-fly opgevraagd
         "status",
         # Writable inline resource, as opposed to eigenschappen for demo
         # purposes. Eventually, we need to choose one form.
         "kenmerken",
         # Archiving
         "archiefnominatie",
         "archiefstatus",
         "archiefactiedatum",
         "resultaat",
     )
     extra_kwargs = {
         "url": {"lookup_field": "uuid"},
         "uuid": {"read_only": True},
         "zaaktype": {
             "lookup_field": "uuid",
             "max_length": 1000,
             "min_length": 1,
             "validators": [
                 LooseFkResourceValidator("ZaakType", settings.ZTC_API_SPEC),
                 LooseFkIsImmutableValidator(),
                 PublishValidator(),
             ],
         },
         "zaakgeometrie": {
             "help_text": "Punt, lijn of (multi-)vlak geometrie-informatie, in GeoJSON."
         },
         "identificatie": {"validators": [IsImmutableValidator()]},
         "einddatum": {"read_only": True, "allow_null": True},
         "communicatiekanaal": {
             "validators": [
                 ResourceValidator(
                     "CommunicatieKanaal", settings.REFERENTIELIJSTEN_API_SPEC
                 )
             ]
         },
         "vertrouwelijkheidaanduiding": {
             "required": False,
             "help_text": _(
                 "Aanduiding van de mate waarin het zaakdossier van de "
                 "ZAAK voor de openbaarheid bestemd is. Optioneel - indien "
                 "geen waarde gekozen wordt, dan wordt de waarde van het "
                 "ZAAKTYPE overgenomen. Dit betekent dat de API _altijd_ een "
                 "waarde teruggeeft."
             ),
         },
         "selectielijstklasse": {
             "validators": [
                 ResourceValidator(
                     "Resultaat",
                     settings.REFERENTIELIJSTEN_API_SPEC,
                     get_auth=get_auth,
                 )
             ]
         },
         "hoofdzaak": {
             "lookup_field": "uuid",
             "queryset": Zaak.objects.all(),
             "validators": [NotSelfValidator(), HoofdzaakValidator()],
         },
         "laatste_betaaldatum": {"validators": [UntilNowValidator()]},
     }
     # Replace a default "unique together" constraint.
     validators = [
         UniekeIdentificatieValidator(),
         ZaakArchiveIOsArchivedValidator(),
     ]
Exemplo n.º 13
0
class BesluitInformatieObjectSerializer(serializers.HyperlinkedModelSerializer
                                        ):
    informatieobject = EnkelvoudigInformatieObjectField(
        validators=[
            LooseFkIsImmutableValidator(instance_path="canonical"),
            LooseFkResourceValidator("EnkelvoudigInformatieObject",
                                     settings.DRC_API_SPEC),
        ],
        max_length=1000,
        min_length=1,
        help_text=get_help_text("besluiten.BesluitInformatieObject",
                                "informatieobject"),
    )

    class Meta:
        model = BesluitInformatieObject
        fields = ("url", "informatieobject", "besluit")
        validators = [
            UniqueTogetherValidator(
                queryset=BesluitInformatieObject.objects.all(),
                fields=["besluit", "informatieobject"],
            ),
            ObjecttypeInformatieobjecttypeRelationValidator(
                "besluit", "besluittype"),
        ]
        extra_kwargs = {
            "url": {
                "lookup_field": "uuid"
            },
            "besluit": {
                "lookup_field": "uuid",
                "validators": [IsImmutableValidator()]
            },
        }

    def create(self, validated_data):
        with transaction.atomic():
            bio = super().create(validated_data)

        # local FK - nothing to do -> our signals create the OIO
        if bio.informatieobject.pk:
            return bio

        # we know that we got valid URLs in the initial data
        io_url = self.initial_data["informatieobject"]
        besluit_url = self.initial_data["besluit"]

        # manual transaction management - documents API checks that the BIO
        # exists, so that transaction must be committed.
        # If it fails in any other way, we need to handle that by rolling back
        # the BIO creation.
        try:
            response = create_remote_oio(io_url, besluit_url, "besluit")
        except Exception as exception:
            bio.delete()
            raise serializers.ValidationError(
                _("Could not create remote relation: {exception}"),
                params={"exception": exception},
            )
        else:
            bio._objectinformatieobject_url = response["url"]
            bio.save()
        return bio
Exemplo n.º 14
0
class ZaakInformatieObjectSerializer(serializers.HyperlinkedModelSerializer):
    aard_relatie_weergave = serializers.ChoiceField(
        source="get_aard_relatie_display",
        read_only=True,
        choices=[(force_text(value), key)
                 for key, value in RelatieAarden.choices],
    )
    informatieobject = EnkelvoudigInformatieObjectField(
        validators=[
            LooseFkIsImmutableValidator(instance_path="canonical"),
            LooseFkResourceValidator("EnkelvoudigInformatieObject",
                                     settings.DRC_API_SPEC),
        ],
        max_length=1000,
        min_length=1,
        help_text=get_help_text("zaken.ZaakInformatieObject",
                                "informatieobject"),
    )

    class Meta:
        model = ZaakInformatieObject
        fields = (
            "url",
            "uuid",
            "informatieobject",
            "zaak",
            "aard_relatie_weergave",
            "titel",
            "beschrijving",
            "registratiedatum",
        )
        validators = [
            UniqueTogetherValidator(
                queryset=ZaakInformatieObject.objects.all(),
                fields=["zaak", "informatieobject"],
            ),
            ObjecttypeInformatieobjecttypeRelationValidator(),
        ]
        extra_kwargs = {
            "url": {
                "lookup_field": "uuid"
            },
            "uuid": {
                "read_only": True
            },
            "zaak": {
                "lookup_field": "uuid",
                "validators": [IsImmutableValidator()]
            },
        }

    def create(self, validated_data):
        with transaction.atomic():
            zio = super().create(validated_data)

        # we now expect to be in autocommit mode, i.e. - the transaction before has been
        # committed to the database as well. This makes it so that the remote DRC can
        # actually retrieve this ZIO we just created, to validate that we did indeed
        # create the relation information on our end.
        # XXX: would be nice to change the standard to rely on notifications for this
        # sync-machinery

        # Can't actually make the assertion because tests run in atomic transactions
        # assert (
        #     transaction.get_autocommit()
        # ), "Expected to be in autocommit mode at this point"

        # local FK or CMIS - nothing to do -> our signals create the OIO
        if zio.informatieobject.pk or settings.CMIS_ENABLED:
            return zio

        # we know that we got valid URLs in the initial data
        io_url = self.initial_data["informatieobject"]
        zaak_url = self.initial_data["zaak"]

        # manual transaction management - documents API checks that the ZIO
        # exists, so that transaction must be committed.
        # If it fails in any other way, we need to handle that by rolling back
        # the ZIO creation.
        try:
            response = create_remote_oio(io_url, zaak_url)
        except Exception as exception:
            zio.delete()
            raise serializers.ValidationError(
                {
                    "informatieobject":
                    _("Could not create remote relation: {exception}").format(
                        exception=exception)
                },
                code="pending-relations",
            )
        else:
            zio._objectinformatieobject_url = response["url"]
            zio.save()

        return zio

    def run_validators(self, value):
        """
        Add read_only fields with defaults to value before running validators.
        """
        # In the case CMIS is enabled, we need to filter on the URL and not the canonical object
        if value.get("informatieobject") is not None and settings.CMIS_ENABLED:
            value["informatieobject"] = self.initial_data.get(
                "informatieobject")

        return super().run_validators(value)