Closed signebedi closed 2 months ago
Maybe, if it's set to true, then all default templates will be disabled. So, we would add the following to get_form_model():
disable_default_emails: bool | list = _config.get("disable_default_emails", False)
The key here is that, if set to true, all email templates will need to be manually sent using event hooks elsewhere within the form __config__
object. There are pros and cons, but ultimately this gives far more control to admins.
I added support for the config object but now need to implement it throughout the API routes.
check_background_email = not form_model.disable_default_emails or isinstance(form_model.disable_default_emails, list) and 'some_event' not in form_model.disable_default_emails
if check_background_email:
... # LOGIC FOR EMAILS AS BACKGROUND TASK
This is also forcing me to manually check to verify that there is a corresponding event hook for each default email event... if not, then disabling default emails will stop possibly important traffic for an individual form. At the very least, it will be important to document this so that admins can decide whether to exclude these from the disablement by passing a list instead of passing a bool.
Example config set ups:
__config__:
disable_default_emails: true
disable_default_emails:
- form_deleted
This could optional param that defaults to an empty list, and be a list of emails from the email_config.yml file. So, no errors will be raised if you type the wrong key name. But, if there's a match between a template in the email_config keys and the list of emails to disable for the current form.