Пример #1
0
    def __call__(self, attrs):
        code = self.code.format(self.objecttype_field)
        message = self.message.format(self.objecttype_field, self.object_field)

        informatieobject = attrs.get("informatieobject")
        object = attrs.get(self.object_field)
        if not informatieobject or not object:
            return

        objecttype = getattr(object, self.objecttype_field)

        if isinstance(informatieobject, ProxyMixin) and settings.CMIS_ENABLED:
            io_uuid = get_uuid_from_path(informatieobject._initial_data["url"])
            io = EnkelvoudigInformatieObject.objects.get(uuid=io_uuid)
            io_type = io.informatieobjecttype
        elif isinstance(informatieobject, EnkelvoudigInformatieObject):
            io_type = informatieobject.informatieobjecttype
        elif isinstance(informatieobject, str):
            io_uuid = get_uuid_from_path(informatieobject)
            io = EnkelvoudigInformatieObject.objects.get(uuid=io_uuid)
            io_type = io.informatieobjecttype
        else:
            io_type = informatieobject.latest_version.informatieobjecttype

        # zaaktype/besluittype and informatieobjecttype should be both internal or external
        if bool(objecttype.pk) != bool(io_type.pk):
            msg_diff = _(
                "Het informatieobjecttype en het {objecttype_field} van de/het "
                "{object_field} moeten tot dezelfde catalogus behoren."
            ).format(objecttype_field=self.objecttype_field,
                     object_field=self.object_field)
            raise serializers.ValidationError(msg_diff, code=code)

        # local zaaktype/besluittype
        if objecttype.pk:
            if not objecttype.informatieobjecttypen.filter(
                    uuid=io_type.uuid).exists():
                raise serializers.ValidationError(message, code=code)

        # external zaaktype/besluittype - workaround since loose-fk field doesn't support m2m relations
        else:
            objecttype_url = objecttype._loose_fk_data["url"]
            iotype_url = io_type._loose_fk_data["url"]
            objecttype_data = AuthorizedRequestsLoader.fetch_object(
                objecttype_url, do_underscoreize=False)
            if iotype_url not in objecttype_data.get("informatieobjecttypen",
                                                     []):
                raise serializers.ValidationError(message, code=code)
Пример #2
0
def move_objecttypes_to_model(apps, _):
    ObjectType = apps.get_model("core", "ObjectType")
    Object = apps.get_model("core", "Object")
    Service = apps.get_model("zgw_consumers", "Service")

    for object in Object.objects.all():
        service = get_service(Service, object.object_type)
        if not service:
            logger.warning(
                "object %s can't be migrated since it has invalid objecttype %s",
                object,
                object.object_type,
            )
            continue
        try:
            uuid = get_uuid_from_path(object.object_type)
        except ValueError:
            logger.warning(
                "object %s can't be migrated since it has invalid objecttype %s",
                object,
                object.object_type,
            )
            continue

        object_type, created = ObjectType.objects.get_or_create(
            service=service, uuid=uuid)
        object.object_type_fk = object_type
        object.save()
Пример #3
0
def create_remote_zaakbesluit(besluit_url: str, zaak_url: str) -> dict:
    client = Service.get_client(zaak_url)
    if client is None:
        raise UnknownService(f"{zaak_url} API should be added to Service model")

    zaak_uuid = get_uuid_from_path(zaak_url)
    body = {"besluit": besluit_url}

    response = client.create("zaakbesluit", data=body, zaak_uuid=zaak_uuid)

    return response
    def test_audittrail_resource_weergave(self):
        zaak_response = self._create_zaak()

        zaak_uuid = get_uuid_from_path(zaak_response['url'])
        zaak_unique_representation = Zaak.objects.get(uuid=zaak_uuid).unique_representation()

        audittrail = AuditTrail.objects.filter(hoofd_object=zaak_response['url']).get()

        # Verify that the resource weergave stored in the AuditTrail matches
        # the unique representation as defined in the Zaak model
        self.assertIn(audittrail.resource_weergave, zaak_unique_representation)
Пример #5
0
    def test_audittrail_resource_weergave(self):
        eio_response = self._create_enkelvoudiginformatieobject()

        eio_uuid = get_uuid_from_path(eio_response["url"])
        eio_unique_representation = EnkelvoudigInformatieObject.objects.get(
            uuid=eio_uuid).unique_representation()

        audittrail = AuditTrail.objects.filter(
            hoofd_object=eio_response["url"]).get()

        # Verify that the resource weergave stored in the AuditTrail matches
        # the unique representation as defined in the Zaak model
        self.assertIn(audittrail.resource_weergave, eio_unique_representation)
Пример #6
0
    def test_audittrail_resource_weergave(self):
        besluit_response = self._create_besluit()

        besluit_uuid = get_uuid_from_path(besluit_response["url"])
        besluit_unique_representation = Besluit.objects.get(
            uuid=besluit_uuid).unique_representation()

        audittrail = AuditTrail.objects.filter(
            hoofd_object=besluit_response["url"]).get()

        # Verify that the resource weergave stored in the AuditTrail matches
        # the unique representation as defined in the besluit model
        self.assertIn(audittrail.resource_weergave,
                      besluit_unique_representation)
Пример #7
0
 def get_by_url(self, url):
     service = Service.get_service(url)
     uuid = get_uuid_from_path(url)
     return self.get(service=service, uuid=uuid)