From 68a21bb6f964395eea2da0758b67da2d86d8a8f6 Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Mon, 9 Dec 2024 09:49:09 +0100 Subject: [PATCH] :boom: [#3283] Remove conversion of form step URL to form step UUID Fully qualified URLs to resolve a form step have been deprecated for a while, since they're not portable across environments with different base URLs. Now the compatibility code is removed too, which may break old exports. --- docs/installation/upgrade-300.rst | 7 +++ pyright.pyproject.toml | 2 + src/openapi.yaml | 7 --- .../serializers/logic/action_serializers.py | 46 +++++-------------- .../forms/tests/e2e_tests/test_logic_tab.py | 1 - .../forms/tests/test_import_export.py | 3 +- 6 files changed, 22 insertions(+), 44 deletions(-) diff --git a/docs/installation/upgrade-300.rst b/docs/installation/upgrade-300.rst index 3dddadc039..82c096d543 100644 --- a/docs/installation/upgrade-300.rst +++ b/docs/installation/upgrade-300.rst @@ -91,6 +91,13 @@ active locale field (``name_nl`` or ``name_en``) during imports. Instead, the ``translations`` key existed. We recommend re-creating the exports on a newer version of Open Forms. +Removal of ``formStep`` reference in form logic +----------------------------------------------- + +The ``formStep`` key was deprecated in favour of ``formStepUuid`` and the conversion +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 /api/v2/location/get-street-name-and-city endpoint ============================================================= diff --git a/pyright.pyproject.toml b/pyright.pyproject.toml index 55892ac49c..4c1a6ed7fd 100644 --- a/pyright.pyproject.toml +++ b/pyright.pyproject.toml @@ -24,6 +24,8 @@ include = [ # Formio tooling "src/openforms/formio/typing/", "src/openforms/formio/formatters/", + # Core forms app + "src/openforms/forms/api/serializers/logic/action_serializers.py", # Payments "src/openforms/payments/models.py", # Interaction with the outside world diff --git a/src/openapi.yaml b/src/openapi.yaml index 813ad744e0..ac2561fa52 100644 --- a/src/openapi.yaml +++ b/src/openapi.yaml @@ -8754,13 +8754,6 @@ components: title: Key of the target variable description: Sleutel van de variabele die aangepast wordt door de actie. Dit veld is verplicht voor de actietypes `variable` - anders is het optioneel. - formStep: - type: string - format: uri - nullable: true - description: De formulierstap die wordt beïnvloed door de actie. Dit veld - is verplicht als het actietype `step-not-applicable` is, anders optioneel. - deprecated: true formStepUuid: type: string format: uuid diff --git a/src/openforms/forms/api/serializers/logic/action_serializers.py b/src/openforms/forms/api/serializers/logic/action_serializers.py index ddf4f1993f..f3266e4709 100644 --- a/src/openforms/forms/api/serializers/logic/action_serializers.py +++ b/src/openforms/forms/api/serializers/logic/action_serializers.py @@ -1,12 +1,9 @@ -import warnings from datetime import date -from django.urls import resolve from django.utils.translation import gettext_lazy as _ from drf_polymorphic.serializers import PolymorphicSerializer from drf_spectacular.utils import extend_schema_serializer -from furl import furl from json_logic.typing import Primitive from rest_framework import serializers @@ -168,18 +165,6 @@ class LogicComponentActionSerializer(serializers.Serializer): ) ), ) - # Deprecated field! form_step_uuid should be used instead - form_step = serializers.URLField( - allow_null=True, - required=False, # validated against the action.type - allow_blank=True, - label=_("form step"), - help_text=_( - "The form step that will be affected by the action. This field is " - "required if the action type is `%(action_type)s`, otherwise optional." - ) - % {"action_type": LogicActionTypes.step_not_applicable}, - ) form_step_uuid = ActionFormStepUUIDField( allow_null=True, required=False, # validated against the action.type @@ -192,27 +177,17 @@ class LogicComponentActionSerializer(serializers.Serializer): ) action = LogicActionPolymorphicSerializer() - def validate(self, data: dict) -> dict: + def validate(self, attrs: dict) -> dict: """ 1. Check that the component is supplied depending on the action type. 2. Check that the value for date variables has the right format """ - action_type = data.get("action", {}).get("type") - action_value = data.get("action", {}).get("value") - component = data.get("component") - form_step = data.get("form_step") - - if form_step and not data.get("form_step_uuid"): - warnings.warn( - "Logic action 'formStep' is deprecated, use 'formStepUuid' instead", - DeprecationWarning, - ) - # normalize to UUID following deprecation of URL reference - match = resolve(furl(form_step).path) - data["form_step_uuid"] = match.kwargs["uuid"] + action_type = attrs.get("action", {}).get("type") + action_value = attrs.get("action", {}).get("value") + component = attrs.get("component") - form_step_uuid = data.get("form_step_uuid") - variable = data.get("variable") + form_step_uuid = attrs.get("form_step_uuid") + variable = attrs.get("variable") if ( action_type @@ -254,7 +229,10 @@ def validate(self, data: dict) -> dict: if form_var.data_type == FormVariableDataTypes.date: try: - date.fromisoformat(action_value) + # type check muted since we handle it at runtime + date.fromisoformat( + action_value # pyright: ignore[reportArgumentType] + ) except (ValueError, TypeError) as ex: raise serializers.ValidationError( { @@ -270,7 +248,7 @@ def validate(self, data: dict) -> dict: if ( action_type and action_type == LogicActionTypes.step_not_applicable - and (not form_step and not form_step_uuid) + and not form_step_uuid ): raise serializers.ValidationError( { @@ -281,4 +259,4 @@ def validate(self, data: dict) -> dict: code="blank", ) - return data + return attrs diff --git a/src/openforms/forms/tests/e2e_tests/test_logic_tab.py b/src/openforms/forms/tests/e2e_tests/test_logic_tab.py index b6847b3b47..4db34d66f3 100644 --- a/src/openforms/forms/tests/e2e_tests/test_logic_tab.py +++ b/src/openforms/forms/tests/e2e_tests/test_logic_tab.py @@ -77,7 +77,6 @@ def assertState(): rule.actions[0], { "component": "field1", - "form_step": "", "action": { "type": "property", "property": {"value": "validate.required", "type": "bool"}, diff --git a/src/openforms/forms/tests/test_import_export.py b/src/openforms/forms/tests/test_import_export.py index dd5b178026..d0cad6ee0b 100644 --- a/src/openforms/forms/tests/test_import_export.py +++ b/src/openforms/forms/tests/test_import_export.py @@ -873,8 +873,7 @@ def test_import_form_with_disable_step_logic(self): "actions": [ { "action": {"type": "step-not-applicable"}, - # In versions <= 2.0, we used the url of the form step, but this was replaced with the UUID - "form_step": "http://127.0.0.1:8999/api/v2/forms/324cadce-a627-4e3f-b117-37ca232f16b2/steps/a54864c6-c460-48bd-a520-eced60ffb209", + "form_step_uuid": "a54864c6-c460-48bd-a520-eced60ffb209", } ], "form": "http://testserver/api/v2/forms/324cadce-a627-4e3f-b117-37ca232f16b2",