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.

53 lines
1.9 KiB

  1. # Copyright 2018 Tecnativa - Jairo Llopis
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from odoo import models
  4. class MailMail(models.Model):
  5. _inherit = "mail.mail"
  6. def _postprocess_sent_message(self, mail_sent=True):
  7. """Write consent status after sending message."""
  8. if mail_sent:
  9. # Get all mails sent to consents
  10. consent_mails = self.filtered(
  11. lambda one: one.mail_message_id.model == "privacy.consent"
  12. )
  13. # Get related draft consents
  14. consents = self.env["privacy.consent"].browse(
  15. consent_mails.mapped("mail_message_id.res_id"),
  16. self._prefetch
  17. ).filtered(lambda one: one.state == "draft")
  18. # Set as sent
  19. consents.write({
  20. "state": "sent",
  21. })
  22. return super(MailMail, self)._postprocess_sent_message(mail_sent)
  23. def send_get_mail_body(self, partner=None):
  24. """Replace privacy consent magic links.
  25. This replacement is done here instead of directly writing it into
  26. the ``mail.template`` to avoid writing the tokeinzed URL
  27. in the mail thread for the ``privacy.consent`` record,
  28. which would enable any reader of such thread to impersonate the
  29. subject and choose in its behalf.
  30. """
  31. result = super(MailMail, self).send_get_mail_body(partner=partner)
  32. # Avoid polluting other model mails
  33. if self.model != "privacy.consent":
  34. return result
  35. # Tokenize consent links
  36. consent = self.env["privacy.consent"] \
  37. .browse(self.mail_message_id.res_id) \
  38. .with_prefetch(self._prefetch)
  39. result = result.replace(
  40. "/privacy/consent/accept/",
  41. consent._url(True),
  42. )
  43. result = result.replace(
  44. "/privacy/consent/reject/",
  45. consent._url(False),
  46. )
  47. return result