Skip to content

Commit

Permalink
♻️ Refactor serializer implementation
Browse files Browse the repository at this point in the history
Make the branching/feature flag more obvious. This allows
additional validations to be added without accidentally
shortcutting because of the feature flag.
  • Loading branch information
sergei-maertens committed Apr 8, 2024
1 parent 5653b51 commit 1d7e747
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/openforms/submissions/api/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ def validate_contains_blocked_steps(self, value):
)

def validate(self, attrs: dict):
self._run_formio_validation()
return attrs

def _run_formio_validation(self) -> None:
# Check feature flag to opt out of formio validation first.
config = GlobalConfiguration.get_solo()
assert isinstance(config, GlobalConfiguration)
if not config.enable_backend_formio_validation:
return attrs
return

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

formio_validation_errors = []

data = submission.data
Expand All @@ -80,8 +84,6 @@ def validate(self, attrs: dict):
if any(formio_validation_errors):
raise serializers.ValidationError({"steps": formio_validation_errors})

return attrs

def save(self, **kwargs):
submission = self.context["submission"]
submission.privacy_policy_accepted = True
Expand Down

0 comments on commit 1d7e747

Please sign in to comment.