Skip to content

Commit

Permalink
Merge pull request #3673 from open-formulieren/fix/3649-compatibility…
Browse files Browse the repository at this point in the history
…-with-rxmission

[#3649] Add bestandsomvang field
  • Loading branch information
sergei-maertens authored Dec 8, 2023
2 parents 5387d18 + ac3feec commit 7b0a25c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/configuration/registration/zgw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ OAS URL to the OAS.
Client ID Client ID for the JWT-token.
Secret Secret for the JWT-token.
**Documenten API**
API root URL Root URL for the Documenten API that Open Forms can access.
API root URL Root URL for the Documenten API (version 1.1+) that Open Forms can access.
OAS URL to the OAS.
Client ID Client ID for the JWT-token.
Secret Secret for the JWT-token.
Expand Down Expand Up @@ -133,6 +133,6 @@ Technical
API Supported versions
================ ===================
Zaken API 1.0
Documenten API 1.0
Documenten API 1.1+
Catalogi API 1.0
================ ===================
6 changes: 5 additions & 1 deletion src/openforms/contrib/zgw/clients/documenten.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def create_document(
):
assert author, "author must be a non-empty string"
today = get_today()
base64_body = b64encode(content.read()).decode()
file_content = content.read()
base64_body = b64encode(file_content).decode()
data = {
"informatieobjecttype": informatieobjecttype,
"bronorganisatie": bronorganisatie,
Expand All @@ -46,6 +47,9 @@ def create_document(
"bestandsnaam": filename,
"beschrijving": description,
"indicatieGebruiksrecht": False,
"bestandsomvang": (
content.size if hasattr(content, "size") else len(file_content)
),
}

if vertrouwelijkheidaanduiding:
Expand Down
51 changes: 51 additions & 0 deletions src/openforms/registrations/contrib/zgw_apis/tests/test_backend.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from decimal import Decimal

from django.test import TestCase, override_settings, tag
Expand Down Expand Up @@ -1392,6 +1393,56 @@ def test_zgw_backend_has_reference_after_pre_submission(self, m):
submission.refresh_from_db()
self.assertEqual(submission.public_registration_reference, "ZAAK-OF-TEST")

@tag("gh-3649")
def test_document_size_argument_present(self, m):
submission = SubmissionFactory.from_components(
[
{
"key": "field1",
"type": "file",
},
],
)
zgw_form_options = dict(
zgw_api_group=self.zgw_group,
zaaktype="https://catalogi.nl/api/v1/zaaktypen/1",
informatieobjecttype="https://catalogi.nl/api/v1/informatieobjecttypen/1",
organisatie_rsin="000000000",
zaak_vertrouwelijkheidaanduiding="openbaar",
)
SubmissionFileAttachmentFactory.create(
submission_step=SubmissionStep.objects.first(),
content__data=b"content",
file_name="attachment1.txt",
form_key="field1",
_component_configuration_path="components.0",
)

self.install_mocks(m)

plugin = ZGWRegistration("zgw")
plugin.pre_register_submission(submission, zgw_form_options)
plugin.register_submission(submission, zgw_form_options)

(
create_zaak,
create_pdf_document,
relate_pdf_document,
get_roltypen,
create_rol,
get_statustypen,
create_status,
create_attachment1_document,
relate_attachment1_document,
) = m.request_history

self.assertIn("bestandsomvang", json.loads(create_pdf_document.body))

attachment_data = json.loads(create_attachment1_document.body)

self.assertIn("bestandsomvang", attachment_data)
self.assertEqual(attachment_data["bestandsomvang"], 7)


@tag("gh-1183")
@temp_private_root()
Expand Down

0 comments on commit 7b0a25c

Please sign in to comment.