Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add validation for email templates (#6770)
Maciej Korycinski44b86a1af093
diff --git a/saleor/plugins/admin_email/constants.py b/saleor/plugins/admin_email/constants.pyindex 90a040345b..e34bbf6565 100644--- a/saleor/plugins/admin_email/constants.py+++ b/saleor/plugins/admin_email/constants.py@@ -11,16 +11,22 @@ SET_STAFF_PASSWORD_TEMPLATE_FIELD = "set_staff_password_template"CSV_PRODUCT_EXPORT_SUCCESS_TEMPLATE_FIELD = "csv_product_export_success_template"CSV_EXPORT_FAILED_TEMPLATE_FIELD = "csv_export_failed_template"+TEMPLATE_FIELDS = [+ STAFF_ORDER_CONFIRMATION_TEMPLATE_FIELD,+ SET_STAFF_PASSWORD_TEMPLATE_FIELD,+ CSV_PRODUCT_EXPORT_SUCCESS_TEMPLATE_FIELD,+ CSV_EXPORT_FAILED_TEMPLATE_FIELD,+]SET_STAFF_PASSWORD_DEFAULT_TEMPLATE = "set_password.html"CSV_PRODUCT_EXPORT_SUCCESS_DEFAULT_TEMPLATE = "export_products_file.html"CSV_EXPORT_FAILED_TEMPLATE_DEFAULT_TEMPLATE = "export_failed.html"STAFF_ORDER_CONFIRMATION_DEFAULT_TEMPLATE = "staff_confirm_order.html"-STAFF_ORDER_CONFIRMATION_SUBJECT_FIELD = "staff_order_confirmation_title"-SET_STAFF_PASSWORD_SUBJECT_FIELD = "set_staff_password_title"-CSV_PRODUCT_EXPORT_SUCCESS_SUBJECT_FIELD = "csv_product_export_success_title"-CSV_EXPORT_FAILED_SUBJECT_FIELD = "csv_export_failed_title"+STAFF_ORDER_CONFIRMATION_SUBJECT_FIELD = "staff_order_confirmation_subject"+SET_STAFF_PASSWORD_SUBJECT_FIELD = "set_staff_password_subject"+CSV_PRODUCT_EXPORT_SUCCESS_SUBJECT_FIELD = "csv_product_export_success_subject"+CSV_EXPORT_FAILED_SUBJECT_FIELD = "csv_export_failed_subject"STAFF_ORDER_CONFIRMATION_DEFAULT_SUBJECT = "Order {{ order.id }} details"diff --git a/saleor/plugins/admin_email/plugin.py b/saleor/plugins/admin_email/plugin.pyindex 503c705c36..97c8fdde58 100644--- a/saleor/plugins/admin_email/plugin.py+++ b/saleor/plugins/admin_email/plugin.py@@ -10,27 +10,14 @@ from ..email_common import (DEFAULT_EMAIL_CONFIG_STRUCTURE,DEFAULT_EMAIL_CONFIGURATION,DEFAULT_EMAIL_VALUE,- DEFAULT_SUBJECT_MESSAGE,- DEFAULT_TEMPLATE_MESSAGE,+ DEFAULT_SUBJECT_HELP_TEXT,+ DEFAULT_TEMPLATE_HELP_TEXT,EmailConfig,validate_default_email_configuration,+ validate_format_of_provided_templates,)from ..models import PluginConfiguration-from .constants import (- CSV_EXPORT_FAILED_DEFAULT_SUBJECT,- CSV_EXPORT_FAILED_SUBJECT_FIELD,- CSV_EXPORT_FAILED_TEMPLATE_FIELD,- CSV_PRODUCT_EXPORT_SUCCESS_DEFAULT_SUBJECT,- CSV_PRODUCT_EXPORT_SUCCESS_SUBJECT_FIELD,- CSV_PRODUCT_EXPORT_SUCCESS_TEMPLATE_FIELD,- PLUGIN_ID,- SET_STAFF_PASSWORD_DEFAULT_SUBJECT,- SET_STAFF_PASSWORD_SUBJECT_FIELD,- SET_STAFF_PASSWORD_TEMPLATE_FIELD,- STAFF_ORDER_CONFIRMATION_DEFAULT_SUBJECT,- STAFF_ORDER_CONFIRMATION_SUBJECT_FIELD,- STAFF_ORDER_CONFIRMATION_TEMPLATE_FIELD,-)+from . import constantsfrom .notify_events import (send_csv_export_failed,send_csv_product_export_success,@@ -70,75 +57,84 @@ def get_admin_event_map():class AdminEmailPlugin(BasePlugin):- PLUGIN_ID = PLUGIN_ID+ PLUGIN_ID = constants.PLUGIN_IDPLUGIN_NAME = "Admin emails"DEFAULT_ACTIVE = TrueDEFAULT_CONFIGURATION = [{- "name": STAFF_ORDER_CONFIRMATION_SUBJECT_FIELD,- "value": STAFF_ORDER_CONFIRMATION_DEFAULT_SUBJECT,+ "name": constants.STAFF_ORDER_CONFIRMATION_SUBJECT_FIELD,+ "value": constants.STAFF_ORDER_CONFIRMATION_DEFAULT_SUBJECT,+ },+ {+ "name": constants.STAFF_ORDER_CONFIRMATION_TEMPLATE_FIELD,+ "value": DEFAULT_EMAIL_VALUE,+ },+ {+ "name": constants.SET_STAFF_PASSWORD_SUBJECT_FIELD,+ "value": constants.SET_STAFF_PASSWORD_DEFAULT_SUBJECT,},- {"name": STAFF_ORDER_CONFIRMATION_TEMPLATE_FIELD, "value": DEFAULT_EMAIL_VALUE},{- "name": SET_STAFF_PASSWORD_SUBJECT_FIELD,- "value": SET_STAFF_PASSWORD_DEFAULT_SUBJECT,+ "name": constants.SET_STAFF_PASSWORD_TEMPLATE_FIELD,+ "value": DEFAULT_EMAIL_VALUE,},- {"name": SET_STAFF_PASSWORD_TEMPLATE_FIELD, "value": DEFAULT_EMAIL_VALUE},{- "name": CSV_PRODUCT_EXPORT_SUCCESS_SUBJECT_FIELD,- "value": CSV_PRODUCT_EXPORT_SUCCESS_DEFAULT_SUBJECT,+ "name": constants.CSV_PRODUCT_EXPORT_SUCCESS_SUBJECT_FIELD,+ "value": constants.CSV_PRODUCT_EXPORT_SUCCESS_DEFAULT_SUBJECT,},{- "name": CSV_PRODUCT_EXPORT_SUCCESS_TEMPLATE_FIELD,+ "name": constants.CSV_PRODUCT_EXPORT_SUCCESS_TEMPLATE_FIELD,"value": DEFAULT_EMAIL_VALUE,},{- "name": CSV_EXPORT_FAILED_SUBJECT_FIELD,- "value": CSV_EXPORT_FAILED_DEFAULT_SUBJECT,+ "name": constants.CSV_EXPORT_FAILED_SUBJECT_FIELD,+ "value": constants.CSV_EXPORT_FAILED_DEFAULT_SUBJECT,+ },+ {+ "name": constants.CSV_EXPORT_FAILED_TEMPLATE_FIELD,+ "value": DEFAULT_EMAIL_VALUE,},- {"name": CSV_EXPORT_FAILED_TEMPLATE_FIELD, "value": DEFAULT_EMAIL_VALUE},] + DEFAULT_EMAIL_CONFIGURATION # type: ignoreCONFIG_STRUCTURE = {- STAFF_ORDER_CONFIRMATION_SUBJECT_FIELD: {+ constants.STAFF_ORDER_CONFIRMATION_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Staff order confirmation subject",},- STAFF_ORDER_CONFIRMATION_TEMPLATE_FIELD: {+ constants.STAFF_ORDER_CONFIRMATION_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Staff order confirmation template",},- SET_STAFF_PASSWORD_SUBJECT_FIELD: {+ constants.SET_STAFF_PASSWORD_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Set staff password subject",},- SET_STAFF_PASSWORD_TEMPLATE_FIELD: {+ constants.SET_STAFF_PASSWORD_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Set staff password email template",},- CSV_PRODUCT_EXPORT_SUCCESS_SUBJECT_FIELD: {+ constants.CSV_PRODUCT_EXPORT_SUCCESS_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "CSV product export success subject",},- CSV_PRODUCT_EXPORT_SUCCESS_TEMPLATE_FIELD: {+ constants.CSV_PRODUCT_EXPORT_SUCCESS_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "CSV product export success template",},- CSV_EXPORT_FAILED_SUBJECT_FIELD: {+ constants.CSV_EXPORT_FAILED_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "CSV export failed template",},- CSV_EXPORT_FAILED_TEMPLATE_FIELD: {+ constants.CSV_EXPORT_FAILED_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "CSV export failed template",},}@@ -159,13 +155,15 @@ class AdminEmailPlugin(BasePlugin):use_ssl=configuration["use_ssl"] or settings.EMAIL_USE_SSL,)self.templates = AdminTemplate(- csv_export_failed=configuration[CSV_EXPORT_FAILED_TEMPLATE_FIELD],+ csv_export_failed=configuration[constants.CSV_EXPORT_FAILED_TEMPLATE_FIELD],csv_product_export_success=configuration[- CSV_PRODUCT_EXPORT_SUCCESS_TEMPLATE_FIELD+ constants.CSV_PRODUCT_EXPORT_SUCCESS_TEMPLATE_FIELD+ ],+ set_staff_password_email=configuration[+ constants.SET_STAFF_PASSWORD_TEMPLATE_FIELD],- set_staff_password_email=configuration[SET_STAFF_PASSWORD_TEMPLATE_FIELD],staff_order_confirmation=configuration[- STAFF_ORDER_CONFIRMATION_TEMPLATE_FIELD+ constants.STAFF_ORDER_CONFIRMATION_TEMPLATE_FIELD],)@@ -187,3 +185,6 @@ class AdminEmailPlugin(BasePlugin):def validate_plugin_configuration(cls, plugin_configuration: "PluginConfiguration"):"""Validate if provided configuration is correct."""validate_default_email_configuration(plugin_configuration)+ validate_format_of_provided_templates(+ plugin_configuration, constants.TEMPLATE_FIELDS+ )diff --git a/saleor/plugins/admin_email/tests/test_plugin.py b/saleor/plugins/admin_email/tests/test_plugin.pyindex 7347af6f0a..068697b955 100644--- a/saleor/plugins/admin_email/tests/test_plugin.py+++ b/saleor/plugins/admin_email/tests/test_plugin.py@@ -8,6 +8,12 @@ from django.core.mail.backends.smtp import EmailBackendfrom ....core.notify_events import NotifyEventTypefrom ...models import PluginConfiguration+from ..constants import (+ CSV_EXPORT_FAILED_TEMPLATE_FIELD,+ CSV_PRODUCT_EXPORT_SUCCESS_TEMPLATE_FIELD,+ SET_STAFF_PASSWORD_TEMPLATE_FIELD,+ STAFF_ORDER_CONFIRMATION_TEMPLATE_FIELD,+)from ..notify_events import (send_csv_export_failed,send_csv_product_export_success,@@ -145,3 +151,42 @@ def test_save_plugin_configuration_incorrect_email_backend_configuration(with pytest.raises(ValidationError):plugin.save_plugin_configuration(configuration, data_to_save)++[email protected](EmailBackend, "open")+def test_save_plugin_configuration_incorrect_template(mocked_open, admin_email_plugin):+ incorrect_template_str = """+ {{#if order.order_details_url}}+ Thank you for your order. Below is the list of fulfilled products. To see your+ order details please visit:+ <a href="{{ order.order_details_url }}">{{ order.order_details_url }}</a>+ {{else}}+ Thank you for your order. Below is the list of fulfilled products.+ {{/if}+ """ # missing } at the end of the if condition++ plugin = admin_email_plugin()+ configuration = PluginConfiguration.objects.get()++ data_to_save = {+ "configuration": [+ {+ "name": STAFF_ORDER_CONFIRMATION_TEMPLATE_FIELD,+ "value": incorrect_template_str,+ },+ {+ "name": SET_STAFF_PASSWORD_TEMPLATE_FIELD,+ "value": incorrect_template_str,+ },+ {+ "name": CSV_PRODUCT_EXPORT_SUCCESS_TEMPLATE_FIELD,+ "value": incorrect_template_str,+ },+ {"name": CSV_EXPORT_FAILED_TEMPLATE_FIELD, "value": incorrect_template_str},+ ]+ }++ with pytest.raises(ValidationError):+ plugin.save_plugin_configuration(configuration, data_to_save)++ mocked_open.assert_called_with()diff --git a/saleor/plugins/email_common.py b/saleor/plugins/email_common.pyindex 7d5e11cf43..79fd28bae0 100644--- a/saleor/plugins/email_common.py+++ b/saleor/plugins/email_common.py@@ -4,7 +4,7 @@ import refrom dataclasses import dataclassfrom decimal import Decimal, InvalidOperationfrom email.headerregistry import Address-from typing import Optional+from typing import List, Optionalimport html2textimport i18naddress@@ -25,12 +25,12 @@ from .models import PluginConfigurationlogger = logging.getLogger(__name__)-DEFAULT_TEMPLATE_MESSAGE = (+DEFAULT_TEMPLATE_HELP_TEXT = ("An HTML template built with handlebars template language. Leave it ""blank if you don't want to send an email for this action. Use the ""default Saleor template by providing DEFAULT value.")-DEFAULT_SUBJECT_MESSAGE = "An email subject built with handlebars template language."+DEFAULT_SUBJECT_HELP_TEXT = "An email subject built with Handlebars template language."DEFAULT_EMAIL_VALUE = "DEFAULT"@@ -273,6 +273,32 @@ def validate_default_email_configuration(plugin_configuration: "PluginConfigurat)+def validate_format_of_provided_templates(+ plugin_configuration: "PluginConfiguration", template_fields: List[str]+):+ """Make sure that the templates provided by the user have the correct structure."""+ configuration = plugin_configuration.configuration+ configuration = {item["name"]: item["value"] for item in configuration}++ if not plugin_configuration.active:+ return+ compiler = pybars.Compiler()+ errors = {}+ for field in template_fields:+ template_str = configuration.get(field)+ if not template_str or template_str == DEFAULT_EMAIL_VALUE:+ continue+ try:+ compiler.compile(template_str)+ except pybars.PybarsError:+ errors[field] = ValidationError(+ "The provided template has an inccorect structure.",+ code=PluginErrorCode.INVALID.value,+ )+ if errors:+ raise ValidationError(errors)++def get_email_template(plugin_identifier: str, template_field_name: str, default: str) -> str:diff --git a/saleor/plugins/user_email/constants.py b/saleor/plugins/user_email/constants.pyindex 3d3e46fc22..9c9b881d70 100644--- a/saleor/plugins/user_email/constants.py+++ b/saleor/plugins/user_email/constants.py@@ -24,6 +24,22 @@ ORDER_PAYMENT_CONFIRMATION_TEMPLATE_FIELD = "order_payment_confirmation"ORDER_CANCELED_TEMPLATE_FIELD = "order_canceled"ORDER_REFUND_CONFIRMATION_TEMPLATE_FIELD = "order_refund_confirmation"+TEMPLATE_FIELDS = [+ ACCOUNT_CONFIRMATION_TEMPLATE_FIELD,+ ACCOUNT_SET_CUSTOMER_PASSWORD_TEMPLATE_FIELD,+ ACCOUNT_DELETE_TEMPLATE_FIELD,+ ACCOUNT_CHANGE_EMAIL_CONFIRM_TEMPLATE_FIELD,+ ACCOUNT_CHANGE_EMAIL_REQUEST_TEMPLATE_FIELD,+ ACCOUNT_PASSWORD_RESET_TEMPLATE_FIELD,+ INVOICE_READY_TEMPLATE_FIELD,+ ORDER_CONFIRMATION_TEMPLATE_FIELD,+ ORDER_CONFIRMED_TEMPLATE_FIELD,+ ORDER_FULFILLMENT_CONFIRMATION_TEMPLATE_FIELD,+ ORDER_FULFILLMENT_UPDATE_TEMPLATE_FIELD,+ ORDER_PAYMENT_CONFIRMATION_TEMPLATE_FIELD,+ ORDER_CANCELED_TEMPLATE_FIELD,+ ORDER_REFUND_CONFIRMATION_TEMPLATE_FIELD,+]ACCOUNT_CONFIRMATION_DEFAULT_TEMPLATE = "confirm.html"ACCOUNT_SET_CUSTOMER_PASSWORD_DEFAULT_TEMPLATE = "set_customer_password.html"diff --git a/saleor/plugins/user_email/plugin.py b/saleor/plugins/user_email/plugin.pyindex d389008d5b..155216708f 100644--- a/saleor/plugins/user_email/plugin.py+++ b/saleor/plugins/user_email/plugin.py@@ -8,13 +8,15 @@ from ..email_common import (DEFAULT_EMAIL_CONFIG_STRUCTURE,DEFAULT_EMAIL_CONFIGURATION,DEFAULT_EMAIL_VALUE,- DEFAULT_SUBJECT_MESSAGE,- DEFAULT_TEMPLATE_MESSAGE,+ DEFAULT_SUBJECT_HELP_TEXT,+ DEFAULT_TEMPLATE_HELP_TEXT,EmailConfig,validate_default_email_configuration,+ validate_format_of_provided_templates,)from ..models import PluginConfigurationfrom . import constants+from .constants import TEMPLATE_FIELDSfrom .notify_events import (send_account_change_email_confirm,send_account_change_email_request,@@ -217,142 +219,142 @@ class UserEmailPlugin(BasePlugin):CONFIG_STRUCTURE = {constants.ACCOUNT_CONFIRMATION_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Account confirmation - subject",},constants.ACCOUNT_CONFIRMATION_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Account confirmation - template",},constants.ACCOUNT_SET_CUSTOMER_PASSWORD_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Set customer password - subject",},constants.ACCOUNT_SET_CUSTOMER_PASSWORD_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Set customer password - template",},constants.ACCOUNT_DELETE_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Account delete - subject",},constants.ACCOUNT_DELETE_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Account delete - template",},constants.ACCOUNT_CHANGE_EMAIL_CONFIRM_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Account change email confirm - subject",},constants.ACCOUNT_CHANGE_EMAIL_CONFIRM_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Account change email confirm - template",},constants.ACCOUNT_CHANGE_EMAIL_REQUEST_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Account change email request - subject",},constants.ACCOUNT_CHANGE_EMAIL_REQUEST_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Account change email request - template",},constants.ACCOUNT_PASSWORD_RESET_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Account password reset - subject",},constants.ACCOUNT_PASSWORD_RESET_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Account password reset - template",},constants.INVOICE_READY_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Invoice ready - subject",},constants.INVOICE_READY_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Invoice ready - template",},constants.ORDER_CONFIRMATION_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Order confirmation - subject",},constants.ORDER_CONFIRMATION_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Order confirmation - template",},constants.ORDER_CONFIRMED_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Order confirmed - subject",},constants.ORDER_CONFIRMED_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Order confirmed - template",},constants.ORDER_FULFILLMENT_CONFIRMATION_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Order fulfillment confirmation - subject",},constants.ORDER_FULFILLMENT_CONFIRMATION_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Order fulfillment confirmation - template",},constants.ORDER_FULFILLMENT_UPDATE_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Order fulfillment update - subject",},constants.ORDER_FULFILLMENT_UPDATE_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Order fulfillment update - template",},constants.ORDER_PAYMENT_CONFIRMATION_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Payment confirmation - subject",},constants.ORDER_PAYMENT_CONFIRMATION_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Payment confirmation - template",},constants.ORDER_CANCELED_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Order canceled - subject",},constants.ORDER_CANCELED_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Order canceled - template",},constants.ORDER_REFUND_CONFIRMATION_SUBJECT_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_SUBJECT_MESSAGE,+ "help_text": DEFAULT_SUBJECT_HELP_TEXT,"label": "Order refund - subject",},constants.ORDER_REFUND_CONFIRMATION_TEMPLATE_FIELD: {"type": ConfigurationTypeField.STRING,- "help_text": DEFAULT_TEMPLATE_MESSAGE,+ "help_text": DEFAULT_TEMPLATE_HELP_TEXT,"label": "Order refund - template",},}@@ -426,3 +428,4 @@ class UserEmailPlugin(BasePlugin):def validate_plugin_configuration(cls, plugin_configuration: "PluginConfiguration"):"""Validate if provided configuration is correct."""validate_default_email_configuration(plugin_configuration)+ validate_format_of_provided_templates(plugin_configuration, TEMPLATE_FIELDS)diff --git a/saleor/plugins/user_email/tests/test_plugin.py b/saleor/plugins/user_email/tests/test_plugin.pyindex 5795fa50b0..813582c9cb 100644--- a/saleor/plugins/user_email/tests/test_plugin.py+++ b/saleor/plugins/user_email/tests/test_plugin.py@@ -8,6 +8,10 @@ from django.core.mail.backends.smtp import EmailBackendfrom ....core.notify_events import NotifyEventTypefrom ...models import PluginConfiguration+from ..constants import (+ ORDER_CONFIRMATION_TEMPLATE_FIELD,+ ORDER_CONFIRMED_TEMPLATE_FIELD,+)from ..notify_events import (send_account_change_email_confirm,send_account_change_email_request,@@ -174,3 +178,33 @@ def test_save_plugin_configuration_incorrect_email_backend_configuration(with pytest.raises(ValidationError):plugin.save_plugin_configuration(configuration, data_to_save)+ mocked_open.assert_called_with()++[email protected](EmailBackend, "open")+def test_save_plugin_configuration_incorrect_template(mocked_open, user_email_plugin):+ incorrect_template_str = """+ {{#if order.order_details_url}}+ Thank you for your order. Below is the list of fulfilled products. To see your+ order details please visit:+ <a href="{{ order.order_details_url }}">{{ order.order_details_url }}</a>+ {{else}}+ Thank you for your order. Below is the list of fulfilled products.+ {{/if}+ """ # missing } at the end of the if condition++ plugin = user_email_plugin()+ configuration = PluginConfiguration.objects.get()+ data_to_save = {+ "configuration": [+ {+ "name": ORDER_CONFIRMATION_TEMPLATE_FIELD,+ "value": incorrect_template_str,+ },+ {"name": ORDER_CONFIRMED_TEMPLATE_FIELD, "value": incorrect_template_str},+ ]+ }++ with pytest.raises(ValidationError):+ plugin.save_plugin_configuration(configuration, data_to_save)+ mocked_open.assert_called_with()