-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [#4650] Add variable select input to email registration
Either the `to_emails` or the `to_email_from_variable` fields should used when registering the email backend plugin. When a variable is selected, the resulting email address will be used for mailings. When the variable doesn't contain an email address, the `to_emails` will be used as fallback.
- Loading branch information
1 parent
b0b5055
commit 473b0bb
Showing
5 changed files
with
134 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...js/components/admin/form_design/registrations/email/fields/EmailRecipientsFromVariable.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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, , fieldHelpers] = useField('toEmailsFromVariable'); | ||
const {setValue} = fieldHelpers; | ||
return ( | ||
<FormRow> | ||
<Field | ||
name="toEmailsFromVariable" | ||
label={ | ||
<FormattedMessage | ||
description="Email registration options 'toEmailsFromVariable' label" | ||
defaultMessage="Using a variable to decide to which email address the | ||
submission details will be sent" | ||
/> | ||
} | ||
helpText={ | ||
<FormattedMessage | ||
description="Email registration options 'toEmailsFromVariable' helpText" | ||
defaultMessage="The email address described in this variable will be used | ||
for the mailing. If a variable is selected, the general registration | ||
addresses will be used as fallback option. " | ||
/> | ||
} | ||
> | ||
<VariableSelection | ||
name="toEmailsFromVariable" | ||
value={fieldProps.value} | ||
onChange={event => { | ||
setValue(event.target.value); | ||
}} | ||
/> | ||
</Field> | ||
</FormRow> | ||
); | ||
}; | ||
|
||
EmailRecipientsFromVariable.propTypes = {}; | ||
|
||
export default EmailRecipientsFromVariable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,7 +312,7 @@ def test_registration_backend_invalid_options(self): | |
completed=True, | ||
form__registration_backend="email", | ||
form__registration_backend_options={}, | ||
) # Missing "to_email" option | ||
) # Missing "to_emails" and "to_emails_from_variable" option | ||
|
||
with ( | ||
self.subTest("On completion - does NOT raise"), | ||
|
@@ -334,6 +334,48 @@ def test_registration_backend_invalid_options(self): | |
): | ||
register_submission(submission.id, PostSubmissionEvents.on_retry) | ||
|
||
def test_email_registration_backend_with_to_emails(self): | ||
submission = SubmissionFactory.create( | ||
completed=True, | ||
form__registration_backend="email", | ||
form__registration_backend_options={"to_emails": ["[email protected]"]}, | ||
) | ||
|
||
with ( | ||
self.subTest("On completion - logs as successful"), | ||
self.assertLogs(level="INFO") as logs, | ||
): | ||
register_submission(submission.id, PostSubmissionEvents.on_completion) | ||
|
||
submission.refresh_from_db() | ||
self.assertIn( | ||
"Registration using plugin '%r' for submission '%s' succeeded", | ||
logs.records[-1].msg, | ||
) | ||
self.assertFalse(submission.needs_on_completion_retry) | ||
|
||
def test_email_registration_backend_with_to_emails_from_variable(self): | ||
submission = SubmissionFactory.create( | ||
completed=True, | ||
form__registration_backend="email", | ||
form__registration_backend_options={ | ||
"to_emails_from_variable": "email_example_variable" | ||
}, | ||
) | ||
|
||
with ( | ||
self.subTest("On completion - logs as successful"), | ||
self.assertLogs(level="INFO") as logs, | ||
): | ||
register_submission(submission.id, PostSubmissionEvents.on_completion) | ||
|
||
submission.refresh_from_db() | ||
self.assertIn( | ||
"Registration using plugin '%r' for submission '%s' succeeded", | ||
logs.records[-1].msg, | ||
) | ||
self.assertFalse(submission.needs_on_completion_retry) | ||
|
||
def test_calling_registration_task_with_serialized_args(self): | ||
submission = SubmissionFactory.create( | ||
completed=True, | ||
|