Skip to content

Commit

Permalink
🚚 [#4908] Rename relative_api_endpoint to path
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorvanwijk committed Jan 21, 2025
1 parent 4233f5c commit 3ee8503
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export default {
enum: [1, 2],
enumNames: ['Service 1', 'Service 2'],
},
relativeApiEndpoint: {
path: {
minLength: 1,
title: 'Relative API endpoint',
type: 'string',
Expand Down Expand Up @@ -769,7 +769,7 @@ export const ConfiguredBackends = {
backend: 'json_dump',
options: {
service: 1,
relativeApiEndpoint: 'example/endpoint',
path: 'example/endpoint',
formVariables: [],
},
},
Expand Down Expand Up @@ -1028,7 +1028,7 @@ export const JSONDump = {
backend: 'json_dump',
options: {
service: 1,
relativeApiEndpoint: 'example/endpoint',
path: 'example/endpoint',
formVariables: [],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from 'components/admin/forms/ValidationErrors';
import {getChoicesFromSchema} from 'utils/json-schema';

import {FormVariablesSelect, RelativeAPIEndpoint, ServiceSelect} from './fields';
import {FormVariablesSelect, Path, ServiceSelect} from './fields';

const JSONDumpOptionsForm = ({name, label, schema, formData, onChange}) => {
const validationErrors = useContext(ValidationErrorContext);
Expand Down Expand Up @@ -48,7 +48,7 @@ const JSONDumpOptionsForm = ({name, label, schema, formData, onChange}) => {
}
initialFormData={{
service: null,
relativeApiEndpoint: '',
path: '',
formVariables: [],
...formData,
}}
Expand All @@ -58,7 +58,7 @@ const JSONDumpOptionsForm = ({name, label, schema, formData, onChange}) => {
<ValidationErrorsProvider errors={relevantErrors}>
<Fieldset>
<ServiceSelect options={serviceOptions} />
<RelativeAPIEndpoint />
<Path />
<FormVariablesSelect options={formVariableOptions} />
</Fieldset>
</ValidationErrorsProvider>
Expand All @@ -79,7 +79,7 @@ JSONDumpOptionsForm.propTypes = {
}).isRequired,
formData: PropTypes.shape({
service: PropTypes.number,
relativeApiEndpoint: PropTypes.string,
path: PropTypes.string,
// TODO-4908: might need to rename this to selectedFormVariables to avoid confusion or even
// naming conflicts
formVariables: PropTypes.arrayOf(PropTypes.string),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import Field from 'components/admin/forms/Field';
import FormRow from 'components/admin/forms/FormRow';
import {TextInput} from 'components/admin/forms/Inputs';

const RelativeAPIEndpoint = () => {
const [fieldProps] = useField('relativeApiEndpoint');
const Path = () => {
const [fieldProps] = useField('path');
return (
<FormRow>
<Field
name="relativeApiEndpoint"
name="path"
label={
<FormattedMessage
description="JSON registration options 'relativeApiEndpoint' label"
defaultMessage="Relative API Endpoint"
description="JSON registration options 'path' label"
defaultMessage="Path"
/>
}
helpText={
<FormattedMessage
description="JSON registration options 'relativeApiEndpoint' helpText"
defaultMessage="Relative endpoint to send the data to (will be added to the root endpoint of the service)."
description="JSON registration options 'path' helpText"
defaultMessage="Path relative to the Service API root"
/>
}
>
Expand All @@ -31,4 +31,4 @@ const RelativeAPIEndpoint = () => {
);
};

export default RelativeAPIEndpoint;
export default Path;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FormVariablesSelect from './FormVariablesSelect';
import RelativeAPIEndpoint from './RelativeAPIEndpoint';
import Path from './Path';
import ServiceSelect from './ServiceSelect';

export {FormVariablesSelect, RelativeAPIEndpoint, ServiceSelect};
export {FormVariablesSelect, Path, ServiceSelect};
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ export const WithJSONDumpRegistrationBackend = {
name: 'JSON dump registration',
options: {
service: 2,
relativeApiEndpoint: 'test',
path: 'test',
formVariables: ['aSingleFile', 'now'],
},
},
Expand Down
14 changes: 5 additions & 9 deletions src/openforms/registrations/contrib/json_dump/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Required, TypedDict
from typing import TypedDict

from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -31,14 +31,10 @@ class JSONDumpOptionsSerializer(JsonSchemaSerializerMixin, serializers.Serialize
help_text=_("Which service to use."),
required=True,
)
# TODO-4908: show the complete API endpoint as a (tooltip) hint after user entry?
# Might be a front-end thing...
relative_api_endpoint = serializers.CharField(
path = 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)."
),
label=_("Path"),
help_text=_("Path relative to the Service API root."),
allow_blank=True,
required=False,
default="",
Expand All @@ -64,5 +60,5 @@ class JSONDumpOptions(TypedDict):
"""

service: Service
relative_api_endpoint: str
path: str
form_variables: list[str]
11 changes: 8 additions & 3 deletions src/openforms/registrations/contrib/json_dump/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
SubmissionValueVariable,
)
from openforms.typing import JSONObject
from openforms.variables.constants import FormVariableSources

from ...base import BasePlugin # openforms.registrations.base
from ...registry import register # openforms.registrations.registry
Expand Down Expand Up @@ -63,7 +64,7 @@ def register_submission(
service = options["service"]
submission.registration_result = result = {}
with build_client(service) as client:
if ".." in (path := options["relative_api_endpoint"]):
if ".." in (path := options["path"]):
raise SuspiciousOperation("Possible path traversal detected")

res = client.post(path, json=data)
Expand All @@ -88,8 +89,12 @@ def process_variables(submission: Submission, values: JSONObject):

for key in values.keys():
variable = state.variables.get(key)
if variable is None:
# None for static variables
if (
variable is None
or variable.form_variable.source == FormVariableSources.user_defined
):
# None for static variables, and processing user defined variables is
# not relevant here
continue

component = get_component(variable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_submission_with_json_dump_backend(self):

json_form_options = dict(
service=(ServiceFactory(api_root="http://localhost:80/")),
relative_api_endpoint="json_plugin",
path="json_plugin",
form_variables=["firstName", "file", "auth_bsn"],
)
json_plugin = JSONDumpRegistration("json_registration_plugin")
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_exception_raised_when_service_returns_unexpected_status_code(self):

json_form_options = dict(
service=(ServiceFactory(api_root="http://localhost:80/")),
relative_api_endpoint="fake_endpoint",
path="fake_endpoint",
form_variables=["firstName", "auth_bsn"],
)
json_plugin = JSONDumpRegistration("json_registration_plugin")
Expand All @@ -135,7 +135,7 @@ def test_multiple_file_uploads(self):
"name": "file2.txt",
"type": "application/text",
"originalName": "file2.txt",
}
},
],
},
)
Expand All @@ -162,7 +162,7 @@ def test_multiple_file_uploads(self):

json_form_options = dict(
service=(ServiceFactory(api_root="http://localhost:80/")),
relative_api_endpoint="json_plugin",
path="json_plugin",
form_variables=["file"],
)
json_plugin = JSONDumpRegistration("json_registration_plugin")
Expand Down

0 comments on commit 3ee8503

Please sign in to comment.