コード例 #1
0
ファイル: utils.py プロジェクト: tiltshiftnl/open-zaak
def delete_remote_zaakbesluit(zaakbesluit_url: str) -> None:
    client = Service.get_client(zaakbesluit_url)
    if client is None:
        raise UnknownService(
            f"{zaakbesluit_url} API should be added to Service model")

    client.delete("zaakbesluit", zaakbesluit_url)
コード例 #2
0
ファイル: viewsets.py プロジェクト: open-zaak/open-zaak
    def perform_destroy(self, instance: Zaak):
        if instance.besluit_set.exists():
            raise ValidationError(
                {
                    api_settings.NON_FIELD_ERRORS_KEY:
                    _("All related Besluit objects should be destroyed before destroying the zaak"
                      )
                },
                code="pending-besluit-relation",
            )

        # check if we need to delete any remote OIOs
        autocommit = transaction.get_autocommit()
        assert autocommit is False, "Expected to be in a transaction.atomic block"
        # evaluate the queryset, because the transaction will delete the records with
        # a cascade
        oio_urls = instance.zaakinformatieobject_set.filter(
            _informatieobject__isnull=True).values_list(
                "_objectinformatieobject_url", flat=True)
        delete_params = [(url, Service.get_client(url)) for url in oio_urls]

        def _delete_oios():
            for url, client in delete_params:
                client.delete("objectinformatieobject", url=url)

        transaction.on_commit(_delete_oios)

        super().perform_destroy(instance)
コード例 #3
0
 def get_drc_client(self, document_url: str) -> Service:
     try:
         return self.get_client(APITypes.drc)
     except NoService:
         client = Service.get_client(document_url)
         client._log.task = self.task
         return client
コード例 #4
0
ファイル: api.py プロジェクト: PaulWagener/open-zaak
def create_remote_oio(io_url: str, object_url: str, object_type: str = "zaak") -> dict:
    if settings.CMIS_ENABLED:
        if object_type == "zaak":
            oio = ObjectInformatieObject.objects.create(
                informatieobject=io_url, zaak=object_url, object_type=object_type
            )
        elif object_type == "besluit":
            oio = ObjectInformatieObject.objects.create(
                informatieobject=io_url, besluit=object_url, object_type=object_type
            )

        response = {"url": oio.get_url()}
    else:
        client = Service.get_client(io_url)
        if client is None:
            raise UnknownService(f"{io_url} API should be added to Service model")

        body = {
            "informatieobject": io_url,
            "object": object_url,
            "objectType": object_type,
        }

        response = client.create("objectinformatieobject", data=body)
    return response
コード例 #5
0
    def clean(self):
        super().clean()

        app = self.cleaned_data.get("autorisaties_application")
        label = self.cleaned_data.get("label")
        app_id = self.cleaned_data.get("app_id")

        # the other fields become required fields if there's no application specified
        # that we can derive the values from
        if not app:
            for field in ["label", "app_id"]:
                value = self.cleaned_data.get(field)
                if not value:
                    form_field = self.fields[field]
                    self.add_error(
                        field,
                        forms.ValidationError(
                            form_field.error_messages["required"],
                            code="required"),
                    )

        else:
            ac_client = Service.get_client(app)
            application = ac_client.retrieve("applicatie", url=app)
            if not label:
                self.cleaned_data["label"] = application["label"]
            if not app_id:
                self.cleaned_data["app_id"] = application["url"]

        return self.cleaned_data
コード例 #6
0
ファイル: utils.py プロジェクト: ConductionNL/open-zaak
def create_remote_oio(io_url: str, object_url: str, object_type: str = "zaak") -> dict:
    client = Service.get_client(io_url)
    if client is None:
        raise UnknownService(f"{io_url} API should be added to Service model")

    body = {"informatieobject": io_url, "object": object_url, "objectType": object_type}

    response = client.create("objectinformatieobject", data=body)
    return response
コード例 #7
0
ファイル: client.py プロジェクト: tiltshiftnl/open-zaak
def fetch_object(resource: str, url: str) -> dict:
    """
    Fetch a remote object by URL.
    """
    client = Service.get_client(url)
    if not client:
        raise UnknownService(f"{url} API should be added to Service model")
    obj = client.retrieve(resource, url=url)
    return obj
コード例 #8
0
 def client_from_url(self, url) -> ZGWClient:
     if url in self._clients:
         return self._clients[url]
     client = Service.get_client(url)
     if not client:
         raise ClientError(
             f"a ZGW service must be configured first for url '{url}'")
     self._clients[url] = client
     return client
コード例 #9
0
ファイル: utils.py プロジェクト: ConductionNL/open-zaak
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
コード例 #10
0
def check_objecttype(object_type, version, data):
    if not data:
        return

    client = Service.get_client(object_type)
    objecttype_version_url = f"{object_type}/versions/{version}"

    try:
        response = client.retrieve("objectversion", url=objecttype_version_url)
    except ClientError as exc:
        raise ValidationError(exc.args[0]) from exc

    try:
        schema = response["jsonSchema"]
    except KeyError:
        msg = f"{objecttype_version_url} does not appear to be a valid objecttype."
        raise ValidationError(msg)

    # TODO: Set warning header if objecttype is not published.

    try:
        jsonschema.validate(data, schema)
    except jsonschema.exceptions.ValidationError as exc:
        raise ValidationError(exc.args[0]) from exc
コード例 #11
0
ファイル: utils.py プロジェクト: ConductionNL/open-zaak
def delete_remote_oio(oio_url: str) -> None:
    client = Service.get_client(oio_url)
    if client is None:
        raise UnknownService(f"{oio_url} API should be added to Service model")

    client.delete("objectinformatieobject", oio_url)
コード例 #12
0
ファイル: auth.py プロジェクト: tiltshiftnl/open-zaak
def get_client(url: str) -> Optional[ZGWClient]:
    client = Service.get_client(url)
    return client