diff --git a/addons/website/controllers/form.py b/addons/website/controllers/form.py index 56fee82ef72..a2d1a00212b 100644 --- a/addons/website/controllers/form.py +++ b/addons/website/controllers/form.py @@ -12,7 +12,8 @@ from odoo import http, SUPERUSER_ID, _, _lt from odoo.addons.base.models.ir_qweb_fields import nl2br, nl2br_enclose from odoo.http import request from odoo.tools import plaintext2html -from odoo.exceptions import ValidationError, UserError +from odoo.exceptions import AccessDenied, ValidationError, UserError +from odoo.tools.misc import hmac, consteq class WebsiteForm(http.Controller): @@ -73,6 +74,15 @@ class WebsiteForm(http.Controller): # for the email queue to process if model_name == 'mail.mail': + form_has_email_cc = {'email_cc', 'email_bcc'} & kwargs.keys() or \ + 'email_cc' in kwargs["website_form_signature"] + # remove the email_cc information from the signature + kwargs["website_form_signature"] = kwargs["website_form_signature"].split(':')[0] + if kwargs.get("email_to"): + value = kwargs['email_to'] + (':email_cc' if form_has_email_cc else '') + hash_value = hmac(model_record.env, 'website_form_signature', value) + if not consteq(kwargs["website_form_signature"], hash_value): + raise AccessDenied('invalid website_form_signature') request.env[model_name].sudo().browse(id_record).send() # Some fields have additional SQL constraints that we can't check generically @@ -184,7 +194,7 @@ class WebsiteForm(http.Controller): custom_fields.append((_('email'), field_value)) # If it's a custom field - elif field_name != 'context': + elif field_name not in ('context', 'website_form_signature'): custom_fields.append((field_name, field_value)) data['custom'] = "\n".join([u"%s : %s" % v for v in custom_fields]) @@ -217,7 +227,8 @@ class WebsiteForm(http.Controller): def insert_record(self, request, model, values, custom, meta=None): model_name = model.sudo().model if model_name == 'mail.mail': - values.update({'reply_to': values.get('email_from')}) + email_from = _('"%s form submission" <%s>') % (request.env.company.name, request.env.company.email) + values.update({'reply_to': values.get('email_from'), 'email_from': email_from}) record = request.env[model_name].with_user(SUPERUSER_ID).with_context( mail_create_nosubscribe=True, ).create(values) diff --git a/addons/website/models/ir_qweb_fields.py b/addons/website/models/ir_qweb_fields.py index 9f2a98a4e7f..d9c879210bc 100644 --- a/addons/website/models/ir_qweb_fields.py +++ b/addons/website/models/ir_qweb_fields.py @@ -1,7 +1,11 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from lxml import etree +from markupsafe import Markup + from odoo import api, models, _ +from odoo.addons.website.tools import add_form_signature class Contact(models.AbstractModel): @@ -16,3 +20,20 @@ class Contact(models.AbstractModel): badges=dict(type='boolean', string=_('Display the badges')) ) return options + + +class HTML(models.AbstractModel): + _inherit = 'ir.qweb.field.html' + + @api.model + def value_to_html(self, value, options): + res = super().value_to_html(value, options) + + if res and '