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

Dynamic email registration recipients using variables #4971

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
3 changes: 1 addition & 2 deletions pyright.pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ include = [
"src/openforms/emails/templatetags/cosign_information.py",
# Registrations
"src/openforms/registrations/tasks.py",
"src/openforms/registrations/contrib/email/config.py",
"src/openforms/registrations/contrib/email/plugin.py",
"src/openforms/registrations/contrib/email/",
"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
42 changes: 42 additions & 0 deletions src/openforms/js/compiled-lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,12 @@
"value": "Minimum value"
}
],
"BHr/3M": [
{
"type": 0,
"value": "If specified, the recipient email addresses will be taken from the selected variable. You must still specify 'regular' email addresses as a fallback, in case something is wrong with the variable."
}
],
"BKTOtD": [
{
"offset": 0,
Expand Down Expand Up @@ -1873,6 +1879,12 @@
"value": "The co-sign component requires at least one authentication plugin to be enabled."
}
],
"FNT8nq": [
{
"type": 0,
"value": "Variable containing email addresses"
}
],
"FOlQaP": [
{
"type": 0,
Expand Down Expand Up @@ -2233,6 +2245,12 @@
"value": " is unknown. We can only display the JSON definition."
}
],
"Igt0Rc": [
{
"type": 0,
"value": "Skip ownership check"
}
],
"IhIqdj": [
{
"type": 0,
Expand Down Expand Up @@ -3251,6 +3269,12 @@
"value": "Open editor"
}
],
"T2TGaF": [
{
"type": 0,
"value": "Ownership checks"
}
],
"T2dCIS": [
{
"type": 0,
Expand Down Expand Up @@ -5571,6 +5595,12 @@
"value": "The registration result will be an object from the selected type."
}
],
"nhBYT3": [
{
"type": 0,
"value": "Recipients"
}
],
"nkr7r0": [
{
"type": 0,
Expand Down Expand Up @@ -5889,6 +5919,12 @@
"value": "How errored submissions of this form will be removed after the limit. Leave blank to use value in General Configuration."
}
],
"qdV9zh": [
{
"type": 0,
"value": "If enabled, then no access control on the referenced object is performed. Ensure that it does not contain private data before checking this!"
}
],
"qmBAmr": [
{
"type": 0,
Expand Down Expand Up @@ -6297,6 +6333,12 @@
"value": "Value"
}
],
"vaO0I+": [
{
"type": 0,
"value": "Content"
}
],
"ve3rsH": [
{
"type": 0,
Expand Down
44 changes: 43 additions & 1 deletion src/openforms/js/compiled-lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,12 @@
"value": "Minimale waarde"
}
],
"BHr/3M": [
{
"type": 0,
"value": "Als een variable geselecteerd is, dan wordt de waarde gebruikt als e-mailadres(sen) van de ontvangers. Je moet nog steeds een vast adres opgeven als terugvaloptie voor het geval er iets fout gaat met de variabele."
}
],
"BKTOtD": [
{
"offset": 0,
Expand Down Expand Up @@ -1894,6 +1900,12 @@
"value": "Er moet minstens één authenticatiemethode ingeschakeld zijn voor de mede-ondertekencomponent."
}
],
"FNT8nq": [
{
"type": 0,
"value": "Variabele die adres(sen) bevat"
}
],
"FOlQaP": [
{
"type": 0,
Expand Down Expand Up @@ -2254,6 +2266,12 @@
"value": " is niet bekend. We kunnen enkel de JSON-definitie weergeven."
}
],
"Igt0Rc": [
{
"type": 0,
"value": "Sla eigenaarcontrole over"
}
],
"IhIqdj": [
{
"type": 0,
Expand Down Expand Up @@ -2597,7 +2615,7 @@
"LeVpdf": [
{
"type": 0,
"value": "Plugin-insellingen: e-mail"
"value": "Plugin-instellingen: e-mail"
}
],
"LiXrER": [
Expand Down Expand Up @@ -3264,6 +3282,12 @@
"value": "Editor openen"
}
],
"T2TGaF": [
{
"type": 0,
"value": "Eigenaarcontroles"
}
],
"T2dCIS": [
{
"type": 0,
Expand Down Expand Up @@ -5589,6 +5613,12 @@
"value": "Het registratieresultaat zal een object van dit type zijn."
}
],
"nhBYT3": [
{
"type": 0,
"value": "Ontvangers"
}
],
"nkr7r0": [
{
"type": 0,
Expand Down Expand Up @@ -5907,6 +5937,12 @@
"value": "Geeft aan hoe niet voltooide inzendingen (door fouten in de afhandeling) worden opgeschoond na de bewaartermijn. Laat leeg om de waarde van de algemene configuratie te gebruiken."
}
],
"qdV9zh": [
{
"type": 0,
"value": "Indien aangevinkt, dan worden geen controles uitgevoerd of de (ingelogde) gebruiker toegang heeft op het gerefereerde object. Valideer dat de objecten geen privacy-gevoelige gegevens bevatten voor je dit aanvinkt!"
}
],
"qmBAmr": [
{
"type": 0,
Expand Down Expand Up @@ -6315,6 +6351,12 @@
"value": "(Standaard)tekst"
}
],
"vaO0I+": [
{
"type": 0,
"value": "E-mailinhoud"
}
],
"ve3rsH": [
{
"type": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,73 @@ export default {
label: 'textfield2',
},
},
availableFormVariables: [
{
dataFormat: '',
dataType: 'string',
form: 'http://localhost:8000/api/v2/forms/ae26e20c-f059-4fdf-bb82-afc377869bb5',
formDefinition: null,
initialValue: '',
isSensitiveData: false,
key: 'textField1',
name: 'textfield1',
prefillAttribute: '',
prefillPlugin: '',
source: 'component',
},
{
dataFormat: '',
dataType: 'string',
form: 'http://localhost:8000/api/v2/forms/ae26e20c-f059-4fdf-bb82-afc377869bb5',
formDefinition: null,
initialValue: '',
isSensitiveData: false,
key: 'textField2',
name: 'textfield2',
prefillAttribute: '',
prefillPlugin: '',
source: 'component',
},
{
dataFormat: '',
dataType: 'string',
form: 'http://localhost:8000/api/v2/forms/ae26e20c-f059-4fdf-bb82-afc377869bb5',
formDefinition: null,
initialValue: '',
isSensitiveData: false,
key: 'userDefinedVar1',
name: 'User defined string',
prefillAttribute: '',
prefillPlugin: '',
source: 'user_defined',
},
{
dataFormat: '',
dataType: 'array',
form: 'http://localhost:8000/api/v2/forms/ae26e20c-f059-4fdf-bb82-afc377869bb5',
formDefinition: null,
initialValue: [],
isSensitiveData: false,
key: 'userDefinedVar2',
name: 'User defined array',
prefillAttribute: '',
prefillPlugin: '',
source: 'user_defined',
},
{
dataFormat: '',
dataType: 'float',
form: 'http://localhost:8000/api/v2/forms/ae26e20c-f059-4fdf-bb82-afc377869bb5',
formDefinition: null,
initialValue: null,
isSensitiveData: false,
key: 'userDefinedVar3',
name: 'User defined float',
prefillAttribute: '',
prefillPlugin: '',
source: 'user_defined',
},
],
registrationPluginsVariables: [
{
pluginIdentifier: 'stuf-zds-create-zaak',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const EmailOptionsForm = ({name, label, schema, formData, onChange}) => {
/>
}
initialFormData={{
toEmailsFromVariable: '', // ensure an initial value is provided
...formData,
// ensure we have a blank row initially
toEmails: formData.toEmails?.length ? formData.toEmails : [''],
Expand Down Expand Up @@ -51,6 +52,7 @@ EmailOptionsForm.propTypes = {
emailSubject: PropTypes.string,
paymentEmails: PropTypes.arrayOf(PropTypes.string),
toEmails: PropTypes.arrayOf(PropTypes.string),
toEmailsFromVariable: PropTypes.string,
}),
onChange: PropTypes.func.isRequired,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import EmailHasAttachmentSelect from './fields/EmailHasAttachmentSelect';
import EmailPaymentSubject from './fields/EmailPaymentSubject';
import EmailPaymentUpdateRecipients from './fields/EmailPaymentUpdateRecipients';
import EmailRecipients from './fields/EmailRecipients';
import EmailRecipientsFromVariable from './fields/EmailRecipientsFromVariable';
import EmailSubject from './fields/EmailSubject';

const EmailOptionsFormFields = ({name, schema}) => {
Expand All @@ -35,8 +36,26 @@ const EmailOptionsFormFields = ({name, schema}) => {
const relevantErrors = filterErrors(name, validationErrors);
return (
<ValidationErrorsProvider errors={relevantErrors}>
<Fieldset>
<Fieldset
title={
<FormattedMessage
description="Email registration: recipients fieldset title"
defaultMessage="Recipients"
/>
}
>
<EmailRecipients />
<EmailRecipientsFromVariable />
</Fieldset>

<Fieldset
title={
<FormattedMessage
description="Email registration: content fieldset title"
defaultMessage="Content"
/>
}
>
<EmailSubject />
<EmailContentTemplateHTML />
<EmailContentTemplateText />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const EmailRecipients = () => {
defaultMessage="The email addresses to which the submission details will be sent"
/>
}
required
>
<ArrayInput
name="toEmails"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {useField} from 'formik';
import React from 'react';
import {FormattedMessage} from 'react-intl';

import Field from 'components/admin/forms/Field';
import FormRow from 'components/admin/forms/FormRow';
import VariableSelection from 'components/admin/forms/VariableSelection';

const EmailRecipientsFromVariable = () => {
const [fieldProps, , {setValue}] = useField('toEmailsFromVariable');
return (
<FormRow>
<Field
name="toEmailsFromVariable"
label={
<FormattedMessage
description="Email registration options 'toEmailsFromVariable' label"
defaultMessage="Variable containing email addresses"
/>
}
helpText={
<FormattedMessage
description="Email registration options 'toEmailsFromVariable' helpText"
defaultMessage={`If specified, the recipient email addresses will be taken
from the selected variable. You must still specify 'regular' email addresses
as a fallback, in case something is wrong with the variable.
`}
/>
}
>
<VariableSelection
{...fieldProps}
isClearable
onChange={event => {
const newValue = event.target.value;
setValue(newValue == null ? '' : newValue);
}}
filter={variable => ['string', 'array'].includes(variable.dataType)}
/>
</Field>
</FormRow>
);
};

EmailRecipientsFromVariable.propTypes = {};

export default EmailRecipientsFromVariable;
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ const PrefillSummary = ({
}
isOpen={modalOpen}
closeModal={() => setModalOpen(false)}
// FIXME: push this down to the plugin-specific components, somehow
extraModifiers={plugin === 'objects_api' ? ['large'] : undefined}
>
<ErrorBoundary>
<PrefillConfigurationForm
Expand Down
Loading
Loading