Skip to content

Commit

Permalink
🚩 Add feature flag to disable formio validation in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Apr 8, 2024
1 parent 94e1749 commit 5653b51
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/openforms/config/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class GlobalConfigurationAdmin(TranslationAdmin, SingletonModelAdmin):
"enable_demo_plugins",
"allow_empty_initiator",
"payment_order_id_prefix",
"enable_backend_formio_validation",
),
},
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.11 on 2024-04-08 09:38

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("config", "0055_remove_globalconfiguration_enable_react_formio_builder"),
]

operations = [
migrations.AddField(
model_name="globalconfiguration",
name="enable_backend_formio_validation",
field=models.BooleanField(
default=True, verbose_name="enabled backend formio validation"
),
),
]
5 changes: 5 additions & 0 deletions src/openforms/config/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ class GlobalConfiguration(SingletonModel):
help_text=_("When enabled, information about the used SDK is displayed."),
)

enable_backend_formio_validation = models.BooleanField(
_("enabled backend formio validation"),
default=True,
)

# Removing data configurations
successful_submissions_removal_limit = models.PositiveIntegerField(
_("successful submission removal limit"),
Expand Down
6 changes: 6 additions & 0 deletions src/openforms/submissions/api/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from rest_framework import serializers

from openforms.api.utils import mark_experimental
from openforms.config.models import GlobalConfiguration
from openforms.formio.service import build_serializer

from ..form_logic import check_submission_logic
Expand Down Expand Up @@ -47,6 +48,11 @@ def validate_contains_blocked_steps(self, value):
)

def validate(self, attrs: dict):
config = GlobalConfiguration.get_solo()
assert isinstance(config, GlobalConfiguration)
if not config.enable_backend_formio_validation:
return attrs

submission: Submission = self.context["submission"]

formio_validation_errors = []
Expand Down
35 changes: 35 additions & 0 deletions src/openforms/submissions/tests/test_submission_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,41 @@ def test_component_level_validation(self):
]
self.assertIn("steps.0.data.firstName", invalid_param_names)

@patch(
"openforms.submissions.api.validation.GlobalConfiguration.get_solo",
return_value=GlobalConfiguration(enable_backend_formio_validation=False),
)
def test_component_level_validation_disabled_via_feature_flag(self, m_solo):
submission = SubmissionFactory.create(
form__generate_minimal_setup=True,
form__formstep__form_definition__configuration={
"components": [
{
"type": "textfield",
"key": "firstName",
"label": "First name",
"validate": {
"required": True,
"maxLength": 20,
},
}
]
},
)
SubmissionStepFactory.create(
submission=submission,
form_step=submission.form.formstep_set.get(),
data={
"firstName": "this value is longer than twenty characters and should not validate"
},
)
self._add_submission_to_session(submission)
endpoint = reverse("api:submission-complete", kwargs={"uuid": submission.uuid})

response = self.client.post(endpoint, {"privacy_policy_accepted": True})

self.assertEqual(response.status_code, status.HTTP_200_OK)

@patch("openforms.submissions.api.mixins.on_post_submission_event")
@freeze_time("2020-12-11T10:53:19+01:00")
def test_complete_submission(self, mock_on_post_submission_event):
Expand Down

0 comments on commit 5653b51

Please sign in to comment.