Skip to content

Commit

Permalink
Merge pull request #137 from open-zaak/feature/put-patch-operations
Browse files Browse the repository at this point in the history
Feature/put patch operations
  • Loading branch information
joeribekker committed Oct 29, 2019
2 parents a5131e4 + 7f68921 commit 252cc8f
Show file tree
Hide file tree
Showing 46 changed files with 9,556 additions and 2,064 deletions.
2 changes: 1 addition & 1 deletion src/openzaak/components/besluiten/api/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __call__(self, attrs):
besluit = attrs.get("besluit")

io = informatieobject.enkelvoudiginformatieobject_set.first()
if not besluit.besluittype.informatieobjecttypes.filter(
if not besluit.besluittype.informatieobjecttypen.filter(
id=io.informatieobjecttype_id, concept=False
).exists():
raise serializers.ValidationError(self.message, code=self.code)
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_create_besluitinformatieobject_audittrail(self):
informatieobjecttype__concept=False
)
io_url = reverse(io)
besluit.besluittype.informatieobjecttypes.add(io.informatieobjecttype)
besluit.besluittype.informatieobjecttypen.add(io.informatieobjecttype)
url = reverse(BesluitInformatieObject)

response = self.client.post(
Expand Down
4 changes: 2 additions & 2 deletions src/openzaak/components/besluiten/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ def test_create_bio_limited_to_authorized_besluiten(self):
besluit1 = BesluitFactory.create(besluittype=self.besluittype)
besluit2 = BesluitFactory.create()

self.besluittype.informatieobjecttypes.add(
self.besluittype.informatieobjecttypen.add(
informatieobject.informatieobjecttype
)
besluit2.besluittype.informatieobjecttypes.add(
besluit2.besluittype.informatieobjecttypen.add(
informatieobject.informatieobjecttype
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_us162_voeg_besluit_toe_aan_zaak(self):
informatieobjecttype__concept=False
)
io_url = reverse(io)
besluittype.informatieobjecttypes.add(io.informatieobjecttype)
besluittype.informatieobjecttypen.add(io.informatieobjecttype)

with self.subTest(part="besluit_create"):
url = get_operation_url("besluit_create")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_create(self):
io = EnkelvoudigInformatieObjectFactory.create(
informatieobjecttype__concept=False
)
besluit.besluittype.informatieobjecttypes.add(io.informatieobjecttype)
besluit.besluittype.informatieobjecttypen.add(io.informatieobjecttype)
besluit_url = reverse(besluit)
io_url = reverse(io)
content = {
Expand Down
2 changes: 1 addition & 1 deletion src/openzaak/components/besluiten/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_besluittype_response(catalogus: str, besluittype: str) -> dict:
"publicatietekst": "",
"publicatietermijn": None,
"toelichting": "",
"informatieobjecttypes": [],
"informatieobjecttypen": [],
"beginGeldigheid": "2018-01-01",
"eindeGeldigheid": None,
"concept": False,
Expand Down
4 changes: 2 additions & 2 deletions src/openzaak/components/catalogi/admin/besluittype.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class BesluitTypeAdmin(GeldigheidAdminMixin, ConceptAdminMixin, admin.ModelAdmin
{
"fields": (
"catalogus",
"informatieobjecttypes",
"informatieobjecttypen",
# 'resultaattypes',
"zaaktypes",
)
},
),
)
filter_horizontal = ("informatieobjecttypes", "zaaktypes") # , 'resultaattypes'
filter_horizontal = ("informatieobjecttypen", "zaaktypes") # , 'resultaattypes'
6 changes: 3 additions & 3 deletions src/openzaak/components/catalogi/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class BesluitTypeFilter(FilterSet):
"ZAAKTYPE met ZAAKen die relevant kunnen zijn voor dit BESLUITTYPE"
),
)
informatieobjecttypes = filters.CharFilter(
field_name="informatieobjecttypes",
informatieobjecttypen = filters.CharFilter(
field_name="informatieobjecttypen",
method=m2m_filter,
help_text=_(
"Het INFORMATIEOBJECTTYPE van informatieobjecten waarin besluiten van dit "
Expand All @@ -150,7 +150,7 @@ class BesluitTypeFilter(FilterSet):

class Meta:
model = BesluitType
fields = ("catalogus", "zaaktypes", "informatieobjecttypes", "status")
fields = ("catalogus", "zaaktypes", "informatieobjecttypen", "status")


class CatalogusFilter(FilterSet):
Expand Down
18 changes: 13 additions & 5 deletions src/openzaak/components/catalogi/api/serializers/besluittype.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
from vng_api_common.utils import get_help_text

from ...models import BesluitType, InformatieObjectType, ZaakType
from ..validators import RelationCatalogValidator
from ..validators import (
ConceptUpdateValidator,
M2MConceptCreateValidator,
M2MConceptUpdateValidator,
RelationCatalogValidator,
)


class BesluitTypeSerializer(serializers.HyperlinkedModelSerializer):
informatieobjecttypes = serializers.HyperlinkedRelatedField(
informatieobjecttypen = serializers.HyperlinkedRelatedField(
view_name="informatieobjecttype-detail",
many=True,
lookup_field="uuid",
queryset=InformatieObjectType.objects.all(),
help_text=get_help_text("catalogi.BesluitType", "informatieobjecttypes"),
help_text=get_help_text("catalogi.BesluitType", "informatieobjecttypen"),
)

zaaktypes = serializers.HyperlinkedRelatedField(
Expand Down Expand Up @@ -44,7 +49,7 @@ class Meta:
"publicatietekst",
"publicatietermijn",
"toelichting",
"informatieobjecttypes",
"informatieobjecttypen",
"begin_geldigheid",
"einde_geldigheid",
"concept",
Expand All @@ -53,6 +58,9 @@ class Meta:
UniqueTogetherValidator(
queryset=BesluitType.objects.all(), fields=["catalogus", "omschrijving"]
),
RelationCatalogValidator("informatieobjecttypes"),
RelationCatalogValidator("informatieobjecttypen"),
RelationCatalogValidator("zaaktypes"),
ConceptUpdateValidator(),
M2MConceptCreateValidator(["zaaktypes", "informatieobjecttypen"]),
M2MConceptUpdateValidator(["zaaktypes", "informatieobjecttypen"]),
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from ...constants import FormaatChoices
from ...models import Eigenschap, EigenschapSpecificatie
from ..validators import ZaakTypeConceptValidator


class EigenschapSpecificatieSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -30,3 +31,4 @@ class Meta:
"naam": {"source": "eigenschapnaam"},
"zaaktype": {"lookup_field": "uuid"},
}
validators = [ZaakTypeConceptValidator()]
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
from vng_api_common.serializers import add_choice_values_help_text

from ...models import InformatieObjectType
from ..validators import (
ConceptUpdateValidator,
M2MConceptCreateValidator,
M2MConceptUpdateValidator,
)


class InformatieObjectTypeSerializer(serializers.HyperlinkedModelSerializer):
Expand All @@ -24,6 +29,11 @@ class Meta:
"einde_geldigheid",
"concept",
)
validators = [
ConceptUpdateValidator(),
M2MConceptCreateValidator(["besluittypen", "zaaktypes"]),
M2MConceptUpdateValidator(["besluittypen", "zaaktypes"]),
]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
26 changes: 26 additions & 0 deletions src/openzaak/components/catalogi/api/serializers/relatieklassen.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.utils.translation import ugettext_lazy as _

from rest_framework import serializers
from vng_api_common.serializers import add_choice_values_help_text

Expand Down Expand Up @@ -36,3 +38,27 @@ def __init__(self, *args, **kwargs):

value_display_mapping = add_choice_values_help_text(RichtingChoices)
self.fields["richting"].help_text += f"\n\n{value_display_mapping}"

def validate(self, attrs):
super().validate(attrs)

if self.instance:
zaaktype = attrs.get("zaaktype") or self.instance.zaaktype
informatieobjecttype = (
attrs.get("informatieobjecttype") or self.instance.informatieobjecttype
)

if not (zaaktype.concept and informatieobjecttype.concept):
message = _("Objects related to non-concept objects can't be updated")
raise serializers.ValidationError(message, code="non-concept-relation")
else:
zaaktype = attrs.get("zaaktype")
informatieobjecttype = attrs.get("informatieobjecttype")

if not (zaaktype.concept and informatieobjecttype.concept):
message = _(
"Creating relations between non-concept objects is forbidden"
)
raise serializers.ValidationError(message, code="non-concept-relation")

return attrs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
BrondatumArchiefprocedureValidator,
ProcestermijnAfleidingswijzeValidator,
ProcesTypeValidator,
ZaakTypeConceptValidator,
)


Expand Down Expand Up @@ -100,6 +101,7 @@ class Meta:
ProcesTypeValidator("selectielijstklasse"),
ProcestermijnAfleidingswijzeValidator("selectielijstklasse"),
BrondatumArchiefprocedureValidator(),
ZaakTypeConceptValidator(),
]

def __init__(self, *args, **kwargs):
Expand Down
2 changes: 2 additions & 0 deletions src/openzaak/components/catalogi/api/serializers/roltype.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from vng_api_common.serializers import add_choice_values_help_text

from ...models import RolType
from ..validators import ZaakTypeConceptValidator


class RolTypeSerializer(NestedCreateMixin, serializers.HyperlinkedModelSerializer):
Expand All @@ -14,6 +15,7 @@ class Meta:
"url": {"lookup_field": "uuid"},
"zaaktype": {"lookup_field": "uuid"},
}
validators = [ZaakTypeConceptValidator()]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from rest_framework import serializers

from ...models import StatusType
from ..validators import ZaakTypeConceptValidator


class StatusTypeSerializer(serializers.HyperlinkedModelSerializer):
Expand Down Expand Up @@ -34,3 +35,4 @@ class Meta:
"volgnummer": {"source": "statustypevolgnummer"},
"zaaktype": {"lookup_field": "uuid"},
}
validators = [ZaakTypeConceptValidator()]
22 changes: 16 additions & 6 deletions src/openzaak/components/catalogi/api/serializers/zaaktype.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from django.utils.translation import ugettext_lazy as _

from drf_writable_nested import NestedCreateMixin
from drf_writable_nested import NestedCreateMixin, NestedUpdateMixin
from rest_framework.serializers import (
HyperlinkedModelSerializer,
HyperlinkedRelatedField,
Expand All @@ -17,7 +17,13 @@

from ...constants import AardRelatieChoices, RichtingChoices
from ...models import BesluitType, ZaakType, ZaakTypenRelatie
from ..validators import RelationCatalogValidator, ZaaktypeGeldigheidValidator
from ..validators import (
ConceptUpdateValidator,
M2MConceptCreateValidator,
M2MConceptUpdateValidator,
RelationCatalogValidator,
ZaaktypeGeldigheidValidator,
)


class ReferentieProcesSerializer(GegevensGroepSerializer):
Expand All @@ -40,7 +46,10 @@ def __init__(self, *args, **kwargs):


class ZaakTypeSerializer(
NestedGegevensGroepMixin, NestedCreateMixin, HyperlinkedModelSerializer
NestedGegevensGroepMixin,
NestedCreateMixin,
NestedUpdateMixin,
HyperlinkedModelSerializer,
):
referentieproces = ReferentieProcesSerializer(
required=True,
Expand All @@ -56,7 +65,6 @@ class ZaakTypeSerializer(
informatieobjecttypen = HyperlinkedRelatedField(
many=True,
read_only=True,
source="heeft_relevant_informatieobjecttype",
view_name="informatieobjecttype-detail",
lookup_field="uuid",
help_text=_(
Expand Down Expand Up @@ -109,7 +117,6 @@ class ZaakTypeSerializer(
besluittypen = HyperlinkedRelatedField(
many=True,
label=_("heeft relevante besluittypen"),
source="besluittype_set",
view_name="besluittype-detail",
lookup_field="uuid",
queryset=BesluitType.objects.all(),
Expand Down Expand Up @@ -178,7 +185,10 @@ class Meta:

validators = [
ZaaktypeGeldigheidValidator(),
RelationCatalogValidator("besluittype_set"),
RelationCatalogValidator("besluittypen"),
ConceptUpdateValidator(),
M2MConceptCreateValidator(["besluittypen", "informatieobjecttypen"]),
M2MConceptUpdateValidator(["besluittypen", "informatieobjecttypen"]),
]

def __init__(self, *args, **kwargs):
Expand Down

0 comments on commit 252cc8f

Please sign in to comment.