diff --git a/docs/developers/plugins/registration_plugins.rst b/docs/developers/plugins/registration_plugins.rst index a3a60dcc7a..99d2084bb9 100644 --- a/docs/developers/plugins/registration_plugins.rst +++ b/docs/developers/plugins/registration_plugins.rst @@ -106,6 +106,8 @@ Public Python API .. autoclass:: openforms.registrations.base.BasePlugin :members: +.. autoclass:: openforms.registrations.base.PreRegistrationResult + **Module documentation** .. automodule:: openforms.registrations diff --git a/src/openforms/forms/tests/test_api_form_plugin_options.py b/src/openforms/forms/tests/test_api_form_plugin_options.py index 2c6c572b8b..50407a7ed7 100644 --- a/src/openforms/forms/tests/test_api_form_plugin_options.py +++ b/src/openforms/forms/tests/test_api_form_plugin_options.py @@ -28,9 +28,6 @@ class RegistrationPlugin(RegistrationBasePlugin): def register_submission(self, submission, options): pass - def get_reference_from_result(self, result: dict) -> None: - pass - class PaymentPlugin(PaymentBasePlugin): configuration_options = EmailOptionsSerializer diff --git a/src/openforms/forms/tests/test_form_admin.py b/src/openforms/forms/tests/test_form_admin.py index 79dfd48c01..ca6efc238d 100644 --- a/src/openforms/forms/tests/test_form_admin.py +++ b/src/openforms/forms/tests/test_form_admin.py @@ -28,9 +28,6 @@ class Plugin(BasePlugin): def register_submission(self, submission, options): pass - def get_reference_from_result(self, result) -> str: - return "foo" - @disable_admin_mfa() class FormAdminTests(FormListAjaxMixin, WebTest): diff --git a/src/openforms/forms/tests/test_serializers.py b/src/openforms/forms/tests/test_serializers.py index bf5d8672d9..954187588d 100644 --- a/src/openforms/forms/tests/test_serializers.py +++ b/src/openforms/forms/tests/test_serializers.py @@ -289,9 +289,6 @@ class UnicornPlugin(BaseRegistrationPlugin): # This doesn't pass registry.check_plugin # configuration_options = None - def get_reference_from_result(self, *args, **kwargs): - pass - def register_submission(self, *args, **kwargs): pass diff --git a/src/openforms/payments/tests/test_services.py b/src/openforms/payments/tests/test_services.py index 4d9ee56448..b63a84163e 100644 --- a/src/openforms/payments/tests/test_services.py +++ b/src/openforms/payments/tests/test_services.py @@ -27,9 +27,6 @@ def register_submission(self, submission, options): def update_payment_status(self, submission: Submission, options): pass - def get_reference_from_result(self, result): - pass - class UpdatePaymentTests(TestCase): def setUp(self): diff --git a/src/openforms/registrations/api/tests/test_endpoints.py b/src/openforms/registrations/api/tests/test_endpoints.py index 33cca90fef..6fa2cda07e 100644 --- a/src/openforms/registrations/api/tests/test_endpoints.py +++ b/src/openforms/registrations/api/tests/test_endpoints.py @@ -35,9 +35,6 @@ class Plugin(BasePlugin): def register_submission(self, submission, options): pass - def get_reference_from_result(self, result: dict) -> None: - pass - register("test")(Plugin) diff --git a/src/openforms/registrations/base.py b/src/openforms/registrations/base.py index 216ff51d48..a4a52a3d8b 100644 --- a/src/openforms/registrations/base.py +++ b/src/openforms/registrations/base.py @@ -1,5 +1,6 @@ from abc import ABC, abstractmethod -from typing import TYPE_CHECKING, Any +from dataclasses import dataclass +from typing import TYPE_CHECKING from rest_framework import serializers @@ -16,6 +17,14 @@ class EmptyOptions(JsonSchemaSerializerMixin, serializers.Serializer): pass +@dataclass +class PreRegistrationResult: + """Encapsulate the submission reference and any intermediate result from pre-registration.""" + + reference: str = "" + data: dict | None = None + + class BasePlugin(ABC, AbstractBasePlugin): configuration_options: SerializerCls = EmptyOptions """ @@ -38,33 +47,18 @@ def register_submission( ) -> dict | None: raise NotImplementedError() - @abstractmethod - def get_reference_from_result(self, result: Any) -> str: - """ - Extract the public submission reference from the result data. - - This method must return a string to be saved on the submission model. - - :arg result: the raw underlying JSONField datastructure. - """ - raise NotImplementedError() - def update_payment_status(self, submission: "Submission", options: dict): raise NotImplementedError() - def pre_register_submission(self, submission: "Submission", options: dict) -> None: + def pre_register_submission( + self, submission: "Submission", options: dict + ) -> PreRegistrationResult: """Perform any tasks before registering the submission - For plugins where the registration backend does not generate a reference number, an internal reference number - can be set on the submission in this step. + For plugins where the registration backend does not generate a reference number, + no need to implement this method. """ - pass - - def obtain_submission_reference( - self, submission: "Submission", options: dict - ) -> None: - """Obtain the reference number generated by the registration backend and set it on the submission.""" - pass + return PreRegistrationResult() def get_custom_templatetags_libraries(self) -> list[str]: """ diff --git a/src/openforms/registrations/contrib/camunda/plugin.py b/src/openforms/registrations/contrib/camunda/plugin.py index d172a4b24f..415a9a3608 100644 --- a/src/openforms/registrations/contrib/camunda/plugin.py +++ b/src/openforms/registrations/contrib/camunda/plugin.py @@ -7,7 +7,7 @@ """ import logging -from typing import Any, NoReturn +from typing import Any from django.urls import reverse from django.utils.translation import gettext_lazy as _ @@ -19,10 +19,9 @@ from django_camunda.utils import serialize_variables from openforms.submissions.models import Submission -from openforms.submissions.public_references import set_submission_reference from ...base import BasePlugin -from ...exceptions import NoSubmissionReference, RegistrationFailed +from ...exceptions import RegistrationFailed from ...registry import register from .checks import check_config from .complex_variables import get_complex_process_variables @@ -144,16 +143,6 @@ def register_submission( } } - def get_reference_from_result(self, result: dict[str, str]) -> NoReturn: - """ - Extract the public submission reference from the result data. - - We never return, as the Camunda API response does not contain anything useful - and readable for the end-user and we cannot make assumptions about the process - model. The instance ID is a UUID, which is not suitable for end users. - """ - raise NoSubmissionReference("Deferred to Open Forms itself") - def update_payment_status(self, submission: "Submission", options: dict): # TODO: we could ask for a BPMN message to be specified so we can signal the # process instance? This needs to be documented properly for the modellers @@ -173,6 +162,3 @@ def get_config_actions(self) -> list[tuple[str, str]]: ), ), ] - - def pre_register_submission(self, submission: "Submission", options: dict) -> None: - set_submission_reference(submission) diff --git a/src/openforms/registrations/contrib/demo/plugin.py b/src/openforms/registrations/contrib/demo/plugin.py index 6b2b65fe99..b765003074 100644 --- a/src/openforms/registrations/contrib/demo/plugin.py +++ b/src/openforms/registrations/contrib/demo/plugin.py @@ -3,10 +3,9 @@ from django.utils.translation import gettext_lazy as _ from openforms.submissions.models import Submission -from openforms.submissions.public_references import set_submission_reference from ...base import BasePlugin -from ...exceptions import NoSubmissionReference, RegistrationFailed +from ...exceptions import RegistrationFailed from ...registry import register from .config import DemoOptionsSerializer @@ -22,9 +21,6 @@ def register_submission(self, submission: Submission, options: dict) -> None: if options.get("extra_line"): print(options["extra_line"]) - def get_reference_from_result(self, result: None) -> NoReturn: - raise NoSubmissionReference("Demo plugin does not emit a reference") - def update_payment_status(self, submission: "Submission", options: dict): print(submission) @@ -34,9 +30,6 @@ def check_config(self): """ pass - def pre_register_submission(self, submission: "Submission", options: dict) -> None: - set_submission_reference(submission) - @register("failing-demo") class DemoFailRegistration(BasePlugin): @@ -47,9 +40,6 @@ class DemoFailRegistration(BasePlugin): def register_submission(self, submission: Submission, options: dict) -> NoReturn: raise RegistrationFailed("Demo failing registration") - def get_reference_from_result(self, result: None) -> NoReturn: - raise NoSubmissionReference("Demo plugin does not emit a reference") - def update_payment_status(self, submission: "Submission", options: dict): pass @@ -59,9 +49,6 @@ def check_config(self): """ pass - def pre_register_submission(self, submission: "Submission", options: dict) -> None: - set_submission_reference(submission) - @register("exception-demo") class DemoExceptionRegistration(BasePlugin): @@ -72,9 +59,6 @@ class DemoExceptionRegistration(BasePlugin): def register_submission(self, submission: Submission, options: dict) -> NoReturn: raise Exception("Demo exception registration") - def get_reference_from_result(self, result: None) -> NoReturn: - raise NoSubmissionReference("Demo plugin does not emit a reference") - def update_payment_status(self, submission: "Submission", options: dict): pass @@ -83,6 +67,3 @@ def check_config(self): Demo config is always valid. """ pass - - def pre_register_submission(self, submission: "Submission", options: dict) -> None: - set_submission_reference(submission) diff --git a/src/openforms/registrations/contrib/email/plugin.py b/src/openforms/registrations/contrib/email/plugin.py index f915f9fa18..845bea4842 100644 --- a/src/openforms/registrations/contrib/email/plugin.py +++ b/src/openforms/registrations/contrib/email/plugin.py @@ -1,6 +1,6 @@ import html from mimetypes import types_map -from typing import Any, NoReturn, TypedDict +from typing import Any, TypedDict from django.conf import settings from django.urls import reverse @@ -21,14 +21,12 @@ ) from openforms.submissions.exports import create_submission_export from openforms.submissions.models import Submission -from openforms.submissions.public_references import set_submission_reference from openforms.submissions.rendering.constants import RenderModes from openforms.submissions.rendering.renderer import Renderer from openforms.template import render_from_string from openforms.variables.utils import get_variables_for_context from ...base import BasePlugin -from ...exceptions import NoSubmissionReference from ...registry import register from .checks import check_config from .config import EmailOptionsSerializer @@ -187,9 +185,6 @@ def send_registration_email( }, ) - def get_reference_from_result(self, result: None) -> NoReturn: - raise NoSubmissionReference("Email plugin does not emit a reference") - def update_payment_status(self, submission: "Submission", options: dict): recipients = options.get("payment_emails") if not recipients: @@ -215,9 +210,6 @@ def get_config_actions(self) -> list[tuple[str, str]]: (_("Test"), reverse("admin_email_test")), ] - def pre_register_submission(self, submission: "Submission", options: dict) -> None: - set_submission_reference(submission) - def get_custom_templatetags_libraries(self) -> list[str]: return [ "openforms.registrations.contrib.email.templatetags.registrations.contrib.email.registration_summary" diff --git a/src/openforms/registrations/contrib/email/tests/test_backend.py b/src/openforms/registrations/contrib/email/tests/test_backend.py index 726a0abecb..c185e22f86 100644 --- a/src/openforms/registrations/contrib/email/tests/test_backend.py +++ b/src/openforms/registrations/contrib/email/tests/test_backend.py @@ -41,7 +41,6 @@ from openforms.utils.tests.html_assert import HTMLAssertMixin from openforms.variables.constants import FormVariableSources -from ....service import NoSubmissionReference, extract_submission_reference from ..constants import AttachmentFormat from ..models import EmailConfig from ..plugin import EmailRegistration @@ -471,17 +470,6 @@ def test_register_and_update_paid_product_with_payment_email_recipient(self): # check we used the payment_emails self.assertEqual(message.to, ["payment@bar.nl", "payment@foo.nl"]) - def test_no_reference_can_be_extracted(self): - submission = SubmissionFactory.create( - form=self.form, - completed=True, - registration_success=True, - registration_result="irrelevant", - ) - - with self.assertRaises(NoSubmissionReference): - extract_submission_reference(submission) - @override_settings(DEFAULT_FROM_EMAIL="info@open-forms.nl") def test_submission_with_email_backend_export_csv_xlsx(self): email_form_options = dict( diff --git a/src/openforms/registrations/contrib/microsoft_graph/plugin.py b/src/openforms/registrations/contrib/microsoft_graph/plugin.py index 6727289894..a2d4bec28c 100644 --- a/src/openforms/registrations/contrib/microsoft_graph/plugin.py +++ b/src/openforms/registrations/contrib/microsoft_graph/plugin.py @@ -1,5 +1,4 @@ from pathlib import PurePosixPath -from typing import NoReturn from django.urls import reverse from django.utils import timezone @@ -17,11 +16,10 @@ MSGraphRegistrationConfig, ) from openforms.submissions.models import Submission, SubmissionReport -from openforms.submissions.public_references import set_submission_reference from openforms.template import render_from_string from ...base import BasePlugin -from ...exceptions import NoSubmissionReference, RegistrationFailed +from ...exceptions import RegistrationFailed from ...registry import register from .config import MicrosoftGraphOptionsSerializer @@ -78,9 +76,6 @@ def register_submission(self, submission: Submission, options: dict) -> None: self._set_payment(uploader, submission, folder_name) - def get_reference_from_result(self, result: None) -> NoReturn: - raise NoSubmissionReference("MS Graph plugin does not emit a reference") - def update_payment_status(self, submission: "Submission", options: dict): config = MSGraphRegistrationConfig.get_solo() client = MSGraphClient(config.service) @@ -129,6 +124,3 @@ def get_config_actions(self): ), ), ] - - def pre_register_submission(self, submission: "Submission", options: dict) -> None: - set_submission_reference(submission) diff --git a/src/openforms/registrations/contrib/objects_api/plugin.py b/src/openforms/registrations/contrib/objects_api/plugin.py index 4c2c946e5b..f4fc8b8943 100644 --- a/src/openforms/registrations/contrib/objects_api/plugin.py +++ b/src/openforms/registrations/contrib/objects_api/plugin.py @@ -1,6 +1,6 @@ import logging from functools import partial -from typing import Any, NoReturn +from typing import Any from django.urls import reverse from django.utils.translation import gettext_lazy as _ @@ -18,12 +18,10 @@ from openforms.submissions.exports import create_submission_export from openforms.submissions.mapping import SKIP, FieldConf from openforms.submissions.models import Submission, SubmissionReport -from openforms.submissions.public_references import set_submission_reference from openforms.variables.utils import get_variables_for_context from ...base import BasePlugin from ...constants import RegistrationAttribute -from ...exceptions import NoSubmissionReference from ...registry import register from .checks import check_config from .client import get_documents_client, get_objects_client @@ -169,9 +167,6 @@ def register_submission( return response - def get_reference_from_result(self, result: None) -> NoReturn: - raise NoSubmissionReference("Object API plugin does not emit a reference") - def check_config(self): check_config() @@ -186,9 +181,6 @@ def get_config_actions(self): ), ] - def pre_register_submission(self, submission: "Submission", options: dict) -> None: - set_submission_reference(submission) - def get_custom_templatetags_libraries(self) -> list[str]: prefix = "openforms.registrations.contrib.objects_api.templatetags.registrations.contrib" return [ diff --git a/src/openforms/registrations/contrib/objects_api/tests/test_backend.py b/src/openforms/registrations/contrib/objects_api/tests/test_backend.py index 3718874533..68b7069b39 100644 --- a/src/openforms/registrations/contrib/objects_api/tests/test_backend.py +++ b/src/openforms/registrations/contrib/objects_api/tests/test_backend.py @@ -17,7 +17,6 @@ ) from ....constants import RegistrationAttribute -from ....service import NoSubmissionReference, extract_submission_reference from ..models import ObjectsAPIConfig from ..plugin import PLUGIN_IDENTIFIER, ObjectsAPIRegistration @@ -792,17 +791,6 @@ def test_submission_with_objects_api_backend_attachments(self, m): ) self.assertNotIn("vertrouwelijkheidaanduiding", attachment2_create_data) - def test_no_reference_can_be_extracted(self, m): - submission = SubmissionFactory.create( - form__registration_backend="objects_api", - completed=True, - registration_success=True, - registration_result="irrelevant", - ) - - with self.assertRaises(NoSubmissionReference): - extract_submission_reference(submission) - def test_submission_with_objects_api_backend_attachments_specific_iotypen(self, m): submission = SubmissionFactory.from_components( [ diff --git a/src/openforms/registrations/contrib/stuf_zds/plugin.py b/src/openforms/registrations/contrib/stuf_zds/plugin.py index 49c73089b4..a6faf1fc52 100644 --- a/src/openforms/registrations/contrib/stuf_zds/plugin.py +++ b/src/openforms/registrations/contrib/stuf_zds/plugin.py @@ -8,7 +8,7 @@ from rest_framework import serializers from openforms.plugins.exceptions import InvalidPluginConfiguration -from openforms.registrations.base import BasePlugin +from openforms.registrations.base import BasePlugin, PreRegistrationResult from openforms.registrations.constants import ( REGISTRATION_ATTRIBUTE, RegistrationAttribute, @@ -199,7 +199,7 @@ class StufZDSRegistration(BasePlugin): def pre_register_submission( self, submission: "Submission", options: ZaakOptions - ) -> None: + ) -> PreRegistrationResult: with get_client(options=options) as client: # obtain a zaaknummer & save it - first, check if we have an intermediate result # from earlier attempts. if we do, do not generate a new number @@ -210,8 +210,7 @@ def pre_register_submission( default="", ) - submission.public_registration_reference = zaak_id - submission.save() + return PreRegistrationResult(reference=zaak_id) def register_submission( self, submission: Submission, options: ZaakOptions @@ -320,22 +319,6 @@ def items(self): } return result - def get_reference_from_result(self, result: dict[str, str]) -> str: - """ - Extract the public submission reference from the result data. - - This method must return a string to be saved on the submission model. - - :arg result: the raw underlying JSONField datastructure. - - .. warning:: - - Technically the combination of (bronorganisatie,identicatie) must be unique, - so if the same identification is generated by different Zaaksystemen, - this may cause problems! - """ - return result["zaak"] - def update_payment_status(self, submission: "Submission", options: ZaakOptions): with get_client(options) as client: client.set_zaak_payment( diff --git a/src/openforms/registrations/contrib/stuf_zds/tests/test_backend.py b/src/openforms/registrations/contrib/stuf_zds/tests/test_backend.py index e4a52324ad..dc4b5996c2 100644 --- a/src/openforms/registrations/contrib/stuf_zds/tests/test_backend.py +++ b/src/openforms/registrations/contrib/stuf_zds/tests/test_backend.py @@ -24,7 +24,6 @@ from stuf.tests.factories import StufServiceFactory from ....constants import RegistrationAttribute -from ....service import extract_submission_reference from ..plugin import PartialDate, StufZDSRegistration @@ -1906,22 +1905,12 @@ def test_retried_registration_with_internal_reference(self, m, mock_task): submission = SubmissionFactory.from_components( registration_in_progress=True, needs_on_completion_retry=True, - public_registration_reference="OF-1234", + public_registration_reference="foo-zaak", pre_registration_completed=False, registration_result={"temporary_internal_reference": "OF-1234"}, components_list=[{"key": "dummy"}], ) - m.post( - self.service.soap_service.url, - content=load_mock( - "genereerZaakIdentificatie.xml", - { - "zaak_identificatie": "foo-zaak", - }, - ), - additional_matcher=match_text("genereerZaakIdentificatie_Di02"), - ) m.post( self.service.soap_service.url, content=load_mock("creeerZaak.xml"), @@ -1956,7 +1945,6 @@ def test_retried_registration_with_internal_reference(self, m, mock_task): serializer = plugin.configuration_options(data=form_options) self.assertTrue(serializer.is_valid()) - plugin.pre_register_submission(submission, serializer.validated_data) result = plugin.register_submission(submission, serializer.validated_data) self.assertEqual( result, @@ -1966,7 +1954,7 @@ def test_retried_registration_with_internal_reference(self, m, mock_task): }, ) - xml_doc = xml_from_request_history(m, 1) + xml_doc = xml_from_request_history(m, 0) self.assertSoapXMLCommon(xml_doc) self.assertXPathEqualDict( xml_doc, @@ -2557,18 +2545,6 @@ def test_plugin_optional_fields_missing_status_code(self, m, mock_task): 5, ) - def test_reference_can_be_extracted(self, m): - submission = SubmissionFactory.create( - form__registration_backend="stuf-zds-create-zaak", - completed=True, - registration_success=True, - registration_result={"zaak": "abcd1234"}, - ) - - reference = extract_submission_reference(submission) - - self.assertEqual("abcd1234", reference) - def test_pre_registration_goes_wrong_sets_internal_reference(self, m): submission = SubmissionFactory.from_components( [], @@ -2604,7 +2580,7 @@ def test_pre_registration_goes_wrong_sets_internal_reference(self, m): serializer.is_valid() with patch( - "openforms.submissions.public_references.get_reference_for_submission", + "openforms.submissions.public_references.generate_unique_submission_reference", return_value="OF-TEST!", ): pre_registration(submission.id, PostSubmissionEvents.on_completion) @@ -2618,6 +2594,7 @@ def test_retry_pre_registration_task(self, m): submission = SubmissionFactory.from_components( [], public_registration_reference="OF-TEMP", + completed=True, pre_registration_completed=False, registration_result={"temporary_internal_reference": "OF-TEMP"}, submitted_data={ @@ -2626,6 +2603,14 @@ def test_retry_pre_registration_task(self, m): "coordinaat": [52.36673378967122, 4.893164274470299], }, kvk="12345678", + form__registration_backend="stuf-zds-create-zaak", + form__registration_backend_options={ + "zds_zaaktype_code": "zt-code", + "zds_zaaktype_omschrijving": "zt-omschrijving", + "zds_zaaktype_status_code": "123", + "zds_zaaktype_status_omschrijving": "aaabbc", + "zds_documenttype_omschrijving_inzending": "aaabbc", + }, ) m.post( @@ -2639,18 +2624,7 @@ def test_retry_pre_registration_task(self, m): additional_matcher=match_text("genereerZaakIdentificatie_Di02"), ) - form_options = { - "zds_zaaktype_code": "zt-code", - "zds_zaaktype_omschrijving": "zt-omschrijving", - "zds_zaaktype_status_code": "123", - "zds_zaaktype_status_omschrijving": "aaabbc", - "zds_documenttype_omschrijving_inzending": "aaabbc", - } - plugin = StufZDSRegistration("stuf") - serializer = plugin.configuration_options(data=form_options) - serializer.is_valid() - - plugin.pre_register_submission(submission, serializer.validated_data) + pre_registration(submission.id, PostSubmissionEvents.on_retry) submission.refresh_from_db() diff --git a/src/openforms/registrations/contrib/zgw_apis/plugin.py b/src/openforms/registrations/contrib/zgw_apis/plugin.py index 8ff2182c91..2bdba5347f 100644 --- a/src/openforms/registrations/contrib/zgw_apis/plugin.py +++ b/src/openforms/registrations/contrib/zgw_apis/plugin.py @@ -28,7 +28,7 @@ from openforms.utils.validators import validate_rsin from openforms.variables.utils import get_variables_for_context -from ...base import BasePlugin +from ...base import BasePlugin, PreRegistrationResult from ...constants import REGISTRATION_ATTRIBUTE, RegistrationAttribute from ...exceptions import RegistrationFailed from ...registry import register @@ -308,7 +308,9 @@ def get_zgw_config(options: dict) -> ZGWApiGroupConfig: return zgw @wrap_api_errors - def pre_register_submission(self, submission: "Submission", options: dict) -> None: + def pre_register_submission( + self, submission: "Submission", options: dict + ) -> PreRegistrationResult: """ Create a Zaak, so that we can have a registration ID. @@ -340,12 +342,9 @@ def pre_register_submission(self, submission: "Submission", options: dict) -> No "intermediate.zaak", ) - result = {"zaak": zaak} - submission.registration_result.update(result) - submission.public_registration_reference = self.get_reference_from_result( - result + return PreRegistrationResult( + reference=zaak["identificatie"], data={"zaak": zaak} ) - submission.save() @wrap_api_errors def register_submission(self, submission: Submission, options: dict) -> dict | None: @@ -599,25 +598,6 @@ def register_submission(self, submission: Submission, options: dict) -> dict | N submission.save() return result - def get_reference_from_result(self, result: dict[str, Any]) -> str: - """ - Extract the public submission reference from the result data. - - This method must return a string to be saved on the submission model. - - :arg result: the raw underlying JSONField datastructure. - - .. warning:: - - Technically the combination of (bronorganisatie,identicatie) must be unique, - so if the same identification is generated by different Zaken APIs, - this may cause problems! - """ - # See response of - # https://raw.githubusercontent.com/vng-Realisatie/zaken-api/1.0.0/src/openapi.yaml#operation/zaak_create - zaak = result["zaak"] - return zaak["identificatie"] - @wrap_api_errors def update_payment_status(self, submission: Submission, options: dict): zgw = options["zgw_api_group"] diff --git a/src/openforms/registrations/contrib/zgw_apis/tests/test_backend.py b/src/openforms/registrations/contrib/zgw_apis/tests/test_backend.py index 8615536b0a..7372001617 100644 --- a/src/openforms/registrations/contrib/zgw_apis/tests/test_backend.py +++ b/src/openforms/registrations/contrib/zgw_apis/tests/test_backend.py @@ -25,7 +25,6 @@ ) from ....constants import RegistrationAttribute -from ....service import extract_submission_reference from ..plugin import ZGWRegistration from .factories import ZGWApiGroupConfigFactory @@ -241,7 +240,11 @@ def test_submission_with_zgw_backend_with_natuurlijk_persoon_initiator(self, m): self.install_mocks(m) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) + pre_registration_result = plugin.pre_register_submission( + submission, zgw_form_options + ) + submission.registration_result.update(pre_registration_result.data) + submission.save() result = plugin.register_submission(submission, zgw_form_options) assert result @@ -454,7 +457,11 @@ def test_submission_with_zgw_backend_with_vestiging_and_kvk_initiator(self, m): self.install_mocks(m) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) + pre_registration_result = plugin.pre_register_submission( + submission, zgw_form_options + ) + submission.registration_result.update(pre_registration_result.data) + submission.save() result = plugin.register_submission(submission, zgw_form_options) assert result @@ -634,6 +641,12 @@ def test_submission_with_zgw_backend_with_kvk_only_initiator(self, m): kvk="12345678", form__product__price=Decimal("0"), form__payment_backend="demo", + registration_result={ + "zaak": { + "url": "https://zaken.nl/api/v1/zaken/1", + "zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1", + } + }, ) SubmissionFileAttachmentFactory.create(submission_step=submission.steps[0]) zgw_form_options = dict( @@ -647,12 +660,10 @@ def test_submission_with_zgw_backend_with_kvk_only_initiator(self, m): self.install_mocks(m) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) plugin.register_submission(submission, zgw_form_options) - self.assertEqual(len(m.request_history), 9) + self.assertEqual(len(m.request_history), 8) ( - create_zaak, create_pdf_document, relate_pdf_document, get_roltypen, @@ -725,7 +736,11 @@ def test_submission_with_zgw_backend_with_vestiging_initiator_kvk_only(self, m): self.install_mocks(m) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) + pre_registration_result = plugin.pre_register_submission( + submission, zgw_form_options + ) + submission.registration_result.update(pre_registration_result.data) + submission.save() result = plugin.register_submission(submission, zgw_form_options) assert result @@ -906,6 +921,12 @@ def test_submission_with_registrator(self, m): kvk="12345678", form__product__price=Decimal("0"), form__payment_backend="demo", + registration_result={ + "zaak": { + "url": "https://zaken.nl/api/v1/zaken/1", + "zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1", + } + }, ) RegistratorInfoFactory.create(submission=submission, value="123456782") zgw_form_options = dict( @@ -937,15 +958,13 @@ def test_submission_with_registrator(self, m): ) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) result = plugin.register_submission(submission, zgw_form_options) assert result self.assertIn("medewerker_rol", result) - self.assertEqual(len(m.request_history), 9) + self.assertEqual(len(m.request_history), 8) ( - create_zaak, create_pdf_document, relate_pdf_document, get_roltypen, @@ -973,7 +992,14 @@ def test_submission_with_registrator(self, m): def test_submission_roltype_initiator_not_found(self, m): submission = SubmissionFactory.create( - completed_not_preregistered=True, with_report=True + completed=True, + with_report=True, + registration_result={ + "zaak": { + "url": "https://zaken.nl/api/v1/zaken/1", + "zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1", + } + }, ) zgw_form_options = dict( zgw_api_group=self.zgw_group, @@ -997,7 +1023,6 @@ def test_submission_roltype_initiator_not_found(self, m): ) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) result = plugin.register_submission(submission, zgw_form_options) assert result @@ -1008,25 +1033,22 @@ def test_retried_registration_with_internal_reference(self, m): Assert that the internal reference is included in the "kenmerken". """ submission = SubmissionFactory.from_components( - completed=True, - registration_in_progress=True, + completed_not_preregistered=True, needs_on_completion_retry=True, public_registration_reference="OF-1234", components_list=[{"key": "dummy"}], - ) - 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", - doc_vertrouwelijkheidaanduiding="openbaar", + form__registration_backend="zgw-create-zaak", + form__registration_backend_options={ + "zgw_api_group": self.zgw_group.pk, + "zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1", + "informatieobjecttype": "https://catalogi.nl/api/v1/informatieobjecttypen/1", + "organisatie_rsin": "000000000", + "vertrouwelijkheidaanduiding": "openbaar", + }, ) self.install_mocks(m) - plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) - plugin.register_submission(submission, zgw_form_options) + pre_registration(submission.id, PostSubmissionEvents.on_retry) create_zaak = m.request_history[0] create_zaak_body = create_zaak.json() @@ -1070,7 +1092,14 @@ def test_register_and_update_paid_product(self, m): ) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) + pre_registration_result = plugin.pre_register_submission( + submission, zgw_form_options + ) + + submission.public_registration_reference = pre_registration_result.reference + submission.registration_result.update(pre_registration_result.data) + submission.save() + result = plugin.register_submission(submission, zgw_form_options) assert result @@ -1092,24 +1121,6 @@ def test_register_and_update_paid_product(self, m): patch_zaak_body["laatsteBetaaldatum"], "2021-01-01T10:00:00+00:00" ) - def test_reference_can_be_extracted(self, m): - result = { - "zaak": { - "url": "https://zaken.nl/api/v1/zaken/1", - "identificatie": "abcd1234", - } - } - submission = SubmissionFactory.create( - form__registration_backend="zgw-create-zaak", - completed=True, - registration_success=True, - registration_result=result, - ) - - reference = extract_submission_reference(submission) - - self.assertEqual("abcd1234", reference) - @tag("sentry-334882") def test_submission_with_zgw_backend_override_fields(self, m): """Assert that override of default values for the ZGW backend works""" @@ -1136,6 +1147,12 @@ def test_submission_with_zgw_backend_override_fields(self, m): }, }, ], + registration_result={ + "zaak": { + "url": "https://zaken.nl/api/v1/zaken/1", + "zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1", + } + }, ) zgw_form_options = dict( zgw_api_group=self.zgw_group, @@ -1159,12 +1176,10 @@ def test_submission_with_zgw_backend_override_fields(self, m): self.install_mocks(m) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) plugin.register_submission(submission, zgw_form_options) - self.assertEqual(len(m.request_history), 11) + self.assertEqual(len(m.request_history), 10) ( - create_zaak, create_pdf_document, relate_pdf_document, get_roltypen, @@ -1254,7 +1269,11 @@ def test_zgw_backend_default_author(self, m): self.install_mocks(m) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) + pre_registration_result = plugin.pre_register_submission( + submission, zgw_form_options + ) + submission.registration_result.update(pre_registration_result.data) + submission.save() plugin.register_submission(submission, zgw_form_options) self.assertEqual(len(m.request_history), 9) @@ -1318,6 +1337,12 @@ def test_zgw_backend_defaults_empty_string(self, m): submission_step__submission__with_report=True, file_name="attachment1.jpg", form_key="field1", + submission_step__submission__registration_result={ + "zaak": { + "url": "https://zaken.nl/api/v1/zaken/1", + "zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1", + } + }, ) submission = attachment.submission_step.submission zgw_form_options = dict( @@ -1329,12 +1354,10 @@ def test_zgw_backend_defaults_empty_string(self, m): self.install_mocks(m) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) plugin.register_submission(submission, zgw_form_options) - self.assertEqual(len(m.request_history), 9) + self.assertEqual(len(m.request_history), 8) ( - create_zaak, create_pdf_document, relate_pdf_document, get_roltypen, @@ -1424,7 +1447,14 @@ def test_document_size_argument_present(self, m): self.install_mocks(m) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) + pre_registration_result = plugin.pre_register_submission( + submission, zgw_form_options + ) + + submission.public_registration_reference = pre_registration_result.reference + submission.registration_result.update(pre_registration_result.data) + submission.save() + plugin.register_submission(submission, zgw_form_options) ( @@ -1598,6 +1628,12 @@ def get_create_json_for_zaakobject(req, ctx): bsn="111222333", language_code="en", form_definition_kwargs={"slug": "test"}, + registration_result={ + "zaak": { + "url": "https://zaken.nl/api/v1/zaken/1", + "zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1", + } + }, ) zgw_form_options = dict( zgw_api_group=self.zgw_group, @@ -1612,7 +1648,6 @@ def get_create_json_for_zaakobject(req, ctx): self.install_mocks(m) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) result = plugin.register_submission(submission, zgw_form_options) assert result @@ -1703,6 +1738,12 @@ def test_submission_with_multiple_eigenschappen_creation(self, m): }, language_code="en", form_definition_kwargs={"slug": "test-eigenschappen"}, + registration_result={ + "zaak": { + "url": "https://zaken.nl/api/v1/zaken/1", + "zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1", + } + }, ) zgw_form_options = dict( zgw_api_group=self.zgw_group, @@ -1814,7 +1855,6 @@ def test_submission_with_multiple_eigenschappen_creation(self, m): ) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) result = plugin.register_submission(submission, zgw_form_options) assert result @@ -1900,6 +1940,12 @@ def test_submission_with_nested_component_columns_and_eigenschap(self, m): }, language_code="en", form_definition_kwargs={"slug": "test-eigenschappen"}, + registration_result={ + "zaak": { + "url": "https://zaken.nl/api/v1/zaken/1", + "zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1", + } + }, ) zgw_form_options = dict( zgw_api_group=self.zgw_group, diff --git a/src/openforms/registrations/contrib/zgw_apis/tests/test_zgw_api_config.py b/src/openforms/registrations/contrib/zgw_apis/tests/test_zgw_api_config.py index 6052c731af..b1126c73c0 100644 --- a/src/openforms/registrations/contrib/zgw_apis/tests/test_zgw_api_config.py +++ b/src/openforms/registrations/contrib/zgw_apis/tests/test_zgw_api_config.py @@ -313,7 +313,14 @@ def test_the_right_api_is_used(self, m): self.install_mocks(m) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) + pre_registration_result = plugin.pre_register_submission( + submission, zgw_form_options + ) + + submission.public_registration_reference = pre_registration_result.reference + submission.registration_result.update(pre_registration_result.data) + submission.save() + plugin.register_submission(submission, zgw_form_options) history = m.request_history @@ -343,7 +350,14 @@ def test_per_form_overwrites(self, m): self.install_mocks(m) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) + pre_registration_result = plugin.pre_register_submission( + submission, zgw_form_options + ) + + submission.public_registration_reference = pre_registration_result.reference + submission.registration_result.update(pre_registration_result.data) + submission.save() + plugin.register_submission(submission, zgw_form_options) self.assertEqual(len(m.request_history), 9) @@ -423,7 +437,14 @@ def test_uses_field_overwrites_for_documents(self, m): self.install_mocks(m) plugin = ZGWRegistration("zgw") - plugin.pre_register_submission(submission, zgw_form_options) + pre_registration_result = plugin.pre_register_submission( + submission, zgw_form_options + ) + + submission.public_registration_reference = pre_registration_result.reference + submission.registration_result.update(pre_registration_result.data) + submission.save() + plugin.register_submission(submission, zgw_form_options) self.assertEqual(len(m.request_history), 9) diff --git a/src/openforms/registrations/exceptions.py b/src/openforms/registrations/exceptions.py index a2f60eb28a..c87d3268a9 100644 --- a/src/openforms/registrations/exceptions.py +++ b/src/openforms/registrations/exceptions.py @@ -2,7 +2,3 @@ class RegistrationFailed(Exception): def __init__(self, *args, **kwargs): self.response = kwargs.pop("response", None) super().__init__(*args, **kwargs) - - -class NoSubmissionReference(Exception): - pass diff --git a/src/openforms/registrations/service.py b/src/openforms/registrations/service.py index ba1f081ddd..22b8c2ae89 100644 --- a/src/openforms/registrations/service.py +++ b/src/openforms/registrations/service.py @@ -1,53 +1,16 @@ import logging -from openforms.submissions.constants import RegistrationStatuses from openforms.submissions.models import Submission from .base import BasePlugin -from .exceptions import NoSubmissionReference __all__ = [ - "NoSubmissionReference", - "extract_submission_reference", "get_registration_plugin", ] logger = logging.getLogger(__name__) -def extract_submission_reference(submission: Submission) -> str: - """ - Extract the (unique) and public submission reference from the submission result. - - :arg submission: :class:`Submission` instance to extract the reference for - :raises NoSubmissionReference: if no reference could be extracted. - """ - backend = submission.registration_backend - - if not backend: - raise NoSubmissionReference( - "There is no backend configured for the form, nothing to extract." - ) - - registry = backend._meta.get_field("backend").registry - - if not submission.registration_status == RegistrationStatuses.success: - raise NoSubmissionReference( - "Submission registration did not succeed, there is no result data to process." - ) - - if not (result := submission.registration_result): - raise NoSubmissionReference("No result data saved, nothing to extract.") - - # figure out which plugin to call for extraction - plugin = registry[backend.backend] - - try: - return plugin.get_reference_from_result(result) - except Exception as exc: - raise NoSubmissionReference("Extraction failed") from exc - - def get_registration_plugin(submission: Submission) -> BasePlugin | None: backend = submission.registration_backend diff --git a/src/openforms/registrations/tasks.py b/src/openforms/registrations/tasks.py index ab8cfa6251..bf3c2573d3 100644 --- a/src/openforms/registrations/tasks.py +++ b/src/openforms/registrations/tasks.py @@ -80,7 +80,7 @@ def pre_registration(submission_id: int, event: PostSubmissionEvents) -> None: submission.save() try: - registration_plugin.pre_register_submission( + result = registration_plugin.pre_register_submission( submission, options_serializer.validated_data ) except Exception as exc: @@ -93,6 +93,20 @@ def pre_registration(submission_id: int, event: PostSubmissionEvents) -> None: raise exc return + if not result.reference: + set_submission_reference(submission) + else: + submission.public_registration_reference = result.reference + + if not submission.registration_result: + submission.registration_result = {} + + if "traceback" in submission.registration_result: + del submission.registration_result["traceback"] + + if result.data is not None: + submission.registration_result.update(result.data) + submission.pre_registration_completed = True submission.save() diff --git a/src/openforms/registrations/tests/test_pre_registration.py b/src/openforms/registrations/tests/test_pre_registration.py index ed88fb979f..498c9575e4 100644 --- a/src/openforms/registrations/tests/test_pre_registration.py +++ b/src/openforms/registrations/tests/test_pre_registration.py @@ -6,6 +6,7 @@ from testfixtures import LogCapture from openforms.config.models import GlobalConfiguration +from openforms.registrations.base import PreRegistrationResult from openforms.registrations.contrib.zgw_apis.tests.factories import ( ZGWApiGroupConfigFactory, ) @@ -58,7 +59,8 @@ def test_if_preregistration_complete_retry_doesnt_repeat_it(self): ) with patch( - "openforms.registrations.contrib.zgw_apis.plugin.ZGWRegistration.pre_register_submission" + "openforms.registrations.contrib.zgw_apis.plugin.ZGWRegistration.pre_register_submission", + return_value=PreRegistrationResult(reference="OF-TRALALA"), ) as mock_pre_register: pre_registration(submission.id, PostSubmissionEvents.on_completion) pre_registration(submission.id, PostSubmissionEvents.on_retry) @@ -239,7 +241,8 @@ def test_retry_keeps_track_of_internal_reference(self): pre_registration(submission.id, PostSubmissionEvents.on_completion) with patch( - "openforms.registrations.contrib.zgw_apis.plugin.ZGWRegistration.pre_register_submission" + "openforms.registrations.contrib.zgw_apis.plugin.ZGWRegistration.pre_register_submission", + return_value=PreRegistrationResult(reference="OF-IM-FINAL"), ): pre_registration(submission.id, PostSubmissionEvents.on_retry) @@ -278,3 +281,53 @@ def test_retry_after_too_many_attempts_skips(self, m_get_solo): "Skipping pre-registration for submission '%s' because it retried and failed too many times.", logs.records[-1].msg, ) + + def test_update_registration_result_after_pre_registration(self): + zgw_group = ZGWApiGroupConfigFactory.create() + submission = SubmissionFactory.create( + form__registration_backend="zgw-create-zaak", + form__registration_backend_options={"zgw_api_group": zgw_group.pk}, + completed_not_preregistered=True, + ) + + with patch( + "openforms.registrations.contrib.zgw_apis.plugin.ZGWRegistration.pre_register_submission", + return_value=PreRegistrationResult( + reference="ZAAK-TRALALA", data={"zaak": {"ohlalla": "a property!"}} + ), + ): + pre_registration(submission.id, PostSubmissionEvents.on_completion) + + submission.refresh_from_db() + self.assertEqual(submission.public_registration_reference, "ZAAK-TRALALA") + self.assertEqual( + submission.registration_result, {"zaak": {"ohlalla": "a property!"}} + ) + + @patch("openforms.plugins.registry.GlobalConfiguration.get_solo") + def test_traceback_removed_from_result_after_success(self, m_get_solo): + zgw_group = ZGWApiGroupConfigFactory.create() + submission = SubmissionFactory.create( + form__registration_backend="zgw-create-zaak", + form__registration_backend_options={"zgw_api_group": zgw_group.pk}, + completed_not_preregistered=True, + registration_attempts=1, + registration_result={"traceback": "An error, how sad."}, + ) + + TEST_NUM_ATTEMPTS = 3 + m_get_solo.return_value = GlobalConfiguration( + registration_attempt_limit=TEST_NUM_ATTEMPTS, + ) + + with patch( + "openforms.registrations.contrib.zgw_apis.plugin.ZGWRegistration.pre_register_submission", + return_value=PreRegistrationResult( + reference="OF-TRALALAL", data={"something": "irrelevant"} + ), + ): + pre_registration(submission.id, PostSubmissionEvents.on_retry) + + submission.refresh_from_db() + + self.assertNotIn("traceback", submission.registration_result) diff --git a/src/openforms/registrations/tests/test_reference_extraction.py b/src/openforms/registrations/tests/test_reference_extraction.py deleted file mode 100644 index 234c89e649..0000000000 --- a/src/openforms/registrations/tests/test_reference_extraction.py +++ /dev/null @@ -1,118 +0,0 @@ -""" -Test the submission reference extraction behaviour, independent from the plugin. -""" - -from django.test import TestCase - -from rest_framework import serializers - -from openforms.forms.models import FormRegistrationBackend -from openforms.submissions.tests.factories import SubmissionFactory - -from ..base import BasePlugin -from ..registry import Registry -from ..service import NoSubmissionReference, extract_submission_reference -from .utils import patch_registry - -# Set up a registry with plugins for the tests - -register = Registry() - -model_field = FormRegistrationBackend._meta.get_field("backend") - - -@register("plugin1") -class Plugin1(BasePlugin): - configuration_options = serializers.Serializer - - def register_submission(self, submission, options): - pass - - def get_reference_from_result(self, result) -> str: - return result.get("reference") - - -@register("plugin2") -class Plugin2(BasePlugin): - configuration_options = serializers.Serializer - - def register_submission(self, submission, options): - pass - - def get_reference_from_result(self, result: dict) -> str: - return str(result["reference"]) - - -# Define the actual test cases - - -class NoExtractableSubmissionReferenceTests(TestCase): - def test_submission_without_registration_backend(self): - submission = SubmissionFactory.create() - - with self.assertRaises(NoSubmissionReference): - extract_submission_reference(submission) - - def test_submission_not_completed(self): - submission = SubmissionFactory.create( - completed=False, form__registration_backend="plugin1" - ) - - with patch_registry(model_field, register): - with self.assertRaises(NoSubmissionReference): - extract_submission_reference(submission) - - def test_submission_registration_not_completed(self): - submissions = [ - SubmissionFactory.create( - registration_failed=True, form__registration_backend="plugin1" - ), - SubmissionFactory.create( - registration_pending=True, form__registration_backend="plugin1" - ), - SubmissionFactory.create( - registration_in_progress=True, form__registration_backend="plugin1" - ), - ] - - with patch_registry(model_field, register): - for submission in submissions: - with self.subTest(registration_status=submission.registration_status): - with self.assertRaises(NoSubmissionReference): - extract_submission_reference(submission) - - def test_submission_registered_but_no_registration_result(self): - submission = SubmissionFactory.create( - registration_success=True, - registration_result={}, - form__registration_backend="plugin1", - ) - - with patch_registry(model_field, register): - with self.assertRaises(NoSubmissionReference): - extract_submission_reference(submission) - - -class ExtractableSubmissionReferenceTests(TestCase): - def test_completed_submission_without_result_serializer(self): - submission = SubmissionFactory.create( - registration_success=True, - registration_result={"reference": "some-unique-reference"}, - form__registration_backend="plugin1", - ) - - with patch_registry(model_field, register): - reference = extract_submission_reference(submission) - - self.assertEqual(reference, "some-unique-reference") - - def test_completed_but_extraction_errors(self): - submission = SubmissionFactory.create( - registration_success=True, - registration_result={"foo": "bar"}, - form__registration_backend="plugin2", - ) - - with patch_registry(model_field, register): - with self.assertRaises(NoSubmissionReference): - extract_submission_reference(submission) diff --git a/src/openforms/registrations/tests/test_registration_hook.py b/src/openforms/registrations/tests/test_registration_hook.py index 91a937331d..b18b43f2e9 100644 --- a/src/openforms/registrations/tests/test_registration_hook.py +++ b/src/openforms/registrations/tests/test_registration_hook.py @@ -76,9 +76,6 @@ def register_submission(self, submission, options): return {"result": "ok"} - def get_reference_from_result(self, result: dict) -> None: - pass - # call the hook for the submission, while patching the model field registry model_field = FormRegistrationBackend._meta.get_field("backend") with patch_registry(model_field, register): @@ -108,9 +105,6 @@ def register_submission(self, submission, options): err = ZeroDivisionError("Can't divide by zero") raise RegistrationFailed("zerodiv") from err - def get_reference_from_result(self, result: dict) -> None: - pass - # call the hook for the submission, while patching the model field registry model_field = FormRegistrationBackend._meta.get_field("backend") with ( @@ -156,9 +150,6 @@ def register_submission(self, submission, options): # plugin errors with unexected exception (= not converted into RegistrationFailed) raise ZeroDivisionError("Can't divide by zero") - def get_reference_from_result(self, result: dict) -> None: - pass - # call the hook for the submission, while patching the model field registry model_field = FormRegistrationBackend._meta.get_field("backend") with ( @@ -204,9 +195,6 @@ def register_submission(self, submission, options): err = ZeroDivisionError("Can't divide by zero") raise RegistrationFailed("zerodiv") from err - def get_reference_from_result(self, result: dict) -> None: - pass - # call the hook for the submission, while patching the model field registry model_field = FormRegistrationBackend._meta.get_field("backend") @@ -284,9 +272,6 @@ class Plugin(BasePlugin): def register_submission(self, submission, options): pass - def get_reference_from_result(self, result: dict) -> None: - pass - mock_get_solo.return_value = GlobalConfiguration( plugin_configuration={"registrations": {"callback": {"enabled": False}}} ) @@ -368,9 +353,6 @@ class FailsPlugin(BasePlugin): def register_submission(self, submission, options): raise RegistrationFailed("fake failure") - def get_reference_from_result(self, result: dict) -> None: - pass - mock_get_solo.return_value = GlobalConfiguration( registration_attempt_limit=TEST_NUM_ATTEMPTS, plugin_configuration={"registrations": {"callback": {"enabled": True}}}, diff --git a/src/openforms/registrations/tests/test_registry.py b/src/openforms/registrations/tests/test_registry.py index 96a4552a20..8e35111b14 100644 --- a/src/openforms/registrations/tests/test_registry.py +++ b/src/openforms/registrations/tests/test_registry.py @@ -17,9 +17,6 @@ class Plugin(BasePlugin): def register_submission(self, submission, options): pass - def get_reference_from_result(self, result: dict) -> None: - pass - class NoConfigPlugin(BasePlugin): verbose_name = "some human readable label" @@ -28,9 +25,6 @@ class NoConfigPlugin(BasePlugin): def register_submission(self, submission, options): pass - def get_reference_from_result(self, result: dict) -> None: - pass - class RegistryTests(SimpleTestCase): def test_register_function(self): diff --git a/src/openforms/submissions/public_references.py b/src/openforms/submissions/public_references.py index 70495c0da8..26b06ab65f 100644 --- a/src/openforms/submissions/public_references.py +++ b/src/openforms/submissions/public_references.py @@ -34,7 +34,7 @@ def set_submission_reference(submission: Submission) -> str | None: ) and save_attempts < MAX_NUM_ATTEMPTS: try: with transaction.atomic(): - reference = get_reference_for_submission(submission) + reference = generate_unique_submission_reference() submission.public_registration_reference = reference submission.save(update_fields=["public_registration_reference"]) except IntegrityError as error: @@ -58,26 +58,6 @@ def set_submission_reference(submission: Submission) -> str | None: ) -def get_reference_for_submission(submission: Submission) -> str: - # Circular import - from openforms.registrations.service import ( - NoSubmissionReference, - extract_submission_reference, - ) - - try: - reference = extract_submission_reference(submission) - except NoSubmissionReference as exc: - logger.info( - "Could not get the reference from the registration result for submission %d, " - "generating one instead", - submission.id, - exc_info=exc, - ) - reference = generate_unique_submission_reference() - return reference - - def get_random_reference() -> str: # 32 characters with length 6 -> 32^6 possible combinations. # that's roughly one billion combinations before we run out of options. diff --git a/src/openforms/submissions/tests/test_post_submission_event.py b/src/openforms/submissions/tests/test_post_submission_event.py index ae7c6fa735..a62cec967a 100644 --- a/src/openforms/submissions/tests/test_post_submission_event.py +++ b/src/openforms/submissions/tests/test_post_submission_event.py @@ -59,7 +59,7 @@ def test_submission_completed_cosign_and_payment_not_needed(self): "openforms.registrations.contrib.email.plugin.EmailRegistration.register_submission" ) as mock_registration, patch( - "openforms.submissions.public_references.get_reference_for_submission", + "openforms.submissions.public_references.generate_unique_submission_reference", return_value="OF-TEST!", ), patch( @@ -130,7 +130,7 @@ def test_submission_completed_cosign_needed(self): "openforms.registrations.contrib.email.plugin.EmailRegistration.register_submission" ) as mock_registration, patch( - "openforms.submissions.public_references.get_reference_for_submission", + "openforms.submissions.public_references.generate_unique_submission_reference", return_value="OF-TEST!", ), patch( @@ -205,7 +205,7 @@ def test_submission_completed_payment_needed(self): "openforms.registrations.contrib.email.plugin.EmailRegistration.register_submission" ) as mock_registration, patch( - "openforms.submissions.public_references.get_reference_for_submission", + "openforms.submissions.public_references.generate_unique_submission_reference", return_value="OF-TEST!", ), patch( @@ -292,7 +292,7 @@ def test_submission_completed_payment_and_cosign_needed(self): "openforms.registrations.contrib.email.plugin.EmailRegistration.register_submission" ) as mock_registration, patch( - "openforms.submissions.public_references.get_reference_for_submission", + "openforms.submissions.public_references.generate_unique_submission_reference", return_value="OF-TEST!", ), patch( diff --git a/src/openforms/submissions/tests/test_submission_completion.py b/src/openforms/submissions/tests/test_submission_completion.py index 36422c16f9..0f215df822 100644 --- a/src/openforms/submissions/tests/test_submission_completion.py +++ b/src/openforms/submissions/tests/test_submission_completion.py @@ -730,9 +730,6 @@ class MockPlugin(BasePlugin): def register_submission(self, *args, **kwargs): mock_calls.append((args, kwargs)) - def get_reference_from_result(self, *args, **kwargs): - pass - backend_field = FormRegistrationBackendFactory._meta.model._meta.get_field( "backend" ) diff --git a/src/openforms/submissions/tests/test_tasks_registration.py b/src/openforms/submissions/tests/test_tasks_registration.py index d6cb2ba338..8b5ebdf5c5 100644 --- a/src/openforms/submissions/tests/test_tasks_registration.py +++ b/src/openforms/submissions/tests/test_tasks_registration.py @@ -10,26 +10,6 @@ class ObtainSubmissionReferenceTests(TestCase): - @patch( - "openforms.submissions.public_references.generate_unique_submission_reference" - ) - def test_source_reference_from_registration_result(self, mock_generate): - """ - Check that a reference is sourced from the registration result if it's available. - """ - submission = SubmissionFactory.create( - form__registration_backend="zgw-create-zaak", - completed=True, - registration_success=True, - registration_result={"zaak": {"identificatie": "AEY64"}}, - ) - - set_submission_reference(submission) - - submission.refresh_from_db() - self.assertEqual(submission.public_registration_reference, "AEY64") - mock_generate.assert_not_called() - def test_reference_generator_checks_for_used_references(self): RANDOM_STRINGS = ["UNIQUE", "OTHER"] SubmissionFactory.create( diff --git a/src/openforms/template/tests/test_templatetags.py b/src/openforms/template/tests/test_templatetags.py index 87a6b69447..604a1ceceb 100644 --- a/src/openforms/template/tests/test_templatetags.py +++ b/src/openforms/template/tests/test_templatetags.py @@ -17,9 +17,6 @@ class TestPlugin(BasePlugin): def register_submission(self, submission, options): pass - def get_reference_from_result(self, result: dict) -> None: - pass - def get_custom_templatetags_libraries(self) -> list[str]: return ["openforms.template.tests.templatetags.a_test_tag"]