Skip to content

Commit

Permalink
✨ [#4908] Add required properties to json options serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorvanwijk committed Dec 20, 2024
1 parent fd18855 commit 34ab315
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/openforms/registrations/contrib/json/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ class JSONOptionsSerializer(JsonSchemaSerializerMixin, serializers.Serializer):
queryset=Service.objects.all(),
label=_("Service"),
help_text=_("Which service to use."),
required=True,
)
# TODO-4098: show the complete API endpoint as a (tooltip) hint after user entry? Might be a front-end thing...
# TODO-4098: show the complete API endpoint as a (tooltip) hint after user entry?
# Might be a front-end thing...
relative_api_endpoint = serializers.CharField(
max_length=255,
label=_("Relative API endpoint"),
help_text=_("The API endpoint to send the data to (relative to the service API root)."),
allow_blank=True,
required=False,
)
form_variables = serializers.ListField(
child=FormioVariableKeyField(max_length=50),
label=_("Form variable key list"),
help_text=_(
"A comma-separated list of form variables (can also include static variables) to use."
)
help_text=_("A list of form variables (can also include static variables) to use."),
required=True,
)


Expand Down
9 changes: 6 additions & 3 deletions src/openforms/registrations/contrib/json/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class JSONRegistration(BasePlugin):

def register_submission(self, submission: Submission, options: JSONOptions) -> None:
# TODO-4908: the email plugin works with a EmailConfig singleton model. Is that useful here?
# Doesn't look like it. Seems to be used as a model for default configuration options, which
# which wouldn't really be useful for this plugin

# TODO-4908: any other form field types that need 'special attention'?

Expand All @@ -40,8 +42,9 @@ def register_submission(self, submission: Submission, options: JSONOptions) -> N
variable.key: variable.initial_value for variable in static_variables
}

# TODO-4908: what should the behaviour be when a form
# variable is not in the data or static variables?
# TODO-4908: what should the behaviour be when a form variable is not in the data or static variables?
# Raising an error probably a good idea, the form variable is currently just set to None in the
# resulting values dict
# Update values dict with relevant form data
values.update({
form_variable: submission.data.get(
Expand All @@ -58,7 +61,7 @@ def register_submission(self, submission: Submission, options: JSONOptions) -> N
# TODO-4098: is the service type relevant here?
with build_client(service) as client:
response = client.post(
options["relative_api_endpoint"],
options.get("relative_api_endpoint", ""),
json=json,
headers={"Content-Type": "application/json"},
)
Expand Down

0 comments on commit 34ab315

Please sign in to comment.