Skip to content

Commit

Permalink
Merge pull request #1467 from open-zaak/issue/1441-eio-admin-without-…
Browse files Browse the repository at this point in the history
…iotype

fix 500 when saving document admin with empty iotype
  • Loading branch information
annashamray committed Sep 11, 2023
2 parents 32b4438 + 4b081b6 commit 36e4a86
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/openzaak/components/documenten/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,25 @@ def get_viewset(self, request):
return None


class EnkelvoudigInformatieObjectForm(forms.ModelForm):
class Meta:
model = EnkelvoudigInformatieObject
fields = "__all__"

def clean(self):
cleaned_data = super().clean()

if not cleaned_data.get("_informatieobjecttype") and not cleaned_data.get(
"_informatieobjecttype_base_url"
):
raise forms.ValidationError(
"Je moet een informatieobjecttype opgeven: "
"selecteer een informatieobjecttype uit de catalogus of vul een externe URL in."
)

return cleaned_data


@admin.register(EnkelvoudigInformatieObject)
class EnkelvoudigInformatieObjectAdmin(
AuditTrailAdminMixin,
Expand Down Expand Up @@ -233,6 +252,7 @@ class EnkelvoudigInformatieObjectAdmin(
private_media_fields = ("inhoud",)
private_media_view_class = PrivateMediaView
private_media_file_widget = PrivateFileWidget
form = EnkelvoudigInformatieObjectForm

fieldsets = (
(
Expand Down
25 changes: 25 additions & 0 deletions src/openzaak/components/documenten/tests/admin/test_eio.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,28 @@ def test_create_informatieobject_save(self):

response = form.submit(name="_continue")
self.assertEqual(response.status_code, 200)

def test_create_without_iotype(self):
"""
regression test for https://github.com/open-zaak/open-zaak/issues/1441
"""
canonical = EnkelvoudigInformatieObjectCanonicalFactory.create(
latest_version=None
)
add_url = reverse("admin:documenten_enkelvoudiginformatieobject_add")

response = self.app.get(add_url)
form = response.form

form["canonical"] = canonical.pk
form["bronorganisatie"] = "000000000"
form["creatiedatum"] = "2010-01-01"
form["titel"] = "test"
form["auteur"] = "test"
form["taal"] = "nld"
form["inhoud"] = Upload("stuff.txt", b"some content")

response = form.submit(name="_save")

self.assertEqual(response.status_code, 200)
self.assertIn("Je moet een informatieobjecttype opgeven", response.text)

0 comments on commit 36e4a86

Please sign in to comment.