[FIX] website: make email_to of contactus form dynamic again

The email_to field of the contactus form have to be dynamic except if
the user manually set it via the form options. Unfortunately, the
website signature task broke this feature. This commit fixes it and adds
a test to prevent this regression in the future.

Steps to reproduce the bug:
- Go to the contactus page
- Edit the page
- Add a field on the form
- Save the page
- Change the company email address via the settings

=> The contactus form still send the email to the old email address.

Related to task-3382195

X-original-commit: 10b4db60fbd077936b5c9586485fa40c3c890d3f
Part-of: odoo/odoo#147933
This commit is contained in:
Guillaume-gdi
2024-01-04 12:02:01 +00:00
parent 2a8dd60118
commit f9154bb6db
4 changed files with 40 additions and 3 deletions
@@ -707,4 +707,16 @@
}
]);
wTourUtils.registerWebsitePreviewTour('website_form_contactus_change_random_option', {
test: true,
url: '/contactus',
edition: true,
}, () => editContactUs([
{
content: "Change a random option",
trigger: '[data-set-mark] input',
run: 'text_blur **',
},
]));
export default {};
@@ -217,3 +217,13 @@ registry.category("web_tour.tours").add('website_form_contactus_submit', {
isCheck: true,
},
]});
registry.category("web_tour.tours").add('website_form_contactus_check_changed_email', {
test: true,
url: '/contactus',
steps: () => [
{
content: "Check that the recipient email is updated",
trigger: 'form:has(input[name="email_to"][value="after.change@mail.com"])',
isCheck: true,
},
]});
@@ -41,3 +41,11 @@ class TestWebsiteFormEditor(HttpCaseWithUserPortal):
def test_website_form_conditional_required_checkboxes(self):
self.start_tour('/', 'website_form_conditional_required_checkboxes', login="admin")
def test_contactus_form_email_stay_dynamic(self):
# The contactus form should always be sent to the company email except
# if the user explicitly changed it in the options.
self.env.company.email = 'before.change@mail.com'
self.start_tour('/contactus', 'website_form_contactus_change_random_option', login="admin")
self.env.company.email = 'after.change@mail.com'
self.start_tour('/contactus', 'website_form_contactus_check_changed_email', login="portal")
+10 -3
View File
@@ -203,10 +203,17 @@ def add_form_signature(html_fragment, env_sudo):
# the value of email_to can still be None in case of default value
if 'email_to' not in form_values:
continue
elif not form_values['email_to'].attrib.get('value'):
form_values['email_to'].attrib['value'] = env_sudo.company.email or ''
email_to_value = form_values['email_to'].attrib.get('value')
if (not email_to_value
or (email_to_value == 'info@yourcompany.example.com'
and html_fragment.xpath('//span[@data-for="contactus_form"]'))):
# This means that the mail will be sent to the value of the dataFor
# which is the company email.
email_to_value = env_sudo.company.email or ''
has_cc = {'email_cc', 'email_bcc'} & form_values.keys()
value = form_values['email_to'].attrib['value'] + (':email_cc' if has_cc else '')
value = email_to_value + (':email_cc' if has_cc else '')
hash_value = hmac(env_sudo, 'website_form_signature', value)
if has_cc:
hash_value += ':email_cc'