Skip to content
Open
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
41 changes: 31 additions & 10 deletions src/openforms/contrib/zgw/service.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import json
from io import BytesIO
from typing import Literal, NotRequired, TypedDict
from typing import Literal

from django.core.serializers.json import DjangoJSONEncoder

from openforms.formio.datastructures import FormioData
from openforms.submissions.models import SubmissionFileAttachment, SubmissionReport
from openforms.typing import JSONObject, VariableValue

Check failure on line 9 in src/openforms/contrib/zgw/service.py

View workflow job for this annotation

GitHub Actions / Ruff - lint and check code formatting

ruff (F401)

src/openforms/contrib/zgw/service.py:9:42: F401 `openforms.typing.VariableValue` imported but unused

from .clients.documenten import DocumentenClient
from .resolvers import DocumentTypeResolver
from .typing import DocumentOptions

__all__ = [
"DocumentOptions",
Expand All @@ -17,15 +23,6 @@
type SupportedLanguage = Literal["nl", "en"]


class DocumentOptions(TypedDict):
informatieobjecttype: str
organisatie_rsin: str
auteur: NotRequired[str]
doc_vertrouwelijkheidaanduiding: NotRequired[str]
ontvangstdatum: NotRequired[str]
titel: NotRequired[str]


def create_report_document(
client: DocumentenClient,
name: str,
Expand Down Expand Up @@ -104,3 +101,27 @@
"doc_vertrouwelijkheidaanduiding", ""
),
)


def create_json_document(
client: DocumentenClient,
name: str,
document_data: dict[str, FormioData | JSONObject],
options: DocumentOptions,
language: SupportedLanguage,
) -> dict:
content = BytesIO(json.dumps(document_data, cls=DjangoJSONEncoder).encode("utf-8"))
return client.create_document(
informatieobjecttype=options["informatieobjecttype"],
bronorganisatie=options["organisatie_rsin"],
title=name,
author=options.get("auteur") or "Aanvrager",
language=language,
format="application/json",
content=content,
status="definitief",
filename=f"openforms-{name}.json",
description="Ingezonden formulier",
received_date=options.get("ontvangstdatum"),
vertrouwelijkheidaanduiding=options.get("doc_vertrouwelijkheidaanduiding", ""),
)
10 changes: 10 additions & 0 deletions src/openforms/contrib/zgw/typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import NotRequired, TypedDict


class DocumentOptions(TypedDict):
informatieobjecttype: str
organisatie_rsin: str
auteur: NotRequired[str]
doc_vertrouwelijkheidaanduiding: NotRequired[str]
ontvangstdatum: NotRequired[str]
titel: NotRequired[str]
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export default {
enum: ['objects-group'],
enumNames: ['Objects API Group'],
},
summaryDocuments: {
enum: ['pdf', 'json'],
enumNames: ['PDF document', 'JSON document'],
},
},
},
},
Expand Down Expand Up @@ -621,6 +625,7 @@ export const ConfiguredBackends = {
objecttypeVersion: '',
contentJson: '',
propertyMappings: [],
summaryDocuments: [],
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ import {
OrganisationRSIN,
ProductSelect,
RoltypeFields,
SummaryDocuments,
} from './fields';

const OptionalOptionsFieldset = ({confidentialityLevelChoices, catalogueUrl}) => {
const OptionalOptionsFieldset = ({
confidentialityLevelChoices,
catalogueUrl,
summaryDocumentChoices,
}) => {
return (
<Fieldset
title={
Expand All @@ -33,6 +38,7 @@ const OptionalOptionsFieldset = ({confidentialityLevelChoices, catalogueUrl}) =>
'childrenRoltype',
'childrenDescription',
'productUrl',
'summaryDocuments',
]}
>
<div className="description">
Expand Down Expand Up @@ -71,6 +77,7 @@ const OptionalOptionsFieldset = ({confidentialityLevelChoices, catalogueUrl}) =>
}
>
<ProductSelect catalogueUrl={catalogueUrl} />
<SummaryDocuments summaryDocumentChoices={summaryDocumentChoices} />
</ErrorBoundary>
</Fieldset>
);
Expand All @@ -80,6 +87,9 @@ OptionalOptionsFieldset.propTypes = {
confidentialityLevelChoices: PropTypes.arrayOf(
PropTypes.arrayOf(PropTypes.string) // value & label are both string
).isRequired,
summaryDocumentChoices: PropTypes.arrayOf(
PropTypes.arrayOf(PropTypes.string) // value & label are both string
).isRequired,
catalogueUrl: PropTypes.string,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import ZGWFormFields from './ZGWOptionsFormFields';
const ZGWOptionsForm = ({name, label, schema, formData, onChange}) => {
const validationErrors = useContext(ValidationErrorContext);

const {zgwApiGroup, zaakVertrouwelijkheidaanduiding, objectsApiGroup} = schema.properties;
const {zgwApiGroup, zaakVertrouwelijkheidaanduiding, objectsApiGroup, summaryDocuments} =
schema.properties;
const apiGroupChoices = getChoicesFromSchema(zgwApiGroup.enum, zgwApiGroup.enumNames);
const objectsApiGroupChoices = getChoicesFromSchema(
objectsApiGroup.enum,
Expand All @@ -21,9 +22,14 @@ const ZGWOptionsForm = ({name, label, schema, formData, onChange}) => {
zaakVertrouwelijkheidaanduiding.enum,
zaakVertrouwelijkheidaanduiding.enumNames
);
const summaryDocumentChoices = getChoicesFromSchema(
summaryDocuments.enum,
summaryDocuments.enumNames
);

const numErrors = filterErrors(name, validationErrors).length;
const defaultGroup = apiGroupChoices.length === 1 ? apiGroupChoices[0][0] : undefined;
const defaultSummaryDocument = summaryDocumentChoices.find(([value]) => value === 'pdf');

return (
<ModalOptionsConfiguration
Expand Down Expand Up @@ -60,6 +66,7 @@ const ZGWOptionsForm = ({name, label, schema, formData, onChange}) => {
...formData,
// Ensure that if there's only one option, it is automatically selected.
zgwApiGroup: formData.zgwApiGroup ?? defaultGroup,
summaryDocuments: formData.summaryDocuments ?? [defaultSummaryDocument[0]],
}}
onSubmit={values => onChange({formData: values})}
>
Expand All @@ -68,6 +75,7 @@ const ZGWOptionsForm = ({name, label, schema, formData, onChange}) => {
apiGroupChoices={apiGroupChoices}
objectsApiGroupChoices={objectsApiGroupChoices}
confidentialityLevelChoices={confidentialityLevelChoices}
summaryDocumentChoices={summaryDocumentChoices}
/>
</ModalOptionsConfiguration>
);
Expand All @@ -90,6 +98,10 @@ ZGWOptionsForm.propTypes = {
enum: PropTypes.arrayOf(PropTypes.string).isRequired,
enumNames: PropTypes.arrayOf(PropTypes.string).isRequired,
}).isRequired,
summaryDocuments: PropTypes.shape({
enum: PropTypes.arrayOf(PropTypes.string).isRequired,
enumNames: PropTypes.arrayOf(PropTypes.string).isRequired,
}).isRequired,
}).isRequired,
}).isRequired,
formData: PropTypes.shape({
Expand All @@ -116,6 +128,7 @@ ZGWOptionsForm.propTypes = {
objecttype: PropTypes.string,
objecttypeVersion: PropTypes.string,
contentJson: PropTypes.string,
summaryDocuments: PropTypes.arrayOf(PropTypes.string),
}),
onChange: PropTypes.func.isRequired,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const ZGWFormFields = ({
apiGroupChoices,
objectsApiGroupChoices,
confidentialityLevelChoices,
summaryDocumentChoices,
}) => {
const {
values: {propertyMappings = []},
Expand Down Expand Up @@ -71,6 +72,7 @@ const ZGWFormFields = ({
<OptionalOptionsFieldset
confidentialityLevelChoices={confidentialityLevelChoices}
catalogueUrl={catalogueUrl}
summaryDocumentChoices={summaryDocumentChoices}
/>
<ObjectsAPIOptionsFieldset objectsApiGroupChoices={objectsApiGroupChoices} />
</TabPanel>
Expand Down Expand Up @@ -105,6 +107,9 @@ ZGWFormFields.propTypes = {
confidentialityLevelChoices: PropTypes.arrayOf(
PropTypes.arrayOf(PropTypes.string) // value & label are both string
).isRequired,
summaryDocumentChoices: PropTypes.arrayOf(
PropTypes.arrayOf(PropTypes.string) // value & label are both string
).isRequired,
};

export default ZGWFormFields;
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ import {

const NAME = 'form.registrationBackends.0.options';

const render = ({apiGroups, objectsApiGroupChoices, confidentialityLevelChoices, formData}) => (
const render = ({
apiGroups,
objectsApiGroupChoices,
confidentialityLevelChoices,
summaryDocumentChoices,
formData,
}) => (
<Formik
initialValues={{
// defaults
Expand Down Expand Up @@ -55,6 +61,7 @@ const render = ({apiGroups, objectsApiGroupChoices, confidentialityLevelChoices,
apiGroupChoices={apiGroups}
objectsApiGroupChoices={objectsApiGroupChoices}
confidentialityLevelChoices={confidentialityLevelChoices}
summaryDocumentChoices={summaryDocumentChoices}
/>
</Form>
</Formik>
Expand All @@ -80,6 +87,10 @@ export default {
['openbaar', 'Openbaar'],
['geheim', 'Geheim'],
],
summaryDocumentChoices: [
['pdf', 'PDF document'],
['json', 'JSON document'],
],
formData: {},
availableComponents: {
textField1: {
Expand Down Expand Up @@ -177,6 +188,7 @@ export const SelectCaseTypeAndDocumentType = {
zgwApiGroup: 1,
zaaktype: '',
propertyMappings: [],
summaryDocuments: [],
},
},

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {useField} from 'formik';
import PropTypes from 'prop-types';
import {FormattedMessage} from 'react-intl';

import Field from 'components/admin/forms/Field';
import FormRow from 'components/admin/forms/FormRow';
import {Checkbox} from 'components/admin/forms/Inputs';

const SummaryDocuments = ({summaryDocumentChoices}) => {
const [fieldProps] = useField('summaryDocuments');
const {name: fieldName, value: initialValue, onChange} = fieldProps;

return (
<FormRow>
<Field
name="summaryDocuments"
label={
<FormattedMessage
description="ZGW APIs registration options 'summaryDocuments' label"
defaultMessage="Summary documents"
/>
}
helpText={
<FormattedMessage
description="ZGW APIs registration options 'summaryDocuments' help text"
defaultMessage="Which summary documents to include during registration."
/>
}
>
<ul>
{summaryDocumentChoices.map(([value, label], index) => (
<li key={index}>
<Checkbox
key={index}
label={label}
value={value}
name={fieldName}
checked={initialValue ? initialValue.includes(value) : false}
onChange={onChange}
/>
</li>
))}
</ul>
</Field>
</FormRow>
);
};

SummaryDocuments.propTypes = {
summaryDocumentChoices: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.string)).isRequired,
};

export default SummaryDocuments;
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export {default as ObjectTypeVersion} from './ObjectTypeVersion';
export {default as ProductSelect} from './ProductSelect';
export {default as CaseDescription} from './CaseDescription';
export {default as CaseExplanation} from './CaseExplanation';
export {default as SummaryDocuments} from './SummaryDocuments';
10 changes: 10 additions & 0 deletions src/openforms/js/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@
"description": "Logic type selection label",
"originalDefault": "Please select the logic type:"
},
"9EaH83": {
"defaultMessage": "Summary documents",
"description": "ZGW APIs registration options 'summaryDocuments' label",
"originalDefault": "Summary documents"
},
"9LdZVP": {
"defaultMessage": "Attribute",
"description": "Variable prefill attribute label",
Expand Down Expand Up @@ -2849,6 +2854,11 @@
"description": "component property \"disabled\" label",
"originalDefault": "disabled"
},
"kUDrTZ": {
"defaultMessage": "Wether to include summary documents in the request or not.",
"description": "ZGW APIs registration options 'summaryDocuments' help text",
"originalDefault": "Wether to include summary documents in the request or not."
},
"kWAxhF": {
"defaultMessage": "Subject of the email sent to the registration backend to notify a change in the payment status.",
"description": "Email registration options 'emailPaymentSubject' helpText",
Expand Down
10 changes: 10 additions & 0 deletions src/openforms/js/lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,11 @@
"description": "Logic type selection label",
"originalDefault": "Please select the logic type:"
},
"9EaH83": {
"defaultMessage": "Samenvattingsdocumenten",
"description": "ZGW APIs registration options 'summaryDocuments' label",
"originalDefault": "Summary documents"
},
"9LdZVP": {
"defaultMessage": "Attribuut",
"description": "Variable prefill attribute label",
Expand Down Expand Up @@ -2872,6 +2877,11 @@
"description": "component property \"disabled\" label",
"originalDefault": "disabled"
},
"kUDrTZ": {
"defaultMessage": "Documenten die toegevoegd worden aan de requests.",
"description": "ZGW APIs registration options 'summaryDocuments' help text",
"originalDefault": "Wether to include summary documents in the request or not."
},
"kWAxhF": {
"defaultMessage": "Onderwerp van de registratiemail om een verandering in betaalstatus te signaleren.",
"description": "Email registration options 'emailPaymentSubject' helpText",
Expand Down
7 changes: 7 additions & 0 deletions src/openforms/registrations/contrib/zgw_apis/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.db import models
from django.utils.translation import gettext_lazy as _


class SummaryDocumentChoices(models.TextChoices):
json = "json", _("JSON document")
pdf = "pdf", _("PDF document")
Loading
Loading