You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.3 KiB

  1. # Copyright 2018 Tecnativa - Jairo Llopis
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from lxml import html
  4. from odoo import _, api, models
  5. from odoo.exceptions import ValidationError
  6. class MailTemplate(models.Model):
  7. _inherit = "mail.template"
  8. @api.constrains("body_html", "model")
  9. def _check_consent_links_in_body_html(self):
  10. """Body for ``privacy.consent`` templates needs placeholder links."""
  11. links = [
  12. "//a[@href='/privacy/consent/{}/']".format(action)
  13. for action in ("accept", "reject")
  14. ]
  15. for one in self:
  16. if one.model != "privacy.consent":
  17. continue
  18. doc = html.document_fromstring(one.body_html)
  19. for link in links:
  20. if not doc.xpath(link):
  21. raise ValidationError(
  22. _(
  23. "Missing privacy consent link placeholders. "
  24. "You need at least these two links:\n"
  25. '<a href="%s">Accept</a>\n'
  26. '<a href="%s">Reject</a>'
  27. )
  28. % (
  29. "/privacy/consent/accept/",
  30. "/privacy/consent/reject/",
  31. )
  32. )