Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1308] Hide upload type from case document when only one type exists #570

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/open_inwoner/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ def __init__(self, case, **kwargs):
choices = self.fields["type"].choices

if choices and len(choices) == 1:
self.fields["type"].disabled = True
self.fields["type"].initial = list(choices)[0][0].value
self.fields["type"].widget = forms.HiddenInput()

def clean_file(self):
file = self.cleaned_data["file"]
Expand Down
45 changes: 42 additions & 3 deletions src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django_webtest import WebTest
from timeline_logger.models import TimelineLog
from webtest import Upload
from webtest.forms import Hidden
from zgw_consumers.api_models.base import factory
from zgw_consumers.api_models.constants import (
RolOmschrijving,
Expand Down Expand Up @@ -528,7 +529,9 @@ def test_no_access_when_case_is_confidential(self, m):
)
self.assertRedirects(response, reverse("root"))

def test_expected_information_object_types_are_available_in_upload_form(self, m):
def test_single_expected_information_object_type_is_available_in_upload_form(
self, m
):
self._setUpMocks(m)

zaak_type_config = ZaakTypeConfigFactory(
Expand All @@ -550,9 +553,45 @@ def test_expected_information_object_types_are_available_in_upload_form(self, m)
)
form = response.forms["document-upload"]
type_field = form["type"]
expected_choices = [(str(zaak_type_iotc.id), True, zaak_type_iotc.omschrijving)]
expected_choice = zaak_type_iotc.id

self.assertEqual(type(type_field), Hidden)
self.assertEqual(type_field.value, str(expected_choice))

def test_expected_information_object_types_are_available_in_upload_form(self, m):
self._setUpMocks(m)

zaak_type_config = ZaakTypeConfigFactory(
identificatie=self.zaaktype["identificatie"]
)
zaak_type_iotc1 = ZaakTypeInformatieObjectTypeConfigFactory(
zaaktype_config=zaak_type_config,
informatieobjecttype_url=self.informatie_object["url"],
zaaktype_uuids=[self.zaaktype["uuid"]],
document_upload_enabled=True,
)
zaak_type_iotc2 = ZaakTypeInformatieObjectTypeConfigFactory(
zaaktype_config=zaak_type_config,
informatieobjecttype_url=f"{DOCUMENTEN_ROOT}enkelvoudiginformatieobjecten/705364ff-385a-4d60-b0da-a8cf5d18e6bb",
zaaktype_uuids=[self.zaaktype["uuid"]],
document_upload_enabled=True,
)

response = self.app.get(
reverse(
"accounts:case_status",
kwargs={"object_id": self.zaak["uuid"]},
),
user=self.user,
)
form = response.forms["document-upload"]
type_field = form["type"]
expected_choices = [
(str(zaak_type_iotc1.id), False, zaak_type_iotc1.omschrijving),
(str(zaak_type_iotc2.id), False, zaak_type_iotc2.omschrijving),
]

self.assertEqual(type_field.options, expected_choices)
self.assertEqual(sorted(type_field.options), sorted(expected_choices))

def test_upload_form_is_not_rendered_when_no_case_exists(self, m):
self._setUpMocks(m)
Expand Down