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.

33 lines
1.2 KiB

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