Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#4395] Add flag for updating an object to the ObjectsAPI registration #4538

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/openforms/contrib/objects_api/clients/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,22 @@ def create_object(self, objecttype_url: str, record_data: dict) -> dict:
response.raise_for_status()

return response.json()

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 = {
"record": record_data,
}

response = self.patch(endpoint, json=json, headers=CRS_HEADERS)
response.raise_for_status()

return response.json()
12 changes: 12 additions & 0 deletions src/openforms/js/compiled-lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,12 @@
"value": "A short instruction shown below the signature pad."
}
],
"Nv0J2Y": [
{
"type": 0,
"value": "Update existing object"
}
],
"NwTdLM": [
{
"type": 0,
Expand Down Expand Up @@ -5616,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: 12 additions & 0 deletions src/openforms/js/compiled-lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -2312,6 +2312,12 @@
"value": "Een korte instructie onder het handtekenvlak."
}
],
"Nv0J2Y": [
{
"type": 0,
"value": "Update existing object"
}
],
"NwTdLM": [
{
"type": 0,
Expand Down Expand Up @@ -5638,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 @@ -18,6 +18,7 @@ const LegacyConfigFields = ({index, name, schema, formData, onFieldChange}) => {
objecttype = '',
objecttypeVersion = '',
productaanvraagType = '',
updateExistingObject = false,
informatieobjecttypeSubmissionReport = '',
uploadSubmissionCsv = false,
informatieobjecttypeSubmissionCsv = '',
Expand Down Expand Up @@ -114,6 +115,30 @@ const LegacyConfigFields = ({index, name, schema, formData, onFieldChange}) => {
onChange={onFieldChange}
/>
</CustomFieldTemplate>
<CustomFieldTemplate
id="root_updateExistingObject"
label={intl.formatMessage({
defaultMessage: 'Update existing object',
description: 'Objects API registration options "Update existing object" label',
})}
rawDescription={intl.formatMessage({
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',
})}
rawErrors={getFieldErrors(name, index, validationErrors, 'updateExistingObject')}
errors={buildErrorsComponent('updateExistingObject')}
displayLabel
>
<Checkbox
id="root_updateExistingObject"
name="updateExistingObject"
checked={updateExistingObject}
onChange={e =>
onFieldChange({target: {name: 'updateExistingObject', value: !updateExistingObject}})
}
/>
</CustomFieldTemplate>
<CustomFieldTemplate
id="root_productaanvraagType"
label={intl.formatMessage({
Expand Down Expand Up @@ -319,6 +344,7 @@ LegacyConfigFields.propTypes = {
version: PropTypes.number,
objecttype: PropTypes.string,
objecttypeVersion: PropTypes.string,
updateExistingObject: PropTypes.bool,
productaanvraagType: PropTypes.string,
informatieobjecttypeSubmissionReport: PropTypes.string,
uploadSubmissionCsv: PropTypes.bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ObjectsApiOptionsForm.propTypes = {
version: PropTypes.number,
objecttype: PropTypes.string,
objecttypeVersion: PropTypes.string,
updateExistingObject: PropTypes.bool,
productaanvraagType: PropTypes.string,
informatieobjecttypeSubmissionReport: PropTypes.string,
uploadSubmissionCsv: PropTypes.bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ ObjectsApiOptionsFormFields.propTypes = {
version: PropTypes.number,
objecttype: PropTypes.string,
objecttypeVersion: PropTypes.string,
updateExistingObject: PropTypes.bool,
productaanvraagType: PropTypes.string,
informatieobjecttypeSubmissionReport: PropTypes.string,
uploadSubmissionCsv: PropTypes.bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const V2ConfigFields = ({index, name, schema, formData, onFieldChange, onChange}
objecttype = '',
objecttypeVersion = '',
informatieobjecttypeSubmissionReport = '',
updateExistingObject = false,
uploadSubmissionCsv = false,
informatieobjecttypeSubmissionCsv = '',
informatieobjecttypeAttachment = '',
Expand Down Expand Up @@ -166,6 +167,30 @@ const V2ConfigFields = ({index, name, schema, formData, onFieldChange, onChange}
onChange={onFieldChange}
/>
</CustomFieldTemplate>
<CustomFieldTemplate
id="root_updateExistingObject"
label={intl.formatMessage({
defaultMessage: 'Update existing object',
description: 'Objects API registration options "Update existing object" label',
})}
rawDescription={intl.formatMessage({
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',
})}
rawErrors={getFieldErrors(name, index, validationErrors, 'updateExistingObject')}
errors={buildErrorsComponent('updateExistingObject')}
displayLabel
>
<Checkbox
id="root_updateExistingObject"
name="updateExistingObject"
checked={updateExistingObject}
onChange={e =>
onFieldChange({target: {name: 'updateExistingObject', value: !updateExistingObject}})
}
/>
</CustomFieldTemplate>
<CustomFieldTemplate
id="root_informatieobjecttypeSubmissionReport"
label={intl.formatMessage({
Expand Down Expand Up @@ -306,6 +331,7 @@ V2ConfigFields.propTypes = {
objecttype: PropTypes.string,
objecttypeVersion: PropTypes.string,
informatieobjecttypeSubmissionReport: PropTypes.string,
updateExistingObject: PropTypes.bool,
uploadSubmissionCsv: PropTypes.bool,
informatieobjecttypeSubmissionCsv: PropTypes.string,
informatieobjecttypeAttachment: PropTypes.string,
Expand Down
10 changes: 10 additions & 0 deletions src/openforms/js/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,11 @@
"description": "Warning that all simple variables are mapped",
"originalDefault": "All simple variables are mapped to a case property."
},
"Nv0J2Y": {
"defaultMessage": "Update existing object",
"description": "Objects API registration options \"Update existing object\" label",
"originalDefault": "Update existing object"
},
"NwTdLM": {
"defaultMessage": "Component where locations for an appointment will be shown",
"description": "Locations Component field help text",
Expand Down Expand Up @@ -2568,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: 10 additions & 0 deletions src/openforms/js/lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,11 @@
"description": "Warning that all simple variables are mapped",
"originalDefault": "All simple variables are mapped to a case property."
},
"Nv0J2Y": {
"defaultMessage": "Update existing object",
"description": "Objects API registration options \"Update existing object\" label",
"originalDefault": "Update existing object"
},
"NwTdLM": {
"defaultMessage": "Veld waar beschikbare locaties voor een afspraak komen te staan",
"description": "Locations Component field help text",
Expand Down Expand Up @@ -2586,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"
}
}
21 changes: 14 additions & 7 deletions src/openforms/registrations/contrib/objects_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,51 +84,58 @@ class ObjectsAPIOptionsSerializer(JsonSchemaSerializerMixin, serializers.Seriali
)
objecttype_version = serializers.IntegerField(
label=_("objecttype version"),
help_text=_("Version of the objecttype in the Objecttypes API"),
help_text=_("Version of the objecttype in the Objecttypes API."),
)
update_existing_object = serializers.BooleanField(
label=_("Update existing object"),
help_text=_(
"Indicates whether the existing object should be updated (if it exists), instead of creating a new one."
),
default=False,
)
informatieobjecttype_submission_report = serializers.URLField(
label=_("submission report PDF informatieobjecttype"),
help_text=_(
"URL that points to the INFORMATIEOBJECTTYPE in the Catalogi API "
"to be used for the submission report PDF"
"to be used for the submission report PDF."
),
required=False,
)
upload_submission_csv = serializers.BooleanField(
label=_("Upload submission CSV"),
help_text=_(
"Indicates whether or not the submission CSV should be uploaded as "
"a Document in Documenten API and attached to the ProductAanvraag"
"a Document in Documenten API and attached to the ProductAanvraag."
),
default=False,
)
informatieobjecttype_submission_csv = serializers.URLField(
label=_("submission report CSV informatieobjecttype"),
help_text=_(
"URL that points to the INFORMATIEOBJECTTYPE in the Catalogi API "
"to be used for the submission report CSV"
"to be used for the submission report CSV."
),
required=False,
)
informatieobjecttype_attachment = serializers.URLField(
label=_("attachment informatieobjecttype"),
help_text=_(
"URL that points to the INFORMATIEOBJECTTYPE in the Catalogi API "
"to be used for the submission attachments"
"to be used for the submission attachments."
),
required=False,
)
organisatie_rsin = serializers.CharField(
label=_("organisation RSIN"),
validators=[validate_rsin],
help_text=_("RSIN of organization, which creates the INFORMATIEOBJECT"),
help_text=_("RSIN of organization, which creates the INFORMATIEOBJECT."),
required=False,
)

# V1 only fields:
productaanvraag_type = serializers.CharField(
label=_("productaanvraag type"),
help_text=_("The type of ProductAanvraag"),
help_text=_("The type of ProductAanvraag."),
required=False,
)
content_json = serializers.CharField(
Expand Down
17 changes: 15 additions & 2 deletions src/openforms/registrations/contrib/objects_api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,25 @@ def register_submission(
objecttype_url = objecttype["url"]

with get_objects_client(options["objects_api_group"]) as objects_client:
response = execute_unless_result_exists(
# update or create the object
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,
)
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",
)
Expand Down
Loading
Loading