Skip to content

Commit

Permalink
👌 [#4980] Process PR feedback
Browse files Browse the repository at this point in the history
* Use json.dumps instead of to_json, as the latter is a private utility from the forms app
* Revise result in register_submission: submission.registration_result automatically gets written with the return value of register_submission, see https://github.com/open-formulieren/open-forms/blob/794bbdae3c62eb4e4ce429661b402b57f24f4605/src/openforms/registrations/tasks.py#L338
* Remove explicit boolean assignments to properties in Variables: this is not necessary in JSX
* Add the json_dump app to the pyright.pyproject.toml, so it is type checked in CI
  • Loading branch information
viktorvanwijk committed Jan 21, 2025
1 parent 343d945 commit 078e410
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions pyright.pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ include = [
# Registrations
"src/openforms/registrations/tasks.py",
"src/openforms/registrations/contrib/email/",
"src/openforms/registrations/contrib/json_dump/",
"src/openforms/registrations/contrib/stuf_zds/options.py",
"src/openforms/registrations/contrib/stuf_zds/plugin.py",
"src/openforms/registrations/contrib/stuf_zds/typing.py",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const Variables = () => {
{...fieldProps}
isMulti
required
closeMenuOnSelect={false}
includeStaticVariables={true}
closeMenuOnSelect
includeStaticVariables
/>
</Field>
</FormRow>
Expand Down
16 changes: 9 additions & 7 deletions src/openforms/registrations/contrib/json_dump/plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
import json
from typing import TypedDict

from django.core.exceptions import SuspiciousOperation
from django.core.serializers.json import DjangoJSONEncoder
Expand All @@ -21,14 +22,18 @@
from .config import JSONDumpOptions, JSONDumpOptionsSerializer


class JSONDumpResult(TypedDict):
api_response: JSONObject


@register("json_dump")
class JSONDumpRegistration(BasePlugin):
verbose_name = _("JSON dump registration")
configuration_options = JSONDumpOptionsSerializer

def register_submission(

Check failure on line 34 in src/openforms/registrations/contrib/json_dump/plugin.py

View workflow job for this annotation

GitHub Actions / Type checking (Pyright)

Method "register_submission" overrides class "BasePlugin" in an incompatible manner   Return type mismatch: base method returns type "dict[Unknown, Unknown] | None", override returns type "JSONDumpResult"     Type "JSONDumpResult" is incompatible with type "dict[Unknown, Unknown] | None"       "JSONDumpResult" is incompatible with "dict[Unknown, Unknown]"       "JSONDumpResult" is incompatible with "None" (reportIncompatibleMethodOverride)
self, submission: Submission, options: JSONDumpOptions
) -> dict:
) -> JSONDumpResult:
state = submission.load_submission_value_variables_state()

all_values: JSONObject = {
Expand Down Expand Up @@ -62,17 +67,14 @@ def register_submission(
# Send to the service
data = json.dumps({"values": values, "schema": schema}, cls=DjangoJSONEncoder)
service = options["service"]
submission.registration_result = result = {}
with build_client(service) as client:
if ".." in (path := options["path"]):
raise SuspiciousOperation("Possible path traversal detected")

res = client.post(path, json=data)
res.raise_for_status()

result["api_response"] = res.json()
result = client.post(path, json=data)
result.raise_for_status()

return result
return {"api_response": result.json()}

def check_config(self) -> None:
# Config checks are not really relevant for this plugin right now
Expand Down

0 comments on commit 078e410

Please sign in to comment.