Skip to content

Commit

Permalink
[#4395] PR feedback-updated vcr tests and better var names and help t…
Browse files Browse the repository at this point in the history
…exts
  • Loading branch information
vaszig committed Jul 25, 2024
1 parent 9ba2778 commit 58ebf87
Show file tree
Hide file tree
Showing 15 changed files with 332 additions and 204 deletions.
15 changes: 10 additions & 5 deletions src/openforms/contrib/objects_api/clients/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ def create_object(self, objecttype_url: str, record_data: dict) -> dict:

return response.json()

def update_object(
self, objecttype_url: str, record_data: dict, initial_data_reference: str
) -> dict:
endpoint = f"objects/{initial_data_reference}"
def get_object(self, object_uuid: str) -> dict:
endpoint = f"objects/{object_uuid}"

response = self.get(endpoint, headers=CRS_HEADERS)
response.raise_for_status()

return response.json()

def update_object(self, record_data: dict, object_uuid: str) -> dict:
endpoint = f"objects/{object_uuid}"
json = {
"type": objecttype_url,
"record": record_data,
}

Expand Down
12 changes: 6 additions & 6 deletions src/openforms/js/compiled-lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3181,12 +3181,6 @@
"value": "Basic"
}
],
"XiPZpg": [
{
"type": 0,
"value": "Indicates whether the (existing) object should be updated and not created"
}
],
"Xj1uvL": [
{
"type": 0,
Expand Down Expand Up @@ -5628,5 +5622,11 @@
"type": 0,
"value": "Use logic rules to determine the price"
}
],
"zrsWsH": [
{
"type": 0,
"value": "Indicates whether the existing object (retrieved from an optional initial data reference) should be updated, instead of creating a new one. If no existing object exists, a new one will be created instead"
}
]
}
12 changes: 6 additions & 6 deletions src/openforms/js/compiled-lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -3198,12 +3198,6 @@
"value": "Basis"
}
],
"XiPZpg": [
{
"type": 0,
"value": "Indicates whether the (existing) object should be updated and not created"
}
],
"Xj1uvL": [
{
"type": 0,
Expand Down Expand Up @@ -5650,5 +5644,11 @@
"type": 0,
"value": "Gebruik prijsregels om de prijs te bepalen"
}
],
"zrsWsH": [
{
"type": 0,
"value": "Indicates whether the existing object (retrieved from an optional initial data reference) should be updated, instead of creating a new one. If no existing object exists, a new one will be created instead"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ const LegacyConfigFields = ({index, name, schema, formData, onFieldChange}) => {
})}
rawDescription={intl.formatMessage({
defaultMessage:
'Indicates whether the (existing) object should be updated and not created',
description: 'Objects API registration options "Upload submission CSV" description',
'Indicates whether the existing object (retrieved from an optional initial data reference) should be updated, instead of creating a new one. If no existing object exists, a new one will be created instead',
description: 'Objects API registration options "Update existing object" description',
})}
rawErrors={getFieldErrors(name, index, validationErrors, 'updateExistingObject')}
errors={buildErrorsComponent('updateExistingObject')}
Expand All @@ -133,7 +133,6 @@ const LegacyConfigFields = ({index, name, schema, formData, onFieldChange}) => {
<Checkbox
id="root_updateExistingObject"
name="updateExistingObject"
value={updateExistingObject}
checked={updateExistingObject}
onChange={e =>
onFieldChange({target: {name: 'updateExistingObject', value: !updateExistingObject}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ const V2ConfigFields = ({index, name, schema, formData, onFieldChange, onChange}
})}
rawDescription={intl.formatMessage({
defaultMessage:
'Indicates whether the (existing) object should be updated and not created',
description: 'Objects API registration options "Upload submission CSV" description',
'Indicates whether the existing object (retrieved from an optional initial data reference) should be updated, instead of creating a new one. If no existing object exists, a new one will be created instead',
description: 'Objects API registration options "Update existing object" description',
})}
rawErrors={getFieldErrors(name, index, validationErrors, 'updateExistingObject')}
errors={buildErrorsComponent('updateExistingObject')}
Expand All @@ -185,7 +185,6 @@ const V2ConfigFields = ({index, name, schema, formData, onFieldChange, onChange}
<Checkbox
id="root_updateExistingObject"
name="updateExistingObject"
value={updateExistingObject}
checked={updateExistingObject}
onChange={e =>
onFieldChange({target: {name: 'updateExistingObject', value: !updateExistingObject}})
Expand Down
10 changes: 5 additions & 5 deletions src/openforms/js/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1474,11 +1474,6 @@
"description": "Service fetch configuration modal basic fieldset title",
"originalDefault": "Basic"
},
"XiPZpg": {
"defaultMessage": "Indicates whether the (existing) object should be updated and not created",
"description": "Objects API registration options \"Upload submission CSV\" description",
"originalDefault": "Indicates whether the (existing) object should be updated and not created"
},
"XqTjf+": {
"defaultMessage": "JSON template for the content of the request sent to the Objects API.",
"description": "Objects API - JSON content field",
Expand Down Expand Up @@ -2578,5 +2573,10 @@
"defaultMessage": "Use logic rules to determine the price",
"description": "dynamic pricing mode label",
"originalDefault": "Use logic rules to determine the price"
},
"zrsWsH": {
"defaultMessage": "Indicates whether the existing object (retrieved from an optional initial data reference) should be updated, instead of creating a new one. If no existing object exists, a new one will be created instead",
"description": "Objects API registration options \"Update existing object\" description",
"originalDefault": "Indicates whether the existing object (retrieved from an optional initial data reference) should be updated, instead of creating a new one. If no existing object exists, a new one will be created instead"
}
}
10 changes: 5 additions & 5 deletions src/openforms/js/lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1486,11 +1486,6 @@
"description": "Service fetch configuration modal basic fieldset title",
"originalDefault": "Basic"
},
"XiPZpg": {
"defaultMessage": "Indicates whether the (existing) object should be updated and not created",
"description": "Objects API registration options \"Upload submission CSV\" description",
"originalDefault": "Indicates whether the (existing) object should be updated and not created"
},
"XqTjf+": {
"defaultMessage": "JSON-sjabloon voor de inhoud van het verzoek wat naar de Objecten API gestuurd wordt.",
"description": "Objects API - JSON content field",
Expand Down Expand Up @@ -2596,5 +2591,10 @@
"defaultMessage": "Gebruik prijsregels om de prijs te bepalen",
"description": "dynamic pricing mode label",
"originalDefault": "Use logic rules to determine the price"
},
"zrsWsH": {
"defaultMessage": "Indicates whether the existing object (retrieved from an optional initial data reference) should be updated, instead of creating a new one. If no existing object exists, a new one will be created instead",
"description": "Objects API registration options \"Update existing object\" description",
"originalDefault": "Indicates whether the existing object (retrieved from an optional initial data reference) should be updated, instead of creating a new one. If no existing object exists, a new one will be created instead"
}
}
2 changes: 1 addition & 1 deletion src/openforms/registrations/contrib/objects_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ObjectsAPIOptionsSerializer(JsonSchemaSerializerMixin, serializers.Seriali
update_existing_object = serializers.BooleanField(
label=_("Update existing object"),
help_text=_(
"Indicates whether the (existing) object should be updated and not created."
"Indicates whether the existing object should be updated (if it exists), instead of creating a new one."
),
default=False,
)
Expand Down
41 changes: 19 additions & 22 deletions src/openforms/registrations/contrib/objects_api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,27 @@ def register_submission(

with get_objects_client(options["objects_api_group"]) as objects_client:
# update or create the object
if not (
options.get("update_existing_object")
and submission.initial_data_reference
):
response = execute_unless_result_exists(
partial(
objects_client.create_object,
objecttype_url=objecttype_url,
record_data=record_data,
),
submission,
"intermediate.objects_api_object_create",
is_update = (
options["update_existing_object"] and submission.initial_data_reference
)
update_or_create = (
partial(
objects_client.update_object,
object_uuid=submission.initial_data_reference,
record_data=record_data,
)
else:
response = execute_unless_result_exists(
partial(
objects_client.update_object,
initial_data_reference=submission.initial_data_reference,
objecttype_url=objecttype_url,
record_data=record_data,
),
submission,
"intermediate.objects_api_object_update",
if is_update
else partial(
objects_client.create_object,
objecttype_url=objecttype_url,
record_data=record_data,
)
)
response = execute_unless_result_exists(
update_or_create,
submission,
"intermediate.objects_api_object_create_or_update",
)

return response

Expand Down
Loading

0 comments on commit 58ebf87

Please sign in to comment.