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.

32 lines
1.2 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 = ["//a[@href='/privacy/consent/{}/']".format(action)
  12. for action in ("accept", "reject")]
  13. for one in self:
  14. if one.model != "privacy.consent":
  15. continue
  16. doc = html.document_fromstring(one.body_html)
  17. for link in links:
  18. if not doc.xpath(link):
  19. raise ValidationError(_(
  20. "Missing privacy consent link placeholders. "
  21. "You need at least these two links:\n"
  22. '<a href="%s">Accept</a>\n'
  23. '<a href="%s">Reject</a>'
  24. ) % (
  25. "/privacy/consent/accept/",
  26. "/privacy/consent/reject/",
  27. ))