Skip to content

Commit

Permalink
Merge pull request #1469 from open-zaak/feature/1419-zaakobjecttype
Browse files Browse the repository at this point in the history
new ZaakObjectType endpoints
  • Loading branch information
annashamray committed Sep 28, 2023
2 parents e40dbbc + 116e7ac commit ec40713
Show file tree
Hide file tree
Showing 25 changed files with 1,976 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/openzaak/components/catalogi/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
from .resultaattype import * # noqa
from .roltype import * # noqa
from .statustype import * # noqa
from .zaakobjecttype import * # noqa
from .zaaktypen import * # noqa
3 changes: 2 additions & 1 deletion src/openzaak/components/catalogi/admin/resultaattype.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ class ResultaatTypeAdmin(
)
},
),
(_("Relaties"), {"fields": ("zaakobjecttypen",)}),
)
raw_id_fields = ("zaaktype",)
raw_id_fields = ("zaaktype", "zaakobjecttypen")
readonly_fields = ("get_zaaktype_procestype", "omschrijving_generiek")

def _get_zaaktype(
Expand Down
4 changes: 2 additions & 2 deletions src/openzaak/components/catalogi/admin/statustype.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class StatusTypeAdmin(
)
},
),
(_("Relaties"), {"fields": ("zaaktype",)}),
(_("Relaties"), {"fields": ("zaaktype", "zaakobjecttype")}),
)
raw_id_fields = ("zaaktype",)
raw_id_fields = ("zaaktype", "zaakobjecttype")
readonly_fields = ("uuid",)
33 changes: 33 additions & 0 deletions src/openzaak/components/catalogi/admin/zaakobjecttype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SPDX-License-Identifier: EUPL-1.2
# Copyright (C) 2023 Dimpact
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

from openzaak.utils.admin import UUIDAdminMixin

from ..models import ZaakObjectType
from .mixins import ReadOnlyPublishedZaaktypeMixin


@admin.register(ZaakObjectType)
class ZaakObjectTypeAdmin(
ReadOnlyPublishedZaaktypeMixin, UUIDAdminMixin, admin.ModelAdmin,
):
# List
list_display = (
"zaaktype",
"ander_objecttype",
)
list_filter = ("zaaktype", "ander_objecttype")
search_fields = ("uuid", "relatie_omschrijving")
ordering = ("zaaktype", "relatie_omschrijving")

# Details
fieldsets = (
(
_("Algemeen"),
{"fields": ("ander_objecttype", "objecttype", "relatie_omschrijving",)},
),
(_("Relaties"), {"fields": ("zaaktype",)}),
)
raw_id_fields = ("zaaktype",)
18 changes: 17 additions & 1 deletion src/openzaak/components/catalogi/admin/zaaktypen.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
ResultaatType,
RolType,
StatusType,
ZaakObjectType,
ZaakType,
ZaakTypenRelatie,
)
Expand All @@ -46,6 +47,7 @@
from .resultaattype import ResultaatTypeAdmin
from .roltype import RolTypeAdmin
from .statustype import StatusTypeAdmin
from .zaakobjecttype import ZaakObjectTypeAdmin

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -107,6 +109,12 @@ class ZaakTypenRelatieInline(EditInlineAdminMixin, admin.TabularInline):
fields = ZaakTypenRelatieAdmin.list_display


class ZaakObjectTypeInline(EditInlineAdminMixin, admin.TabularInline):
model = ZaakObjectType
fk_name = "zaaktype"
fields = ZaakObjectTypeAdmin.list_display


@admin.register(ZaakType)
class ZaakTypeAdmin(
ReadOnlyPublishedMixin,
Expand Down Expand Up @@ -232,6 +240,7 @@ class ZaakTypeAdmin(
RolTypeInline,
EigenschapInline,
ResultaatTypeInline,
ZaakObjectTypeInline,
)
change_form_template = "admin/catalogi/change_form_zaaktype.html"
exclude_copy_relation = ("zaak",)
Expand All @@ -255,7 +264,13 @@ def get_related_objects(self, obj):
)

# Resources with foreign keys to ZaakType
fields = ["ResultaatType", "RolType", "StatusType", "Eigenschap"]
fields = [
"ResultaatType",
"RolType",
"StatusType",
"Eigenschap",
"ZaakObjectType",
]
for field in fields:
model = apps.get_model("catalogi", field)
resources[field] = list(
Expand Down Expand Up @@ -297,6 +312,7 @@ def get_object_actions(self, obj):
link_to_related_objects(Eigenschap, obj),
link_to_related_objects(ResultaatType, obj),
link_to_related_objects(ZaakTypenRelatie, obj),
link_to_related_objects(ZaakObjectType, obj),
)

def formfield_for_dbfield(self, db_field: Field, request: HttpRequest, **kwargs):
Expand Down
27 changes: 26 additions & 1 deletion src/openzaak/components/catalogi/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

from django_filters import rest_framework as filters
from djchoices import ChoiceItem, DjangoChoices
from vng_api_common.filters import URLModelChoiceFilter
from vng_api_common.filtersets import FilterSet
from vng_api_common.utils import get_resource_for_path
from vng_api_common.utils import get_help_text, get_resource_for_path

from ..models import (
BesluitType,
Expand All @@ -20,6 +21,7 @@
ResultaatType,
RolType,
StatusType,
ZaakObjectType,
ZaakType,
ZaakTypeInformatieObjectType,
)
Expand Down Expand Up @@ -199,3 +201,26 @@ class CatalogusFilter(FilterSet):
class Meta:
model = Catalogus
fields = {"domein": ["exact", "in"], "rsin": ["exact", "in"]}


class ZaakObjectTypeFilter(FilterSet):
catalogus = URLModelChoiceFilter(
field_name="zaaktype__catalogus",
queryset=Catalogus.objects.all(),
help_text=get_help_text("catalogi.ZaakType", "catalogus"),
)
zaaktype_identificatie = filters.CharFilter(
field_name="zaaktype__identificatie",
help_text=get_help_text("catalogi.ZaakType", "identificatie"),
)

class Meta:
model = ZaakObjectType
fields = (
"ander_objecttype",
"catalogus",
"objecttype",
"relatie_omschrijving",
"zaaktype",
"zaaktype_identificatie",
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
from .resultaattype import * # noqa
from .roltype import * # noqa
from .statustype import * # noqa
from .zaakobjecttype import * # noqa
from .zaaktype import * # noqa
60 changes: 60 additions & 0 deletions src/openzaak/components/catalogi/api/serializers/zaakobjecttype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# SPDX-License-Identifier: EUPL-1.2
# Copyright (C) 2019 - 2020 Dimpact
from django.utils.translation import gettext as _

from rest_framework import serializers
from rest_framework.serializers import HyperlinkedModelSerializer
from vng_api_common.utils import get_help_text

from ...models import ZaakObjectType
from ..validators import ZaakTypeConceptValidator


class ZaakObjectTypeSerializer(HyperlinkedModelSerializer):
zaaktype_identificatie = serializers.SlugRelatedField(
source="zaaktype",
read_only=True,
slug_field="identificatie",
help_text=_(
"Unieke identificatie van het ZAAKTYPE binnen de CATALOGUS waarin het ZAAKTYPE voorkomt."
),
)
catalogus = serializers.HyperlinkedRelatedField(
view_name="catalogus-detail",
source="zaaktype.catalogus",
read_only=True,
lookup_field="uuid",
help_text=get_help_text("catalogi.ZaakType", "catalogus"),
)

class Meta:
model = ZaakObjectType
fields = (
"url",
"ander_objecttype",
"objecttype",
"relatie_omschrijving",
"zaaktype",
"zaaktype_identificatie",
"resultaattypen",
"statustypen",
"catalogus",
)
extra_kwargs = {
"url": {"lookup_field": "uuid"},
"zaaktype": {"lookup_field": "uuid"},
"resultaattypen": {
"lookup_field": "uuid",
"read_only": True,
"many": True,
"help_text": _("URL-referenties naar de RESULTAATTYPEN."),
},
"statustypen": {
"lookup_field": "uuid",
"read_only": True,
"many": True,
"help_text": _("URL-referenties naar de STATUSTYPEN."),
},
"catalogus": {"lookup_field": "uuid"},
}
validators = [ZaakTypeConceptValidator()]
2 changes: 2 additions & 0 deletions src/openzaak/components/catalogi/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ResultaatTypeViewSet,
RolTypeViewSet,
StatusTypeViewSet,
ZaakObjectTypeViewSet,
ZaakTypeInformatieObjectTypeViewSet,
ZaakTypeViewSet,
)
Expand All @@ -30,6 +31,7 @@
router.register(r"besluittypen", BesluitTypeViewSet)
router.register(r"resultaattypen", ResultaatTypeViewSet)
router.register(r"zaaktype-informatieobjecttypen", ZaakTypeInformatieObjectTypeViewSet)
router.register(r"zaakobjecttypen", ZaakObjectTypeViewSet)


# set the path to schema file
Expand Down
1 change: 1 addition & 0 deletions src/openzaak/components/catalogi/api/viewsets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
from .resultaattype import * # noqa
from .roltype import * # noqa
from .statustype import * # noqa
from .zaakobjecttype import * # noqa
from .zaaktype import * # noqa
78 changes: 78 additions & 0 deletions src/openzaak/components/catalogi/api/viewsets/zaakobjecttype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# SPDX-License-Identifier: EUPL-1.2
# Copyright (C) 2023 Dimpact
from rest_framework import viewsets
from vng_api_common.caching import conditional_retrieve
from vng_api_common.viewsets import CheckQueryParamsMixin

from openzaak.utils.pagination import OptimizedPagination
from openzaak.utils.permissions import AuthRequired

from ...models import ZaakObjectType
from ..filters import ZaakObjectTypeFilter
from ..scopes import (
SCOPE_CATALOGI_FORCED_DELETE,
SCOPE_CATALOGI_FORCED_WRITE,
SCOPE_CATALOGI_READ,
SCOPE_CATALOGI_WRITE,
)
from ..serializers import ZaakObjectTypeSerializer
from .mixins import ZaakTypeConceptMixin


@conditional_retrieve()
class ZaakObjectTypeViewSet(
CheckQueryParamsMixin, ZaakTypeConceptMixin, viewsets.ModelViewSet
):
"""
Opvragen en bewerken van ZAAKOBJECTTYPEn.
create:
Maak een ZAAKOBJECTTYPE aan.
Maak een ZAAKOBJECTTYPE aan.
list:
Alle ZAAKOBJECTTYPEn opvragen.
Deze lijst kan gefilterd wordt met query-string parameters.
retrieve:
Een specifieke ZAAKOBJECTTYPE opvragen.
Een specifieke ZAAKOBJECTTYPE opvragen.
update:
Werk een ZAAKOBJECTTYPE in zijn geheel bij.
Werk een ZAAKOBJECTTYPE in zijn geheel bij.
partial_update:
Werk een ZAAKOBJECTTYPE deels bij.
Werk een ZAAKOBJECTTYPE deels bij.
destroy:
Verwijder een ZAAKOBJECTTYPE.
Verwijder een ZAAKOBJECTTYPE.
"""

queryset = (
ZaakObjectType.objects.select_related("zaaktype", "zaaktype__catalogus")
.prefetch_related("resultaattypen", "statustypen")
.order_by("-pk")
.all()
)
serializer_class = ZaakObjectTypeSerializer
filterset_class = ZaakObjectTypeFilter
lookup_field = "uuid"
pagination_class = OptimizedPagination
permission_classes = (AuthRequired,)
required_scopes = {
"list": SCOPE_CATALOGI_READ,
"retrieve": SCOPE_CATALOGI_READ,
"create": SCOPE_CATALOGI_WRITE | SCOPE_CATALOGI_FORCED_WRITE,
"update": SCOPE_CATALOGI_WRITE | SCOPE_CATALOGI_FORCED_WRITE,
"partial_update": SCOPE_CATALOGI_WRITE | SCOPE_CATALOGI_FORCED_WRITE,
"destroy": SCOPE_CATALOGI_WRITE | SCOPE_CATALOGI_FORCED_DELETE,
}

0 comments on commit ec40713

Please sign in to comment.