Skip to content

Commit

Permalink
Merge pull request #4892 from open-formulieren/cleanup/3283-remove-de…
Browse files Browse the repository at this point in the history
…precated-formstep-logic

💥 Remove conversion of form step URL to form step UUID
  • Loading branch information
sergei-maertens authored Dec 9, 2024
2 parents a25d84b + 68a21bb commit 48773c8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 44 deletions.
7 changes: 7 additions & 0 deletions docs/installation/upgrade-300.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============================================================

Expand Down
2 changes: 2 additions & 0 deletions pyright.pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions src/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 12 additions & 34 deletions src/openforms/forms/api/serializers/logic/action_serializers.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
{
Expand All @@ -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(
{
Expand All @@ -281,4 +259,4 @@ def validate(self, data: dict) -> dict:
code="blank",
)

return data
return attrs
1 change: 0 additions & 1 deletion src/openforms/forms/tests/e2e_tests/test_logic_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def assertState():
rule.actions[0],
{
"component": "field1",
"form_step": "",
"action": {
"type": "property",
"property": {"value": "validate.required", "type": "bool"},
Expand Down
3 changes: 1 addition & 2 deletions src/openforms/forms/tests/test_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 48773c8

Please sign in to comment.