コード例 #1
0
def is_local_url(autorisatie):
    loader = BaseLoader()
    if autorisatie.component == ComponentTypes.zrc:
        return loader.is_local_url(autorisatie.zaaktype)
    elif autorisatie.component == ComponentTypes.drc:
        return loader.is_local_url(autorisatie.informatieobjecttype)
    elif autorisatie.component == ComponentTypes.brc:
        return loader.is_local_url(autorisatie.besluittype)
    return True
コード例 #2
0
# SPDX-License-Identifier: EUPL-1.2
# Copyright (C) 2019 - 2020 Dimpact
from typing import List
from urllib.parse import urlparse

from django.apps import apps
from django.core.exceptions import ObjectDoesNotExist
from django.core.management import BaseCommand
from django.utils.translation import ugettext_lazy as _

from django_loose_fk.loaders import BaseLoader
from vng_api_common.utils import get_resource_for_path

Autorisatie = apps.get_model("authorizations", "Autorisatie")
is_local_url = BaseLoader().is_local_url


def get_out_of_sync_autorisaties(field: str) -> List[Autorisatie]:
    to_delete = []
    for autorisatie in Autorisatie.objects.exclude(**{field: ""}):
        value = getattr(autorisatie, field)
        if not is_local_url(value):
            continue

        parsed = urlparse(value)

        try:
            get_resource_for_path(parsed.path)
        except ObjectDoesNotExist:
            to_delete.append(autorisatie)
    return to_delete
コード例 #3
0
    def _get_extra(self, obj) -> str:
        """
        Show the context-dependent extra fields.

        An :class:`Autorisatie` requires extra attributes depending on the
        component that it's relevant for.

        .. note:: using get_resource_for_path spawns too many queries, since
            the viewsets have prefetch_related calls.
        """
        loader = BaseLoader()
        if obj.component == ComponentTypes.zrc:
            template = (
                "<strong>Zaaktype</strong>: "
                '<a href="{admin_url}" target="_blank" rel="noopener">{zt_repr}</a>'
                "<br>"
                "<strong>Maximale vertrouwelijkheidaanduiding</strong>: "
                "{va}")
            if loader.is_local_url(obj.zaaktype):
                zaaktype = get_related_object(obj)
                admin_url = reverse("admin:catalogi_zaaktype_change",
                                    kwargs={"object_id": zaaktype.pk})
                zt_repr = str(zaaktype)
            else:
                admin_url = obj.zaaktype
                zt_repr = f"{obj.zaaktype} (EXTERN)"

            return format_html(
                template,
                admin_url=admin_url,
                zt_repr=zt_repr,
                va=obj.get_max_vertrouwelijkheidaanduiding_display(),
            )

        if obj.component == ComponentTypes.drc:
            template = (
                "<strong>Informatieobjecttype</strong>: "
                '<a href="{admin_url}" target="_blank" rel="noopener">{iot_repr}</a>'
                "<br>"
                "<strong>Maximale vertrouwelijkheidaanduiding</strong>: "
                "{va}")
            if loader.is_local_url(obj.informatieobjecttype):
                informatieobjecttype = get_related_object(obj)
                admin_url = reverse(
                    "admin:catalogi_informatieobjecttype_change",
                    kwargs={"object_id": informatieobjecttype.pk},
                )
                iot_repr = str(informatieobjecttype)
            else:
                admin_url = obj.informatieobjecttype
                iot_repr = f"{obj.informatieobjecttype} (EXTERN)"

            return format_html(
                template,
                admin_url=admin_url,
                iot_repr=iot_repr,
                va=obj.get_max_vertrouwelijkheidaanduiding_display(),
            )

        if obj.component == ComponentTypes.brc:
            template = (
                "<strong>Besluittype</strong>: "
                '<a href="{admin_url}" target="_blank" rel="noopener">{bt_repr}</a>'
            )
            if loader.is_local_url(obj.besluittype):
                besluittype = get_related_object(obj)
                admin_url = reverse(
                    "admin:catalogi_besluittype_change",
                    kwargs={"object_id": besluittype.pk},
                )
                bt_repr = str(besluittype)
            else:
                admin_url = obj.besluittype
                bt_repr = f"{obj.besluittype} (EXTERN)"

            return format_html(
                template,
                admin_url=admin_url,
                bt_repr=bt_repr,
            )

        return ""