diff --git a/src/openforms/config/admin.py b/src/openforms/config/admin.py index d39e618343..ed38c45a9f 100644 --- a/src/openforms/config/admin.py +++ b/src/openforms/config/admin.py @@ -161,6 +161,7 @@ class GlobalConfigurationAdmin(TranslationAdmin, SingletonModelAdmin): "enable_demo_plugins", "allow_empty_initiator", "payment_order_id_prefix", + "enable_backend_formio_validation", ), }, ), diff --git a/src/openforms/config/migrations/0056_globalconfiguration_enable_backend_formio_validation.py b/src/openforms/config/migrations/0056_globalconfiguration_enable_backend_formio_validation.py new file mode 100644 index 0000000000..b34e4f5a45 --- /dev/null +++ b/src/openforms/config/migrations/0056_globalconfiguration_enable_backend_formio_validation.py @@ -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" + ), + ), + ] diff --git a/src/openforms/config/models/config.py b/src/openforms/config/models/config.py index 9dc8abae47..15524e90fd 100644 --- a/src/openforms/config/models/config.py +++ b/src/openforms/config/models/config.py @@ -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"), diff --git a/src/openforms/submissions/api/validation.py b/src/openforms/submissions/api/validation.py index e8c58cdf3c..1e98bb05fb 100644 --- a/src/openforms/submissions/api/validation.py +++ b/src/openforms/submissions/api/validation.py @@ -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 @@ -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 = [] diff --git a/src/openforms/submissions/tests/test_submission_completion.py b/src/openforms/submissions/tests/test_submission_completion.py index c3b0721c6c..1f6c4a2570 100644 --- a/src/openforms/submissions/tests/test_submission_completion.py +++ b/src/openforms/submissions/tests/test_submission_completion.py @@ -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):