From 75372c008016ddddfa918100f3e158be730d3027 Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Mon, 30 Dec 2024 09:52:04 +0100 Subject: [PATCH] :boom: Remove the cosign information tag patching The tag was introduced in Open Forms 2.3.0 and for backwards compatibility, a data migration and import conversion were added. The former has been removed a long time ago, the latter is being dropped now in OF 3.0. --- docs/installation/upgrade-300.rst | 8 + src/openforms/emails/api/serializers.py | 29 ---- .../forms/tests/test_import_export.py | 154 ------------------ src/openforms/utils/migrations_utils/regex.py | 9 - 4 files changed, 8 insertions(+), 192 deletions(-) delete mode 100644 src/openforms/utils/migrations_utils/regex.py diff --git a/docs/installation/upgrade-300.rst b/docs/installation/upgrade-300.rst index cddd6030e7..14e9aaae1c 100644 --- a/docs/installation/upgrade-300.rst +++ b/docs/installation/upgrade-300.rst @@ -136,6 +136,14 @@ The ``formStep`` key was deprecated in favour of ``formStepUuid`` and the conver code has been removed. This may affect form exports from before Open Forms 2.1.0. We recommend re-creating the exports on a newer version of Open Forms. +Removal of cosign template tag patching +--------------------------------------- + +In Open Forms 2.3, the template tag ``{% cosign_information %}`` was introduced and +automatically added to confirmation templates during import if it was absent. This +automatic patching has now been removed. We recommend re-creating the exports on Open +Forms 2.3 or newer. + Removal of /api/v2/location/get-street-name-and-city endpoint ============================================================= diff --git a/src/openforms/emails/api/serializers.py b/src/openforms/emails/api/serializers.py index af2506a158..07a93036a0 100644 --- a/src/openforms/emails/api/serializers.py +++ b/src/openforms/emails/api/serializers.py @@ -1,9 +1,6 @@ -import re - from rest_framework import serializers from openforms.translations.api.serializers import ModelTranslationsSerializer -from openforms.utils.migrations_utils.regex import add_cosign_info_templatetag from ..models import ConfirmationEmailTemplate @@ -20,29 +17,3 @@ class Meta: "cosign_content", "translations", ) - - def to_internal_value(self, data): - if content := data.get("content"): - data["content"] = self._add_cosign_templatetag(content) - - for language_code, translations in data.get("translations", {}).items(): - if not (translated_content := translations.get("content")): - continue - - data["translations"][language_code]["content"] = ( - self._add_cosign_templatetag(translated_content) - ) - - return super().to_internal_value(data) - - def _add_cosign_templatetag(self, content): - is_import = self.context.get("is_import", False) - - if not is_import: - return content - - match = re.search(r"\{%\s?cosign_information\s?%\}", content) - if not match: - content = add_cosign_info_templatetag(content) - - return content diff --git a/src/openforms/forms/tests/test_import_export.py b/src/openforms/forms/tests/test_import_export.py index 6cdf1ce38e..4a1157d532 100644 --- a/src/openforms/forms/tests/test_import_export.py +++ b/src/openforms/forms/tests/test_import_export.py @@ -922,160 +922,6 @@ def test_export_with_filetype_information(self, m_get_solo): self.assertIsInstance(export_data, dict) - @tag("gh-3182") - def test_import_form_without_cosign_tag(self): - resources = { - "forms": [ - { - "active": True, - "authentication_backends": [], - "is_deleted": False, - "login_required": False, - "maintenance_mode": False, - "name": "Test Form", - "internal_name": "Test Form", - "product": None, - "show_progress_indicator": True, - "slug": "test-form", - "url": "http://testserver/api/v2/forms/324cadce-a627-4e3f-b117-37ca232f16b2", - "uuid": "324cadce-a627-4e3f-b117-37ca232f16b2", - "confirmation_email_template": { - "content": "Some content {% appointment_information %}\n{% payment_information %}", - "subject": "A subject", - "translations": { - "en": { - "content": "Some content {% appointment_information %}\n{% payment_information %}", - "subject": "A subject", - }, - "nl": { - "content": "Wat inhoud {% appointment_information %}\n{% payment_information %}", - "subject": "Een onderwerp", - }, - }, - }, - } - ], - "formSteps": [ - { - "form": "http://testserver/api/v2/forms/324cadce-a627-4e3f-b117-37ca232f16b2", - "form_definition": "http://testserver/api/v2/form-definitions/f0dad93b-333b-49af-868b-a6bcb94fa1b8", - "index": 0, - "slug": "test-step-1", - "uuid": "3ca01601-cd20-4746-bce5-baab47636823", - }, - ], - "formDefinitions": [ - { - "configuration": { - "components": [ - { - "key": "textField", - "type": "textfield", - }, - ] - }, - "name": "Def 1", - "slug": "test-definition-1", - "url": "http://testserver/api/v2/form-definitions/f0dad93b-333b-49af-868b-a6bcb94fa1b8", - "uuid": "f0dad93b-333b-49af-868b-a6bcb94fa1b8", - }, - ], - "formLogic": [], - } - - with zipfile.ZipFile(self.filepath, "w") as zip_file: - for name, data in resources.items(): - zip_file.writestr(f"{name}.json", json.dumps(data)) - - call_command("import", import_file=self.filepath) - form = Form.objects.get(slug="test-form") - - self.assertEqual( - form.confirmation_email_template.content_en, - "Some content {% cosign_information %}\n{% appointment_information %}\n{% payment_information %}", - ) - self.assertEqual( - form.confirmation_email_template.content_nl, - "Wat inhoud {% cosign_information %}\n{% appointment_information %}\n{% payment_information %}", - ) - - @tag("gh-3182") - def test_import_form_without_cosign_tag_in_one_language(self): - resources = { - "forms": [ - { - "active": True, - "authentication_backends": [], - "is_deleted": False, - "login_required": False, - "maintenance_mode": False, - "name": "Test Form", - "internal_name": "Test Form", - "product": None, - "show_progress_indicator": True, - "slug": "test-form", - "url": "http://testserver/api/v2/forms/324cadce-a627-4e3f-b117-37ca232f16b2", - "uuid": "324cadce-a627-4e3f-b117-37ca232f16b2", - "confirmation_email_template": { - "content": "Some content {% appointment_information %}\n{% payment_information %}", - "subject": "A subject", - "translations": { - "en": { - "content": "Some content {% appointment_information %}\n{% payment_information %}", - "subject": "A subject", - }, - "nl": { - "content": "", - "subject": "", - }, - }, - }, - } - ], - "formSteps": [ - { - "form": "http://testserver/api/v2/forms/324cadce-a627-4e3f-b117-37ca232f16b2", - "form_definition": "http://testserver/api/v2/form-definitions/f0dad93b-333b-49af-868b-a6bcb94fa1b8", - "index": 0, - "slug": "test-step-1", - "uuid": "3ca01601-cd20-4746-bce5-baab47636823", - }, - ], - "formDefinitions": [ - { - "configuration": { - "components": [ - { - "key": "textField", - "type": "textfield", - }, - ] - }, - "name": "Def 1", - "slug": "test-definition-1", - "url": "http://testserver/api/v2/form-definitions/f0dad93b-333b-49af-868b-a6bcb94fa1b8", - "uuid": "f0dad93b-333b-49af-868b-a6bcb94fa1b8", - }, - ], - "formLogic": [], - } - - with zipfile.ZipFile(self.filepath, "w") as zip_file: - for name, data in resources.items(): - zip_file.writestr(f"{name}.json", json.dumps(data)) - - call_command("import", import_file=self.filepath) - form = Form.objects.get(slug="test-form") - - self.assertEqual( - form.confirmation_email_template.content_en, - "Some content {% cosign_information %}\n{% appointment_information %}\n{% payment_information %}", - ) - self.assertEqual( - form.confirmation_email_template.content_nl, - "", - ) - def test_import_applies_converters(self): def add_foo(component): component["foo"] = "bar" diff --git a/src/openforms/utils/migrations_utils/regex.py b/src/openforms/utils/migrations_utils/regex.py deleted file mode 100644 index fcb87248ec..0000000000 --- a/src/openforms/utils/migrations_utils/regex.py +++ /dev/null @@ -1,9 +0,0 @@ -import re - - -def add_cosign_info_templatetag(template: str) -> str: - pattern = re.compile( - r"(\{%\s?summary\s?%\}|\{%\s?appointment_information\s?%\}|\{%\s?payment_information\s?%\})" - ) - replacement = r"{% cosign_information %}\n\1" - return pattern.sub(replacement, template, count=1)