diff --git a/docker/docker-compose.open-zaak.yml b/docker/docker-compose.open-zaak.yml index 78434947ff..d2fab6eab8 100644 --- a/docker/docker-compose.open-zaak.yml +++ b/docker/docker-compose.open-zaak.yml @@ -39,6 +39,7 @@ services: - CELERY_RESULT_BACKEND=redis://openzaak-redis:6379/1 - NOTIFICATIONS_DISABLED=true - JWT_EXPIRY=99999999999 # Roughly 3170 years. This is required for tests with time frozen to work + - CELERY_WORKER_CONCURRENCY=${CELERY_WORKER_CONCURRENCY:-2} ports: - 8003:8000 volumes: &openzaak_web_volumes diff --git a/docker/objects-apis/fixtures/objects_api_fixtures.json b/docker/objects-apis/fixtures/objects_api_fixtures.json index a367d2e740..44231cd8a4 100644 --- a/docker/objects-apis/fixtures/objects_api_fixtures.json +++ b/docker/objects-apis/fixtures/objects_api_fixtures.json @@ -1,77 +1,97 @@ -[ - { - "model": "core.objecttype", - "pk": 1, - "fields": { - "service": 1, - "uuid": "8e46e0a5-b1b4-449b-b9e9-fa3cea655f48", - "_name": "Person" - } - }, - { - "model": "core.objecttype", - "pk": 2, - "fields": { - "service": 1, - "uuid": "527b8408-7421-4808-a744-43ccb7bdaaa2", - "_name": "File uploads" - } - }, - { - "model": "token.tokenauth", - "pk": "7657474c3d75f56ae0abd0d1bf7994b09964dca9", - "fields": { - "contact_person": "Admin", - "email": "admin@example.com", - "organization": "", - "last_modified": "2023-10-24T08:58:51.291Z", - "created": "2023-10-24T08:58:51.291Z", - "application": "", - "administration": "" - } - }, - { - "model": "token.permission", - "pk": 1, - "fields": { - "token_auth": "7657474c3d75f56ae0abd0d1bf7994b09964dca9", - "object_type": 1, - "mode": "read_and_write", - "use_fields": false, - "fields": null - } - }, - { - "model": "token.permission", - "pk": 1, - "fields": { - "token_auth": "7657474c3d75f56ae0abd0d1bf7994b09964dca9", - "object_type": 2, - "mode": "read_and_write", - "use_fields": false, - "fields": null - } - }, - { - "model": "zgw_consumers.service", - "pk": 1, - "fields": { - "label": "Local objecttypes", - "oas": "https://raw.githubusercontent.com/maykinmedia/objecttypes-api/master/src/objecttypes/api/v2/openapi.yaml", - "oas_file": "", - "uuid": "ee08faa2-4cd1-45f6-ba16-d50872cf5cf2", - "api_type": "orc", - "api_root": "http://objecttypes-web:8000/api/v2/", - "client_id": "", - "secret": "", - "auth_type": "api_key", - "header_key": "Authorization", - "header_value": "Token 171be5abaf41e7856b423ad513df1ef8f867ff48", - "nlx": "", - "user_id": "", - "user_representation": "", - "client_certificate": null, - "server_certificate": null - } - } -] +[ +{ + "model": "core.objecttype", + "pk": 1, + "fields": { + "service": 1, + "uuid": "8e46e0a5-b1b4-449b-b9e9-fa3cea655f48", + "_name": "Person" + } +}, +{ + "model": "core.objecttype", + "pk": 2, + "fields": { + "service": 1, + "uuid": "527b8408-7421-4808-a744-43ccb7bdaaa2", + "_name": "File uploads" + } +}, +{ + "model": "core.objecttype", + "pk": 3, + "fields": { + "service": 1, + "uuid": "f1dde4fe-b7f9-46dc-84ae-429ae49e3705", + "_name": "Geo in data" + } +}, +{ + "model": "token.tokenauth", + "pk": "7657474c3d75f56ae0abd0d1bf7994b09964dca9", + "fields": { + "contact_person": "Admin", + "email": "admin@example.com", + "organization": "", + "last_modified": "2023-10-24T08:58:51.291Z", + "created": "2023-10-24T08:58:51.291Z", + "application": "", + "administration": "" + } +}, +{ + "model": "token.permission", + "pk": 1, + "fields": { + "token_auth": "7657474c3d75f56ae0abd0d1bf7994b09964dca9", + "object_type": 1, + "mode": "read_and_write", + "use_fields": false, + "fields": null + } +}, +{ + "model": "token.permission", + "pk": 2, + "fields": { + "token_auth": "7657474c3d75f56ae0abd0d1bf7994b09964dca9", + "object_type": 2, + "mode": "read_and_write", + "use_fields": false, + "fields": null + } +}, +{ + "model": "token.permission", + "pk": 3, + "fields": { + "token_auth": "7657474c3d75f56ae0abd0d1bf7994b09964dca9", + "object_type": 3, + "mode": "read_and_write", + "use_fields": false, + "fields": null + } +}, +{ + "model": "zgw_consumers.service", + "pk": 1, + "fields": { + "label": "Local objecttypes", + "oas": "https://raw.githubusercontent.com/maykinmedia/objecttypes-api/master/src/objecttypes/api/v2/openapi.yaml", + "oas_file": "", + "uuid": "ee08faa2-4cd1-45f6-ba16-d50872cf5cf2", + "api_type": "orc", + "api_root": "http://objecttypes-web:8000/api/v2/", + "client_id": "", + "secret": "", + "auth_type": "api_key", + "header_key": "Authorization", + "header_value": "Token 171be5abaf41e7856b423ad513df1ef8f867ff48", + "nlx": "", + "user_id": "", + "user_representation": "", + "client_certificate": null, + "server_certificate": null + } +} +] diff --git a/docker/objects-apis/fixtures/objecttypes_api_fixtures.json b/docker/objects-apis/fixtures/objecttypes_api_fixtures.json index fa62a65f87..79fc516d80 100644 --- a/docker/objects-apis/fixtures/objecttypes_api_fixtures.json +++ b/docker/objects-apis/fixtures/objecttypes_api_fixtures.json @@ -1,264 +1,322 @@ -[ - { - "model": "core.objecttype", - "pk": 1, - "fields": { - "uuid": "8e46e0a5-b1b4-449b-b9e9-fa3cea655f48", - "name": "Person", - "name_plural": "Persons", - "description": "", - "data_classification": "open", - "maintainer_organization": "", - "maintainer_department": "", - "contact_person": "", - "contact_email": "", - "source": "", - "update_frequency": "unknown", - "provider_organization": "", - "documentation_url": "", - "labels": {}, - "created_at": "2023-10-24", - "modified_at": "2024-02-08", - "allow_geometry": true - } - }, - { - "model": "core.objecttype", - "pk": 2, - "fields": { - "uuid": "3edfdaf7-f469-470b-a391-bb7ea015bd6f", - "name": "Tree", - "name_plural": "Trees", - "description": "", - "data_classification": "confidential", - "maintainer_organization": "", - "maintainer_department": "", - "contact_person": "", - "contact_email": "", - "source": "", - "update_frequency": "unknown", - "provider_organization": "", - "documentation_url": "", - "labels": {}, - "created_at": "2024-02-08", - "modified_at": "2024-02-08", - "allow_geometry": true - } - }, - { - "model": "core.objecttype", - "pk": 3, - "fields": { - "uuid": "527b8408-7421-4808-a744-43ccb7bdaaa2", - "name": "File Uploads", - "name_plural": "File Uploads", - "description": "", - "data_classification": "confidential", - "maintainer_organization": "", - "maintainer_department": "", - "contact_person": "", - "contact_email": "", - "source": "", - "update_frequency": "unknown", - "provider_organization": "", - "documentation_url": "", - "labels": {}, - "created_at": "2024-02-08", - "modified_at": "2024-02-08", - "allow_geometry": true - } - }, - { - "model": "core.objectversion", - "pk": 1, - "fields": { - "object_type": 1, - "version": 1, - "created_at": "2023-10-24", - "modified_at": "2024-02-08", - "published_at": "2024-02-08", - "json_schema": { - "$id": "https://example.com/person.schema.json", - "type": "object", - "title": "Person", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "age": { - "type": "integer", - "minimum": 0, - "description": "Age in years which must be equal to or greater than zero." - }, - "lastName": { - "type": "string", - "description": "The person's last name." - }, - "firstName": { - "type": "string", - "description": "The person's first name." - } - } - }, - "status": "published" - } - }, - { - "model": "core.objectversion", - "pk": 2, - "fields": { - "object_type": 1, - "version": 2, - "created_at": "2024-02-08", - "modified_at": "2024-02-08", - "published_at": "2024-02-08", - "json_schema": { - "$id": "https://example.com/person.schema.json", - "type": "object", - "title": "Person", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "age": { - "type": "integer", - "minimum": 18, - "description": "Age in years which must be equal to or greater than 18." - }, - "lastName": { - "type": "string", - "description": "The person's last name." - }, - "firstName": { - "type": "string", - "description": "The person's first name." - } - } - }, - "status": "published" - } - }, - { - "model": "core.objectversion", - "pk": 3, - "fields": { - "object_type": 1, - "version": 3, - "created_at": "2024-02-08", - "modified_at": "2024-02-08", - "published_at": "2024-02-08", - "json_schema": { - "$id": "https://example.com/person.schema.json", - "type": "object", - "title": "Person", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "age": { - "type": "integer", - "minimum": 18 - }, - "name": { - "type": "object", - "properties": { - "last.name": { - "type": "string" - } - } - }, - "submission_pdf_url": { - "type": "string", - "format": "uri" - }, - "submission_csv_url": { - "type": "string", - "format": "uri" - }, - "submission_payment_completed": { - "type": "boolean" - }, - "nested": { - "type": "object", - "properties": { - "unrelated": { - "type": "string" - }, - "submission_payment_amount": { - "type": "number", - "multipleOf": 0.01 - } - } - }, - "submission_payment_public_ids": { - "type": "array" - }, - "submission_date": { - "type": "string", - "format": "date-time" - } - } - }, - "status": "draft" - } - }, - { - "model": "core.objectversion", - "pk": 4, - "fields": { - "object_type": 2, - "version": 1, - "created_at": "2024-02-08", - "modified_at": "2024-02-08", - "published_at": "2024-02-08", - "json_schema": { - "$id": "https://example.com/tree.schema.json", - "type": "object", - "title": "Tree", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "height": { - "type": "integer", - "description": "The height of the tree." - } - } - }, - "status": "published" - } - }, - { - "model": "core.objectversion", - "pk": 5, - "fields": { - "object_type": 3, - "version": 1, - "created_at": "2024-02-08", - "modified_at": "2024-02-08", - "published_at": "2024-02-08", - "json_schema": { - "type": "object", - "title": "File uploads", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "single_file": { - "type": "string" - }, - "multiple_files": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "status": "published" - } - }, - { - "model": "token.tokenauth", - "pk": "171be5abaf41e7856b423ad513df1ef8f867ff48", - "fields": { - "contact_person": "Admin", - "email": "admin@example.com", - "organization": "", - "last_modified": "2023-10-24T08:56:26.955Z", - "created": "2023-10-24T08:56:26.955Z", - "application": "", - "administration": "" - } - } -] +[ +{ + "model": "core.objecttype", + "pk": 1, + "fields": { + "uuid": "8e46e0a5-b1b4-449b-b9e9-fa3cea655f48", + "name": "Person", + "name_plural": "Persons", + "description": "", + "data_classification": "open", + "maintainer_organization": "", + "maintainer_department": "", + "contact_person": "", + "contact_email": "", + "source": "", + "update_frequency": "unknown", + "provider_organization": "", + "documentation_url": "", + "labels": {}, + "created_at": "2023-10-24", + "modified_at": "2024-02-08", + "allow_geometry": true + } +}, +{ + "model": "core.objecttype", + "pk": 2, + "fields": { + "uuid": "3edfdaf7-f469-470b-a391-bb7ea015bd6f", + "name": "Tree", + "name_plural": "Trees", + "description": "", + "data_classification": "confidential", + "maintainer_organization": "", + "maintainer_department": "", + "contact_person": "", + "contact_email": "", + "source": "", + "update_frequency": "unknown", + "provider_organization": "", + "documentation_url": "", + "labels": {}, + "created_at": "2024-02-08", + "modified_at": "2024-02-08", + "allow_geometry": true + } +}, +{ + "model": "core.objecttype", + "pk": 3, + "fields": { + "uuid": "527b8408-7421-4808-a744-43ccb7bdaaa2", + "name": "File Uploads", + "name_plural": "File Uploads", + "description": "", + "data_classification": "confidential", + "maintainer_organization": "", + "maintainer_department": "", + "contact_person": "", + "contact_email": "", + "source": "", + "update_frequency": "unknown", + "provider_organization": "", + "documentation_url": "", + "labels": {}, + "created_at": "2024-02-08", + "modified_at": "2024-02-08", + "allow_geometry": true + } +}, +{ + "model": "core.objecttype", + "pk": 4, + "fields": { + "uuid": "f1dde4fe-b7f9-46dc-84ae-429ae49e3705", + "name": "Geo in data", + "name_plural": "Geo in data", + "description": "", + "data_classification": "confidential", + "maintainer_organization": "", + "maintainer_department": "", + "contact_person": "", + "contact_email": "", + "source": "", + "update_frequency": "unknown", + "provider_organization": "", + "documentation_url": "", + "labels": {}, + "created_at": "2024-02-08", + "modified_at": "2024-02-08", + "allow_geometry": true + } +}, +{ + "model": "core.objectversion", + "pk": 1, + "fields": { + "object_type": 1, + "version": 1, + "created_at": "2023-10-24", + "modified_at": "2024-02-08", + "published_at": "2024-02-08", + "json_schema": { + "$id": "https://example.com/person.schema.json", + "type": "object", + "title": "Person", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "age": { + "type": "integer", + "minimum": 0, + "description": "Age in years which must be equal to or greater than zero." + }, + "lastName": { + "type": "string", + "description": "The person's last name." + }, + "firstName": { + "type": "string", + "description": "The person's first name." + } + } + }, + "status": "published" + } +}, +{ + "model": "core.objectversion", + "pk": 2, + "fields": { + "object_type": 1, + "version": 2, + "created_at": "2024-02-08", + "modified_at": "2024-02-08", + "published_at": "2024-02-08", + "json_schema": { + "$id": "https://example.com/person.schema.json", + "type": "object", + "title": "Person", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "age": { + "type": "integer", + "minimum": 18, + "description": "Age in years which must be equal to or greater than 18." + }, + "lastName": { + "type": "string", + "description": "The person's last name." + }, + "firstName": { + "type": "string", + "description": "The person's first name." + } + } + }, + "status": "published" + } +}, +{ + "model": "core.objectversion", + "pk": 3, + "fields": { + "object_type": 1, + "version": 3, + "created_at": "2024-02-08", + "modified_at": "2024-02-08", + "published_at": "2024-02-08", + "json_schema": { + "$id": "https://example.com/person.schema.json", + "type": "object", + "title": "Person", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "age": { + "type": "integer", + "minimum": 18 + }, + "name": { + "type": "object", + "properties": { + "last.name": { + "type": "string" + } + } + }, + "nested": { + "type": "object", + "properties": { + "unrelated": { + "type": "string" + }, + "submission_payment_amount": { + "type": "number", + "multipleOf": 0.01 + } + } + }, + "submission_date": { + "type": "string", + "format": "date-time" + }, + "submission_csv_url": { + "type": "string", + "format": "uri" + }, + "submission_pdf_url": { + "type": "string", + "format": "uri" + }, + "submission_payment_completed": { + "type": "boolean" + }, + "submission_payment_public_ids": { + "type": "array" + } + } + }, + "status": "draft" + } +}, +{ + "model": "core.objectversion", + "pk": 4, + "fields": { + "object_type": 2, + "version": 1, + "created_at": "2024-02-08", + "modified_at": "2024-02-08", + "published_at": "2024-02-08", + "json_schema": { + "$id": "https://example.com/tree.schema.json", + "type": "object", + "title": "Tree", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "height": { + "type": "integer", + "description": "The height of the tree." + } + } + }, + "status": "published" + } +}, +{ + "model": "core.objectversion", + "pk": 5, + "fields": { + "object_type": 3, + "version": 1, + "created_at": "2024-02-08", + "modified_at": "2024-02-08", + "published_at": "2024-02-08", + "json_schema": { + "type": "object", + "title": "File uploads", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "single_file": { + "type": "string" + }, + "multiple_files": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "status": "published" + } +}, +{ + "model": "core.objectversion", + "pk": 6, + "fields": { + "object_type": 4, + "version": 1, + "created_at": "2024-02-08", + "modified_at": "2024-02-08", + "published_at": "2024-02-08", + "json_schema": { + "type": "object", + "title": "Geo data inside data", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "pointCoordinates": { + "type": "object", + "properties": { + "type": { + "const": "Point" + }, + "coordinates": { + "type": "array", + "items": { + "type": "number" + }, + "maxItems": 2, + "minItems": 2 + } + } + } + } + }, + "status": "published" + } +}, +{ + "model": "token.tokenauth", + "pk": "171be5abaf41e7856b423ad513df1ef8f867ff48", + "fields": { + "contact_person": "Admin", + "email": "admin@example.com", + "organization": "", + "last_modified": "2023-10-24T08:56:26.955Z", + "created": "2023-10-24T08:56:26.955Z", + "application": "", + "administration": "" + } +} +] diff --git a/src/openforms/registrations/contrib/objects_api/submission_registration.py b/src/openforms/registrations/contrib/objects_api/submission_registration.py index 7c4e45e27e..5a1a91f0f7 100644 --- a/src/openforms/registrations/contrib/objects_api/submission_registration.py +++ b/src/openforms/registrations/contrib/objects_api/submission_registration.py @@ -18,6 +18,7 @@ create_report_document, ) from openforms.formio.service import FormioData +from openforms.formio.typing import Component from openforms.registrations.exceptions import RegistrationFailed from openforms.submissions.exports import create_submission_export from openforms.submissions.mapping import SKIP, FieldConf, apply_data_mapping @@ -27,6 +28,7 @@ SubmissionReport, ) from openforms.typing import JSONObject +from openforms.variables.constants import FormVariableSources from openforms.variables.service import get_static_variables from openforms.variables.utils import get_variables_for_context @@ -209,8 +211,9 @@ def save_registration_data( submission=submission ) - with get_documents_client() as documents_client, save_and_raise( - registration_data + with ( + get_documents_client() as documents_client, + save_and_raise(registration_data), ): if not registration_data.pdf_url: registration_data.pdf_url = register_submission_pdf( @@ -383,6 +386,20 @@ def _get_record_data( return record_data + @staticmethod + def _process_value(value: Any, component: Component) -> Any: + match component: + case {"type": "file", **rest}: + multiple = rest.get("multiple", False) + assert isinstance(value, list) + return value[0] if not multiple else value + + case {"type": "map"}: + # Currently we only support Point coordinates + return _point_coordinate(value) + case _: + return value + @override def get_object_data( self, submission: Submission, options: RegistrationOptionsV2 @@ -404,16 +421,25 @@ def get_object_data( urls_map[o.variable_key].append(o.document_url) for key in dynamic_values.keys(): + variable = state.get_variable(key) + submission_value = dynamic_values[key] + + # special casing documents - we transform the formio file upload data into + # the api resource URLs for the uploaded documents in the Documens API. + # + # Normalizing to string/array of strings is done in the _process_value + # method. if key in urls_map: - variable = state.get_variable(key) - is_multiple = variable.form_variable.form_definition.configuration_wrapper.component_map[ + submission_value = urls_map[key] + + # look up the component used (if relevant) to perform any required + # pre-processing. + if (variable.form_variable.source) == FormVariableSources.component: + component = variable.form_variable.form_definition.configuration_wrapper.component_map[ key - ].get( - "multiple", False - ) - dynamic_values[key] = ( - urls_map[key][0] if not is_multiple else urls_map[key] - ) + ] + # update the value after processing to make it objects-API suitable + dynamic_values[key] = self._process_value(submission_value, component) static_values = state.static_data() static_values.update( @@ -437,9 +463,7 @@ def get_object_data( ) if geometry_variable_key := options.get("geometry_variable_key"): - object_data["record"]["geometry"] = _point_coordinate( - variables_values[geometry_variable_key] - ) + object_data["record"]["geometry"] = variables_values[geometry_variable_key] return object_data diff --git a/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIBackendV2Tests/ObjectsAPIBackendV2Tests.test_submission_with_map_component_inside_data.yaml b/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIBackendV2Tests/ObjectsAPIBackendV2Tests.test_submission_with_map_component_inside_data.yaml new file mode 100644 index 0000000000..1a7dfbc757 --- /dev/null +++ b/src/openforms/registrations/contrib/objects_api/tests/files/vcr_cassettes/ObjectsAPIBackendV2Tests/ObjectsAPIBackendV2Tests.test_submission_with_map_component_inside_data.yaml @@ -0,0 +1,103 @@ +interactions: +- request: + body: '{"informatieobjecttype": "http://localhost:8003/catalogi/api/v1/informatieobjecttypen/7a474713-0833-402a-8441-e467c08ac55b", + "bronorganisatie": "000000000", "creatiedatum": "2024-03-19", "titel": "Form + 001", "auteur": "Aanvrager", "taal": "nld", "formaat": "application/pdf", "inhoud": + "", "status": "definitief", "bestandsnaam": "open-forms-Form 001.pdf", "beschrijving": + "Ingezonden formulier", "indicatieGebruiksrecht": false, "bestandsomvang": 0}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcxMDg1NTYzNCwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.NJjZEPSwh9eGzntjwUB7rFAiaq_5DqYgVylWuKdtdMA + Connection: + - keep-alive + Content-Length: + - '450' + Content-Type: + - application/json + User-Agent: + - python-requests/2.31.0 + method: POST + uri: http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten + response: + body: + string: '{"url":"http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/ab166064-d736-4913-a9b0-3d026180d541","identificatie":"DOCUMENT-2024-0000000012","bronorganisatie":"000000000","creatiedatum":"2024-03-19","titel":"Form + 001","vertrouwelijkheidaanduiding":"openbaar","auteur":"Aanvrager","status":"definitief","formaat":"application/pdf","taal":"nld","versie":1,"beginRegistratie":"2024-03-22T15:24:43.032909Z","bestandsnaam":"open-forms-Form + 001.pdf","inhoud":"http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/ab166064-d736-4913-a9b0-3d026180d541/download?versie=1","bestandsomvang":0,"link":"","beschrijving":"Ingezonden + formulier","ontvangstdatum":null,"verzenddatum":null,"indicatieGebruiksrecht":false,"verschijningsvorm":"","ondertekening":{"soort":"","datum":null},"integriteit":{"algoritme":"","waarde":"","datum":null},"informatieobjecttype":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/7a474713-0833-402a-8441-e467c08ac55b","locked":false,"bestandsdelen":[],"trefwoorden":[],"lock":""}' + headers: + API-version: + - 1.4.2 + Allow: + - GET, POST, HEAD, OPTIONS + Content-Length: + - '1042' + Content-Type: + - application/json + Location: + - http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/ab166064-d736-4913-a9b0-3d026180d541 + Referrer-Policy: + - same-origin + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-XSS-Protection: + - 1; mode=block + status: + code: 201 + message: Created +- request: + body: '{"type": "http://objecttypes-web:8000/api/v2/objecttypes/f1dde4fe-b7f9-46dc-84ae-429ae49e3705", + "record": {"typeVersion": 1, "data": {"pointCoordinates": {"type": "Point", + "coordinates": [52.36673378967122, 4.893164274470299]}}, "startAt": "2024-03-19"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Token 7657474c3d75f56ae0abd0d1bf7994b09964dca9 + Connection: + - keep-alive + Content-Crs: + - EPSG:4326 + Content-Length: + - '254' + Content-Type: + - application/json + User-Agent: + - python-requests/2.31.0 + method: POST + uri: http://localhost:8002/api/v2/objects + response: + body: + string: '{"url":"http://localhost:8002/api/v2/objects/d321545b-33e6-4b65-876b-41a63554be0d","uuid":"d321545b-33e6-4b65-876b-41a63554be0d","type":"http://objecttypes-web:8000/api/v2/objecttypes/f1dde4fe-b7f9-46dc-84ae-429ae49e3705","record":{"index":1,"typeVersion":1,"data":{"pointCoordinates":{"type":"Point","coordinates":[52.36673378967122,4.893164274470299]}},"geometry":null,"startAt":"2024-03-19","endAt":null,"registrationAt":"2024-03-22","correctionFor":null,"correctedBy":null}}' + headers: + Allow: + - GET, POST, HEAD, OPTIONS + Content-Crs: + - EPSG:4326 + Content-Length: + - '478' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Location: + - http://localhost:8002/api/v2/objects/d321545b-33e6-4b65-876b-41a63554be0d + Referrer-Policy: + - same-origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + status: + code: 201 + message: Created +version: 1 diff --git a/src/openforms/registrations/contrib/objects_api/tests/test_backend_v2.py b/src/openforms/registrations/contrib/objects_api/tests/test_backend_v2.py index e30871dd65..b082d0d854 100644 --- a/src/openforms/registrations/contrib/objects_api/tests/test_backend_v2.py +++ b/src/openforms/registrations/contrib/objects_api/tests/test_backend_v2.py @@ -241,3 +241,56 @@ def test_submission_with_file_components(self): self.assertIsInstance(result["record"]["data"]["multiple_files"], list) self.assertEqual(len(result["record"]["data"]["multiple_files"]), 1) + + def test_submission_with_map_component_inside_data(self): + """ + A map component can be explicitly mapped to an attribute inside the 'data' key. + + This happens when more than one map component is in the form, and only one can + be mapped to the ``record.geometry`` path, the rest must go in ``record.data.``. + """ + submission = SubmissionFactory.from_components( + [ + { + "key": "location", + "type": "map", + "label": "Map with point coordinate", + }, + ], + completed=True, + submitted_data={ + "location": [52.36673378967122, 4.893164274470299], + }, + ) + v2_options: RegistrationOptionsV2 = { + "version": 2, + # See the docker compose fixtures for more info on these values: + "objecttype": "http://objecttypes-web:8000/api/v2/objecttypes/f1dde4fe-b7f9-46dc-84ae-429ae49e3705", + "objecttype_version": 1, + "upload_submission_csv": False, + "informatieobjecttype_submission_report": "http://localhost:8003/catalogi/api/v1/informatieobjecttypen/7a474713-0833-402a-8441-e467c08ac55b", + "informatieobjecttype_attachment": "", + "organisatie_rsin": "000000000", + "variables_mapping": [ + # fmt: off + { + "variable_key": "location", + "target_path": ["pointCoordinates"], + }, + # fmt: on + ], + } + + plugin = ObjectsAPIRegistration(PLUGIN_IDENTIFIER) + + # Run the registration + result = plugin.register_submission(submission, v2_options) + + record_data = result["record"]["data"] + self.assertEqual( + record_data["pointCoordinates"], + { + "type": "Point", + "coordinates": [52.36673378967122, 4.893164274470299], + }, + )