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

Conversation

robinmolen
Copy link
Contributor

@robinmolen robinmolen commented Dec 24, 2024

Closes #4650

Changes

The email registration plugin now allows setting the recipient using form variables. This can be combined with the prefill to dynamically set the recipients of a form.

With this, either the emails field (internally known as to_emails) or the email variable field has to be filled. When both are used, the mailing will favor the variable. If for some reason the variable cannot be used for the mailing (i.e. when the variable doesn't result into a valid email address), then the general emails configuration (to_emails) will be used.

The variable can also be used for the payment status update mailings. For the payment status mailing the payment status email addresses will be used. If these aren't defined, then the variable is used and as last resort the general emails configuration will be used.

Checklist

Check off the items that are completed or not relevant.

  • Impact on features

    • Checked copying a form
    • Checked import/export of a form
    • Config checks in the configuration overview admin page
    • Problem detection in the admin email digest is handled
  • Release management

    • I have labelled the PR as "needs-backport" accordingly
  • I have updated the translations assets (you do NOT need to provide translations)

    • Ran ./bin/makemessages_js.sh
    • Ran ./bin/compilemessages_js.sh
  • Dockerfile/scripts

    • Updated the Dockerfile with the necessary scripts from the ./bin folder
  • Commit hygiene

    • Commit messages refer to the relevant Github issue
    • Commit messages explain the "why" of change, not the how

@robinmolen robinmolen force-pushed the feature/4650-set-submission-email-address-using-url-parameters branch from 82c9584 to 472a4fd Compare December 24, 2024 16:16
@robinmolen
Copy link
Contributor Author

There are two tasks that still have to be done:

  • The auth field in the prefill configuration has to be optional (it looks optional, but throws an error when its not used)
  • Fixing the required/optional styling for the prefill configuration fields (required fields should have a bold label, and optional fields should not)

@robinmolen robinmolen force-pushed the feature/4650-set-submission-email-address-using-url-parameters branch from 472a4fd to 575b635 Compare December 24, 2024 16:26
Copy link

codecov bot commented Dec 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.66%. Comparing base (5e67644) to head (b8d142b).
Report is 13 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4971      +/-   ##
==========================================
+ Coverage   96.64%   96.66%   +0.01%     
==========================================
  Files         761      761              
  Lines       25908    25939      +31     
  Branches     3386     3392       +6     
==========================================
+ Hits        25040    25074      +34     
+ Misses        604      601       -3     
  Partials      264      264              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

robinmolen and others added 4 commits December 30, 2024 14:39
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.
The variable chosen in the email registration (`to_email_from_variable`) will now actually be used for the mailing. `to_emails` is used as fallback, in case that the variable doesn't return a valid email address.

The variable will also be used for the payment status update mailing. If `payment_emails` is defined, these will be used as recipients. Otherwise it will use `to_email_from_variable`, and as a last resort the `to_emails`
The possible combinations of to_emails being empty and
to_emails_from_variable possibly being malformed, in combination with
having to treat lists of possible email addresses leads to complicated
code and a risk of no email being sent at all.

Instead, it was decided that:

* we keep requiring the field to_emails, to always have a well-formed
  email address that gives sufficient confidence emails will get
  delivered _somewhere_
* if a variable is provided, and it has a value, we use that to override
  the destination email address. This may possibly be a malformed email,
  or even be completely the wrong type of variable, but that will fail
  loudly and show up in error monitoring

I've added some logging as well for when things eventually go wrong, we
have some traces or debugging entrypoints to investigate.
@sergei-maertens sergei-maertens force-pushed the feature/4650-set-submission-email-address-using-url-parameters branch from 6d96cbc to e448544 Compare December 30, 2024 14:30
This should encourage people to pass the proper options and take into
account optional/required configuration parameters.
Simplified tests by removing indirection and only set up the test data
that is actually required by the test. This also uses some more
ergonomic factory utilities rather than hand-wiring everything.

Now new tests should have better examples to follow.
The test module is aimed at the generic registration mechanism and
just 'happens' to use the email plugin. We do not need to repeat all
the various cases/failure modes that are already covered by the
plugin unit tests.
@sergei-maertens sergei-maertens force-pushed the feature/4650-set-submission-email-address-using-url-parameters branch 2 times, most recently from 98c981f to b1f2801 Compare December 31, 2024 07:51
@sergei-maertens sergei-maertens marked this pull request as ready for review December 31, 2024 07:56
* Added fieldsets to group related options together
* Use a shorter form field label and describe the behaviour in the
  help text
* Filter down the available variables to compatible data types (only
  strings and arrays can produce valid values)
* Updated stories to provide some available variables in the context
* Mark toEmails configuration field as required, since it always is
* Clean up the formik hook/props usage
* Ensure that the 'empty' value is normalized when calling the onChange
  behaviour to normalize formik data types to what the backend expects
@sergei-maertens sergei-maertens force-pushed the feature/4650-set-submission-email-address-using-url-parameters branch from b1f2801 to fa86b04 Compare December 31, 2024 07:58
With product prefill, the premise is that the product data is personal
and likely contains sensitive/private data that gives only the person
with a particular BSN access. This requires the person to authenticate
and then their BSN is compared with some property in the retrieved
object.

However, there may be 'public' data used to prefill some variables,
either user defined or even form variables. Multiple people can use
those objects, even without authenticating in the first place.

You can now flag a prefill to not require this kind of ownership check.
* Added tests for configuration validation
* Added tests for runtime behaviour
@sergei-maertens sergei-maertens force-pushed the feature/4650-set-submission-email-address-using-url-parameters branch from fa86b04 to b8d142b Compare December 31, 2024 08:23
@sergei-maertens sergei-maertens merged commit 5dc2c33 into master Dec 31, 2024
17 of 18 checks passed
@sergei-maertens sergei-maertens deleted the feature/4650-set-submission-email-address-using-url-parameters branch December 31, 2024 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow form URL-parameter to safely influence to which email address a submission is sent to
2 participants