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.

35 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from hashlib import sha256
  5. from uuid import uuid4
  6. from openerp import api, models
  7. class MailMassMailing(models.Model):
  8. _inherit = "mail.mass_mailing"
  9. @api.model
  10. def _init_salt_create(self):
  11. """Create a salt to secure the unsubscription URLs."""
  12. icp = self.env["ir.config_parameter"]
  13. key = "mass_mailing.salt"
  14. salt = icp.get_param(key)
  15. if salt is False:
  16. salt = str(uuid4())
  17. icp.set_param(key, salt, ["base.group_erp_manager"])
  18. @api.model
  19. def hash_create(self, mailing_id, res_id, email):
  20. """Create a secure hash to know if the unsubscription is trusted.
  21. :return None/str:
  22. Secure hash, or ``None`` if the system parameter is empty.
  23. """
  24. salt = self.env["ir.config_parameter"].sudo().get_param(
  25. "mass_mailing.salt")
  26. if not salt:
  27. return None
  28. source = (self.env.cr.dbname, mailing_id, res_id, email, salt)
  29. return sha256(",".join(map(unicode, source))).hexdigest()